@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
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import{al as Nc,b as st,am as kc,j as t,H as ge,an as Sc,ao as Cc,a as ln,d as sa,p as Jr,R as l,N as Ps,ac as Pc,ad as Ic,ab as Dc,ae as Ac,a9 as Ec,aa as Mc,af as Rc,ap as Tc,aq as Fc,ar as Lc,u as Oc,k as zc,m as Kc,t as Uc,C as $c,S as Bc,as as Vc,a7 as _c,D as Hc,o as Wc,at as qc,au as Gc,av as Jc,aw as Qc,ax as Yc,Y as Fs,ay as Xc,az as wn,aA as ii,aB as Zc,aC as ed,aD as Ja,aE as td,aF as sd,aG as nd,aH as oi,aI as Ra,aJ as li,i as Na,aK as jl,aL as Qr,aM as Ka,aN as wl,aO as ci,aP as ad,aQ as rd,aR as id,aS as od,aT as di,aU as Te,aV as ra,aW as ld,aX as cd,aY as dd,aZ as md,a_ as ud,a$ as Nl,a8 as pd,b0 as mi,b1 as gd,b2 as hd,b3 as fd,b4 as xd}from"./vendor-.bun-C6iL44L9.js";import{dC as Ua,y as Ta,z as Fa,p as le,dD as ka,dE as Sa,dF as Ca,b as os,c as ot,I as A,aF as It,aG as Dt,aH as At,an as bd,aD as Ws,b7 as Kt,b6 as Ut,b5 as $t,bL as qt,A as Pr,bk as Yr,w as fn,aC as Is,t as q,a1 as kl,B as J,dG as Mn,dH as yd,dI as vd,dr as jd,dJ as wd,dK as Nd,dL as kd,D as ks,dM as Sd,cY as Cd,cZ as Pd,c_ as Id,cb as Dd,ay as us,aA as ps,cc as Ad,aB as gs,a$ as $a,dN as Ed,dO as Dn,b4 as Bt,bx as Ht,bT as Zt,q as tt,dP as ta,ax as ws,X as lt,dn as Md,bM as Tt,bN as Ft,bO as zt,bP as Lt,bQ as ht,bi as hs,b0 as La,dQ as xn,bj as St,dR as Sl,dS as Rd,dT as Td,dU as Ba,dV as Hs,dW as Rn,b2 as Cl,dX as tn,dY as Fd,dZ as Ld,d_ as Od,d$ as zd,e0 as Kd,e1 as Ud,e2 as Vs,e3 as $d,x as Va,ch as ui,n as Bd,cj as Ir,aa as Pl,H as Vd,P as Il,K as Dl,cl as _d,R as pi,d5 as Hd,dl as Al,da as El,dc as Wd,e4 as qd,u as Dr,cH as Gd,e5 as gi,e6 as Jd,e7 as Qd,e8 as hi,e9 as Yd,ea as Xd,eb as Zd,ec as em,aE as tm,ed as sm,L as nm,N as am,d as Xr,aP as fi,ee as xi,ef as bi,aS as _n,eg as Ar,eh as rm,ei as im,aj as Tn,ai as Ml,ah as om,ej as lm,ek as yi,ak as cm,al as dm,ac as mm,aJ as um,aK as pm,aL as Rl,el as Qa,em as vi,en as gm,eo as hm,ep as fm,eq as xm,dd as _a,Y as _s,er as bm,es as ym,et as vm,eu as jm,ev as wm,ew as Ya,ex as ji,ey as Nm,ez as km,eA as Sm,eB as Cm,W as Pm,eC as Im,eD as Xa,eE as Dm,aY as wi,eF as Pn,aX as Am,eG as Em,eH as Ni,eI as ki,ck as Mm,a2 as Xs,F as Rm,S as Tm,eJ as Fm,cu as ia,bp as Er,bq as Mr,br as Rr,bs as Tr,bt as Bs,bu as Ms,bU as An,M as Zn,eK as Si,c4 as Lm,eL as Tl,bW as Om,dh as zm,i as Km,eM as Za,a9 as Um,bc as oa,b_ as $m,eN as Bm,eO as Vm,db as _m,eP as Hm,eQ as Wm,dA as qm,eR as Gm}from"./useAppFontEffects-BUUJYbAZ.js";import{F as Zr,h as pt,o as vs,b as ys,a3 as Jm,a4 as Ci,a5 as Qm,a6 as Ym,y as fs,M as hn,u as Le,m as zn,P as Pi,k as Ct,a as Kn,d as Os,l as ls,s as Xm,a7 as Fl,H as Zm,a8 as er,G as eu,a9 as Ii,aa as tu,z as su,ab as Di,ac as Ai,ad as Ei,ae as Mi,af as tr,ag as Ri,E as Ll,ah as nu,ai as au,aj as ru,ak as iu,a2 as ou,f as lu,al as cu,am as du,an as mu,ao as uu}from"./index-ZJTzZ0_U.js";import{g as pu,s as gu}from"./mobileLayoutPreference-Dio-WWkI.js";function hu(){return new Worker(Nc,{type:"module"})}const fu=["typescript","javascript","tsx","jsx","json","markdown"],Fr={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Ti,Fi;const Li=s=>{const e=Fr[s],n=new kc({workerFactory:hu,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:fu,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},xu=s=>{if(!(typeof window>"u"))return s==="split"?(Fi??=Li("split"),Fi):(Ti??=Li("unified"),Ti)},bu=s=>{const e=st.c(7),{children:n,renderTheme:a}=s,r=Lr("unified"),i=Lr("split");let o,d;e[0]!==a||e[1]!==i||e[2]!==r?(o=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:Fr.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:Fr.split.lineDiffType})},d=[a,i,r],e[0]=a,e[1]=i,e[2]=r,e[3]=o,e[4]=d):(o=e[3],d=e[4]),ge.useEffect(o,d);let c;return e[5]!==n?(c=t.jsx(t.Fragment,{children:n}),e[5]=n,e[6]=c):c=e[6],c},Uv=s=>{const e=st.c(11),{children:n}=s,a=Ua();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const f=Ta(!1),u=Ta(!0),p=a?.lightThemeId??f.metadata.id,m=a?.darkThemeId??u.metadata.id;i=a?.availableThemes.find(I=>I.metadata.id===p)??f,r=a?.availableThemes.find(I=>I.metadata.id===m)??u,Fa(i),Fa(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 o;e[5]!==r.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:r.metadata.id},e[5]=r.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const d=o;let c;return e[8]!==n||e[9]!==d?(c=t.jsx(bu,{renderTheme:d,children:n}),e[8]=n,e[9]=d,e[10]=c):c=e[10],c},Lr=s=>{const e=st.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=xu(n),e[0]=n,e[1]=a):a=e[1],a};function yu(s){const e=st.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 Oa=ge.forwardRef((s,e)=>{const n=st.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=le("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 o;n[5]===Symbol.for("react.memo_cache_sentinel")?(o={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=o):o=n[5];let d;n[6]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(Sc,{className:le("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(Cc,{className:i,style:o,...r,ref:e,children:d}),n[7]=r,n[8]=e,n[9]=i,n[10]=c):c=n[10],c});Oa.displayName="Switch";const la=()=>{try{const e=os.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=vs.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[McpConfigStore] Error resolving config directory:",s)}return null},Oi=s=>s?Object.entries(s).map(([e,n])=>({key:e,value:n})):[],zi=s=>{const e=s.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},ca=s=>typeof s!="string"?void 0:s.trim()||void 0,sr=800,vu=5e3,ju="__default__",Or=new Map,nr=new Map,Ol=s=>s?.trim()||ju,ar=s=>{Or.delete(Ol(s))},Ln=ln()(sa(Jr((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=la(),r=Ol(a),i=Date.now(),o=Or.get(r)??0,d=e().mcpServers.length>0;if(!n?.force&&d&&i-o<vu)return!0;const c=nr.get(r);if(!n?.force&&c)return c;const f=(async()=>{s({isLoading:!0});try{const u=a?`?directory=${encodeURIComponent(a)}`:"",p=await pt(`/api/config/mcp${u}`,{headers:a?{"x-opencode-directory":a}:void 0});if(!p.ok)throw new Error("Failed to load MCP configs");const m=await p.json();return s({mcpServers:m,isLoading:!1}),Or.set(r,Date.now()),!0}catch(u){return console.error("[McpConfigStore] Failed to load MCP configs:",u),s({isLoading:!1}),!1}})();nr.set(r,f);try{return await f}finally{nr.delete(r)}},createMcp:async n=>{ka("Creating MCP server configuration…");let a=!1;try{const r=Ki(n),i=la(),o=i?`?directory=${encodeURIComponent(i)}`:"",d=await pt(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{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 ar(i),c?.requiresReload?(a=!0,await Sa({message:c.message,delayMs:c.reloadDelayMs??sr,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||Ca()}},updateMcp:async(n,a)=>{ka("Updating MCP server configuration…");let r=!1;try{const i=Ki(a),o=la(),d=o?`?directory=${encodeURIComponent(o)}`:"",c=await pt(`/api/config/mcp/${encodeURIComponent(n)}${d}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),f=await c.json().catch(()=>null);if(!c.ok)throw new Error(f?.error||"Failed to update MCP server");return ar(o),f?.requiresReload?(r=!0,await Sa({message:f.message,delayMs:f.reloadDelayMs??sr,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||Ca()}},deleteMcp:async n=>{ka("Deleting MCP server configuration…");let a=!1;try{const r=la(),i=r?`?directory=${encodeURIComponent(r)}`:"",o=await pt(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:r?{"x-opencode-directory":r}:void 0}),d=await o.json().catch(()=>null);if(!o.ok)throw new Error(d?.error||"Failed to delete MCP server");return ar(r),d?.requiresReload&&(a=!0,await Sa({message:d.message,delayMs:d.reloadDelayMs??sr,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||Ca()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:Zr(),partialize:s=>({selectedMcpName:s.selectedMcpName})}),{name:"mcp-config-store"}));function Ki(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=zi(s.environment)??{}),s.headers!==void 0&&(e.headers=zi(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:ca(s.oauthClientId),clientSecret:ca(s.oauthClientSecret),scope:ca(s.oauthScope),redirectUri:ca(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 wu={},Nu={},$s=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},Sn=s=>$s(s)??"__global__",un=s=>{const e=$s(s);return e?vs.getScopedApiClient(e):vs.getApiClient()},cs=ln()(sa((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=Sn(n??ys.getState().currentDirectory);return e().byDirectory[a]??wu},getDiagnosticForDirectory:n=>{const a=Sn(n??ys.getState().currentDirectory);return e().diagnosticsByDirectory[a]??Nu},getErrorForDirectory:n=>{const a=Sn(n??ys.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=$s(n?.directory??ys.getState().currentDirectory),r=Sn(a);n?.silent||s(i=>({loadingKeys:{...i.loadingKeys,[r]:!0},lastErrorKeys:{...i.lastErrorKeys,[r]:null}}));try{const d=(await un(a).mcp.status()).data??{};s(c=>({byDirectory:{...c.byDirectory,[r]:d},diagnosticsByDirectory:{...c.diagnosticsByDirectory,[r]:Object.fromEntries(Object.entries(c.diagnosticsByDirectory[r]??{}).filter(([f])=>!d[f]))},loadingKeys:{...c.loadingKeys,[r]:!1},lastErrorKeys:{...c.lastErrorKeys,[r]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";s(d=>({loadingKeys:{...d.loadingKeys,[r]:!1},lastErrorKeys:{...d.lastErrorKeys,[r]:o}}))}},connect:async(n,a)=>{const r=$s(a??ys.getState().currentDirectory),i=Sn(r),o=un(r);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(d){const c=d instanceof Error?d.message:"Connection failed";throw s(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:c}}}})),d}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=$s(a??ys.getState().currentDirectory);await un(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=$s(a??ys.getState().currentDirectory),d=(await un(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=$s(r??ys.getState().currentDirectory);await un(i).mcp.auth.callback({name:n,code:a},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,a)=>{const r=$s(a??ys.getState().currentDirectory);await un(r).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},testConnection:async(n,a)=>{const r=$s(a??ys.getState().currentDirectory),i=Sn(r),o=un(r),c=e().getStatusForDirectory(r)[n]?.status==="connected";let f,u;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(I){f=I instanceof Error?I.message:"Connection failed",s(g=>({diagnosticsByDirectory:{...g.diagnosticsByDirectory,[i]:{...g.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:f??"Connection failed"}}}}))}await e().refresh({directory:r,silent:!0});const p=e().getStatusForDirectory(r)[n],m=p;if(!c&&p?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(I){u=`Connection test succeeded, but cleanup disconnect failed: ${I instanceof Error?I.message:"Disconnect failed"}`}await e().refresh({directory:r,silent:!0})}return{status:m??e().getStatusForDirectory(r)[n],error:f,warning:u}}}))),ku=(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}},Su=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},$v=({active:s,className:e,headerAction:n,listClassName:a,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:o}=ot(),c=ys(k=>k.currentDirectory)??null,f=cs(k=>k.getStatusForDirectory(c)),u=cs(k=>k.refresh),p=cs(k=>k.connect),m=cs(k=>k.disconnect),I=Ln(k=>k.mcpServers),g=Ln(k=>k.loadMcpConfigs),[h,x]=l.useState(!1),[E,S]=l.useState(null);l.useEffect(()=>{u({directory:c,silent:!0})},[u,c]),l.useEffect(()=>{g({force:!0})},[g]),l.useEffect(()=>{s&&Promise.all([u({directory:c,silent:!0}),g({force:!0})])},[s,u,c,g]);const C=l.useMemo(()=>{const k=new Set(Object.keys(f));for(const v of I)v?.name&&k.add(v.name);return Array.from(k).sort((v,b)=>v.localeCompare(b))},[I,f]),M=l.useCallback(k=>{if(k?.preventDefault(),h)return;x(!0);const v=new Promise(b=>setTimeout(b,500));Promise.all([u({directory:c}),v]).finally(()=>{x(!1)})},[h,u,c]);return t.jsxs("div",{className:le("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:o("mcpDropdown.title")}),c&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:c.split("/").pop()||c})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:h,onClick:M,"aria-label":o("mcpDropdown.actions.refreshAria"),children:t.jsx(A,{name:"refresh",className:le("h-4 w-4",h&&"animate-spin")})})]})]})}),t.jsxs("div",{className:le("max-h-64 overflow-y-auto py-2",i&&"space-y-1 py-3",a),children:[C.map(k=>{const v=f[k],b=Su(v),D=v?.status==="connected",U=E===k,T=ku(v,o);return t.jsxs("div",{className:le("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",i?"gap-3 px-4 py-3":"gap-2 px-4 py-1.5"),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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx("span",{className:le("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",b==="success"&&"bg-status-success",b==="error"&&"bg-status-error",b==="warning"&&"bg-status-warning",b==="default"&&"bg-muted-foreground/40"),"aria-label":T})}),t.jsx(At,{side:"left",children:t.jsx("p",{children:T})})]}),t.jsx("span",{className:le("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:k})]})}),t.jsx(Oa,{checked:D,disabled:U,className:"data-[checked]:bg-status-info",onCheckedChange:async F=>{S(k);try{F?await p(k,c):await m(k,c)}finally{S(null)}}})]},k)}),C.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:o("mcpDropdown.empty.configureInConfig")})]})]})};function Cu(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=bd();return s}catch{return"unknown"}}function Pu(){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 Iu(){if(typeof navigator>"u")return"web";const s=(navigator.platform||"").toLowerCase();return s.includes("mac")?"macos":s.includes("win")?"windows":s.includes("linux")?"linux":"web"}function Du(s){const e=Le.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",Cu()),n.set("arch",Pu()),n.set("platform",Iu()),s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",zn()?"local":"remote"),n):s==="vscode"?(n.set("appType","vscode"),n.set("instanceMode","local"),n):(n.set("appType","web"),n.set("instanceMode","unknown"),n)}async function Ui(s,e){try{const n=Du(s),a=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e||s==="vscode"&&a&&n.set("currentVersion",a);const r=await pt(`/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,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 Au(){return Ym()?"desktop":fs()?"vscode":hn()?"web":null}const $i={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},zl=ln()((s,e)=>({...$i,checkForUpdates:async()=>{const n=Au();if(!n)return null;s({checking:!0,error:null,runtimeType:n});try{let a=null,r=null;if(n==="desktop"){const i=await Ci();return s({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null}),r}else n==="web"?(a=await Ui("web"),r=a?.nextSuggestedCheckInSec??null):n==="vscode"&&(r=(await Ui("vscode"))?.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 Ci();if(!r?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(s(o=>({info:o.info?{...o.info,...r,body:o.info.body||r.body,available:o.info.available}:r})),!await Qm(o=>{s({progress:o})}))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 Jm())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($i)}})),Bi="https://github.com/btriapitsyn/openchamber/releases";function Eu(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(Yr(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function Mu(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Vi(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function Ru(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,o=Number.isFinite(a[r])?a[r]:0;if(i!==o)return o-i}return 0}function Tu(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 o=n[i+1]?.start??s.length,d=s.slice(r.start,o).trim();return{version:r.version,date:r.date,start:r.start,end:o,raw:d}})}const _i=2e3,Fu=600*1e3;async function Lu(){try{const s=await pt("/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 Ou(){try{return(await pt("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function zu(s,e=Math.ceil(Fu/_i),n=_i){for(let a=0;a<e;a++){try{const r=await pt("/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 Ou())return!0}catch{}await new Promise(r=>setTimeout(r,n))}return!1}const Hi=({open:s,onOpenChange:e,info:n,downloading:a,downloaded:r,progress:i,error:o,onDownload:d,onRestart:c,runtimeType:f="desktop"})=>{const{t:u}=ot(),[p,m]=ge.useState(!1),[I,g]=ge.useState("idle"),[h,x]=ge.useState(null),E=n?.version?`${Bi}/tag/v${n.version}`:Bi,S=i?.total?Math.round(i.downloaded/i.total*100):0,C=f==="web",M=n?.updateCommand||"openchamber update";ge.useEffect(()=>{s||(g("idle"),x(null))},[s]);const k=async()=>{(await fn(M)).ok&&(m(!0),setTimeout(()=>m(!1),2e3))},v=ge.useCallback(async T=>{await Ws(T)},[]),b=ge.useCallback(async()=>{g("updating"),x(null);const T=await Lu();if(!T.success){g("error"),x(T.error||u("updateDialog.error.updateFailed"));return}T.autoRestart&&(g("restarting"),await new Promise(j=>setTimeout(j,2e3))),g("reconnecting"),await zu(n?.currentVersion)?window.location.reload():(g("error"),x(u("updateDialog.error.takingLonger")))},[n?.currentVersion,u]),D=I!=="idle"&&I!=="error",U=ge.useMemo(()=>{if(!n?.body)return null;const T=n.body.trim();if(!T)return null;const F=Tu(T);if(F.length===0)return{kind:"raw",title:u("updateDialog.changelog.title"),content:Vi(T)};const j=[...F].sort((P,O)=>Ru(P.version,O.version));return{kind:"sections",title:u("updateDialog.changelog.title"),sections:j.map(P=>({version:P.version,dateLabel:Eu(P.date),content:Vi(Mu(P.raw)||T)}))}},[n?.body,u]);return t.jsx(Kt,{open:s,onOpenChange:D?void 0:e,children:t.jsxs(Ut,{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($t,{className:"flex items-center gap-2.5",children:[t.jsx(A,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),t.jsx("span",{className:"text-lg font-semibold text-foreground",children:u(I==="restarting"||I==="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:[C&&D&&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(A,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),t.jsxs("div",{className:"typography-ui-label text-foreground",children:[I==="updating"&&u("updateDialog.status.installingUpdate"),I==="restarting"&&u("updateDialog.status.serverRestarting"),I==="reconnecting"&&u("updateDialog.status.waitingForServer")]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:u("updateDialog.status.autoReloadHint")})]}),U&&!D&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(qt,{className:"max-h-[400px] p-0",fillContainer:!1,children:U.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:T=>{const j=T.target.closest("a");j&&j.href&&(T.preventDefault(),T.stopPropagation(),v(j.href))},children:t.jsx(Pr,{content:U.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:U.sections.map(T=>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",T.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:T.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:F=>{const P=F.target.closest("a");P&&P.href&&(F.preventDefault(),F.stopPropagation(),v(P.href))},children:t.jsx(Pr,{content:T.content,disableLinkSafety:!0,enableFileReferences:!1})})]},T.version))})})}),C&&I==="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(A,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:u("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:M}),t.jsx("button",{onClick:k,className:le("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:u(p?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:p?t.jsx(A,{name:"check",className:"h-4 w-4"}):t.jsx(A,{name:"clipboard",className:"h-4 w-4"})})]})]}),!C&&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:u("updateDialog.status.downloadingPayload")}),t.jsxs("span",{className:"font-mono text-foreground",children:[S,"%"]})]}),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:`${S}%`}})})]}),(o||h)&&t.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:t.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||h})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:E,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(A,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!C&&!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(A,{name:"download",className:"h-4 w-4"}),u("updateDialog.actions.downloadUpdate")]}),!C&&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(A,{name:"loader",className:"h-4 w-4 animate-spin"}),u("updateDialog.status.downloading")]}),!C&&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(A,{name:"restart",className:"h-4 w-4"}),u("updateDialog.actions.restartToUpdate")]}),C&&!D&&t.jsxs("button",{onClick:b,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(A,{name:"download",className:"h-4 w-4"}),u("updateDialog.actions.updateNow")]}),C&&D&&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(A,{name:"loader",className:"h-4 w-4 animate-spin"}),u("updateDialog.status.updating")]})]})]})]})})},Wi="https://github.com/openchamber/openchamber",Ku="https://discord.gg/ZYRSdnwwKA",qi="https://x.com/openchamber_dev",Uu=800,Kl=({initialUpdateDialogOpen:s=!1})=>{const{t:e}=ot(),[n,a]=l.useState(s),[r,i]=l.useState(!1),[o,d]=l.useState(null),[c,f]=l.useState(null),u=zl(Ps(h=>({info:h.info,checking:h.checking,available:h.available,error:h.error,downloading:h.downloading,downloaded:h.downloaded,progress:h.progress,runtimeType:h.runtimeType,checkForUpdates:h.checkForUpdates,downloadUpdate:h.downloadUpdate,restartToUpdate:h.restartToUpdate}))),{isMobile:p}=Is(),m=o||u.info?.currentVersion||"unknown";l.useEffect(()=>{let h=!1;return(async()=>{try{const E=await pt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!E.ok)return;const S=await E.json().catch(()=>null),C=typeof S?.openchamberVersion=="string"&&S.openchamberVersion.trim().length>0?S.openchamberVersion.trim():null;h||d(C)}catch{h||d(null)}})(),()=>{h=!0}},[]),l.useEffect(()=>{let h=!1;return(async()=>{try{const E=await pt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!E.ok)return;const S=await E.json().catch(()=>null),C=typeof S?.currentVersion=="string"&&S.currentVersion.trim().length>0?S.currentVersion.trim():null;h||f(C)}catch{h||f(null)}})(),()=>{h=!0}},[]);const I=l.useRef(!1);l.useEffect(()=>{if(u.checking)i(!0),I.current=!0;else if(r){const h=setTimeout(()=>{i(!1),I.current&&!u.available&&!u.error&&(q.success(e("settings.openchamber.about.toast.latestVersion")),I.current=!1)},Uu);return()=>clearTimeout(h)}},[e,u.checking,r,u.available,u.error]);const g=u.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(kl,{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:m})}),t.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]})]}),t.jsxs("div",{className:"flex justify-center",children:[!u.available&&!u.error&&t.jsxs(J,{type:"button",variant:"outline",size:"sm",onClick:()=>u.checkForUpdates(),disabled:g,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[g?t.jsx(A,{name:"loader",className:"size-4 animate-spin"}):t.jsx(A,{name:"refresh",className:"size-4"}),e(g?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!g&&u.available&&t.jsxs(J,{type:"button",variant:"default",size:"sm",onClick:()=>a(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[t.jsx(A,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:u.info?.version||""})]})]}),u.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:u.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:Wi,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(A,{name:"github-fill",className:"size-5"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:Ku,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(A,{name:"discord-fill",className:"size-5"}),t.jsx("span",{children:"Discord"})]})]}),t.jsxs("a",{href:qi,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(A,{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(Hi,{open:n,onOpenChange:a,info:u.info,downloading:u.downloading,downloaded:u.downloaded,progress:u.progress,error:u.error,onDownload:u.downloadUpdate,onRestart:u.restartToUpdate,runtimeType:u.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:m})]}),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:[u.checking&&t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!u.checking&&u.available&&t.jsxs(J,{size:"sm",variant:"default",onClick:()=>a(!0),children:[t.jsx(A,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:u.info?.version||""})]}),!u.checking&&!u.available&&!u.error&&t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t.jsx(J,{size:"sm",variant:"outline",onClick:()=>u.checkForUpdates(),disabled:u.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),u.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:u.error})}),t.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[t.jsxs("a",{href:Wi,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(A,{name:"github-fill",className:"h-4 w-4"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:qi,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(A,{name:"twitter-xfill",className:"h-4 w-4"}),t.jsx("span",{children:"@openchamber_dev"})]})]})]}),t.jsx(Hi,{open:n,onOpenChange:a,info:u.info,downloading:u.downloading,downloaded:u.downloaded,progress:u.progress,error:u.error,onDownload:u.downloadUpdate,onRestart:u.restartToUpdate,runtimeType:u.runtimeType})]})},Bv=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),$u=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),Bu=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},Vu=s=>!s||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),Hn="opencode-update-available",da="opencode-upgrade-progress",_u=5e3,Hu=[1e4,6e4],Gi="opencode-update-toast-dismissed-version",Vv=()=>{const{t:s}=ot(),e=Le(o=>o.showOpenCodeUpdateNotifications),n=ge.useRef(new Set),a=ge.useRef(!1);ge.useEffect(()=>{e||q.dismiss(Hn)},[e]);const r=ge.useCallback(()=>{q.dismiss(da),Mn({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),i=ge.useCallback(async()=>{if(!a.current){a.current=!0,q.dismiss(Hn),q.message(s("opencodeUpdate.toast.upgrading.title"),{id:da,description:s("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:t.jsx(A,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const o=await pt("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),d=await o.json().catch(()=>null);if(!o.ok||d?.success===!1)throw new Error(d?.error||o.statusText||s("opencodeUpdate.toast.failed.description"));q.success(s("opencodeUpdate.toast.updated.title"),{id:da,description:d?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:d.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(o){q.error(s("opencodeUpdate.toast.failed.title"),{id:da,description:o instanceof Error?o.message:s("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{a.current=!1}}},[r,s]);return ge.useEffect(()=>{const o=p=>{if(!Le.getState().showOpenCodeUpdateNotifications){q.dismiss(Hn);return}$u({version:p,dismissedVersion:Pi().getItem(Gi),seenVersions:n.current})&&(n.current.add(p),q.info(s("opencodeUpdate.toast.available.title"),{id:Hn,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:()=>{Pi().setItem(Gi,p),Ct({openCodeUpdateToastDismissedVersion:p}),q.dismiss(Hn)}}}))},d=p=>{const m=Bu(p.detail);o(m)};let c=!1;const f=[],u=async p=>{try{const m=await pt("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!m.ok)throw new Error(m.statusText||"OpenCode upgrade status check failed");const I=await m.json().catch(()=>null),g=Vu(I);!c&&g&&o(g)}catch{const m=Hu[p];!c&&m!==void 0&&f.push(setTimeout(()=>{u(p+1)},m))}};return e&&f.push(setTimeout(()=>{u(0)},_u)),window.addEventListener("openchamber:opencode-update-available",d),()=>{c=!0;for(const p of f)clearTimeout(p);window.removeEventListener("openchamber:opencode-update-available",d)}},[i,e,s]),null},_v=()=>{const s=st.c(3),[e,n]=l.useState(Wu),{isUpdating:a}=e;let r,i;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>vd(n),i=[],s[0]=r,s[1]=i):(r=s[0],i=s[1]),l.useEffect(r,i),!a)return null;let o;return s[2]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:t.jsx(kl,{width:80,height:80,isAnimated:!0})}),s[2]=o):o=s[2],o};function Wu(){return yd()}class qu extends l.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(jd,{className:"w-full max-w-md",children:[t.jsx(wd,{className:"text-center",children:t.jsxs(Nd,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(A,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(kd,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(J,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(A,{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 Gu(s){const e=st.c(22),{t:n}=ot();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 o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let d;e[8]!==n?(d=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=d):d=e[9];let c;e[10]!==n?(c=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=c):c=e[11];let f;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==o||e[16]!==d||e[17]!==c?(f={title:a,description:r,sessionLabel:i,detailsSummary:o,resetAction:d,persistentHint:c},e[12]=a,e[13]=r,e[14]=i,e[15]=o,e[16]=d,e[17]=c,e[18]=f):f=e[18];let u;return e[19]!==s||e[20]!==f?(u=t.jsx(qu,{...s,texts:f}),e[19]=s,e[20]=f,e[21]=u):u=e[21],u}const Hv=s=>{const e=st.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=ks(Ju)||void 0;let o;e[0]!==a?(o=t.jsx(Sd,{readOnly:a}),e[0]=a,e[1]=o):o=e[1];let d;return e[2]!==i||e[3]!==o?(d=t.jsx(Gu,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=d):d=e[4],d};function Ju(s){return s.currentSessionId}function sn(s){const e=st.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(Pc,{...n}),e[2]=n,e[3]=a):a=e[3],a}function nn(s){const e=st.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(Ic,{...n}),e[2]=n,e[3]=a):a=e[3],a}function an(s){const e=st.c(20);let n,a,r,i,o;e[0]!==s?({className:a,positionerClassName:r,children:n,style:o,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i,e[5]=o):(n=e[1],a=e[2],r=e[3],i=e[4],o=e[5]);let d;e[6]!==r?(d=le("app-region-no-drag z-50",r),e[6]=r,e[7]=d):d=e[7];let c;e[8]!==o?(c={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",...o},e[8]=o,e[9]=c):c=e[9];let f;e[10]!==a?(f=le(Cd,a),e[10]=a,e[11]=f):f=e[11];let u;e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==f?(u=t.jsx(Dc,{"data-slot":"dropdown-menu-content",style:c,className:f,...i,children:n}),e[12]=n,e[13]=i,e[14]=c,e[15]=f,e[16]=u):u=e[16];let p;return e[17]!==d||e[18]!==u?(p=t.jsx(Ec,{children:t.jsx(Mc,{className:d,children:u})}),e[17]=d,e[18]=u,e[19]=p):p=e[19],p}function qs(s){const e=st.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=le(Pd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(Ac,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}function Wv(s){const e=st.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=le(Id,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(Rc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}const Ul=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),na=s=>{const e=st.c(39),{className:n}=s,{t:a}=ot(),r=os(Qu),i=os(Yu),o=os(Xu),d=fs();let c;e[0]!==r?(c=[...r].sort(Zu),e[0]=r,e[1]=c):c=e[1];const f=c;let u;e:{if(f.length===0){u=null;break e}let O;e[2]!==i||e[3]!==f?(O=f.find(R=>R.id===i)??f[0],e[2]=i,e[3]=f,e[4]=O):O=e[4],u=O}const p=u;if(d||f.length===0)return null;let m;e[5]!==p||e[6]!==a?(m=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]=m):m=e[7];const I=m;let g;e[8]!==I?(g=Ul(I),e[8]=I,e[9]=g):g=e[9];const h=g;let x;e[10]!==n?(x=le(n),e[10]=n,e[11]=x):x=e[11];let E;e[12]!==a?(E=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=E):E=e[13];let S;e[14]!==a?(S=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=S):S=e[15];let C,M;e[16]===Symbol.for("react.memo_cache_sentinel")?(C=le("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),M=t.jsx(A,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=C,e[17]=M):(C=e[16],M=e[17]);let k;e[18]!==h?(k=t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:h}),e[18]=h,e[19]=k):k=e[19];let v;e[20]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=v):v=e[20];let b;e[21]!==k||e[22]!==E||e[23]!==S?(b=t.jsx(us,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":E,title:S,className:C,children:[M,k,v]})}),e[21]=k,e[22]=E,e[23]=S,e[24]=b):b=e[24];const D=p?.id??"";let U;e[25]!==o?(U=O=>{O&&o(O)},e[25]=o,e[26]=U):U=e[26];let T;e[27]!==f?(T=f.map(ep),e[27]=f,e[28]=T):T=e[28];let F;e[29]!==D||e[30]!==U||e[31]!==T?(F=t.jsx(ps,{align:"start",className:"w-auto",children:t.jsx(Ad,{value:D,onValueChange:U,children:T})}),e[29]=D,e[30]=U,e[31]=T,e[32]=F):F=e[32];let j;e[33]!==b||e[34]!==F?(j=t.jsxs(gs,{children:[b,F]}),e[33]=b,e[34]=F,e[35]=j):j=e[35];let P;return e[36]!==j||e[37]!==x?(P=t.jsx("div",{className:x,children:j}),e[36]=j,e[37]=x,e[38]=P):P=e[38],P};function Qu(s){return s.projects}function Yu(s){return s.activeProjectId}function Xu(s){return s.setActiveProject}function Zu(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function ep(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=Ul(e);return t.jsx(Dd,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function tp(s,e){return`opencode:sidebar-group:${s}:${e}`}const zr=s=>{const e=st.c(33),{label:n,count:a,storageKey:r,defaultExpanded:i,children:o}=s,d=i===void 0?!0:i;let c;e[0]!==n||e[1]!==r?(c=tp(r,n),e[0]=n,e[1]=r,e[2]=c):c=e[2];const f=c,u=l.useId();let p;e[3]!==d||e[4]!==f?(p=()=>{try{const F=localStorage.getItem(f);if(F!==null)return F==="true"}catch{}return d},e[3]=d,e[4]=f,e[5]=p):p=e[5];const[m,I]=ge.useState(p);let g,h;e[6]!==m||e[7]!==f?(g=()=>{try{localStorage.setItem(f,String(m))}catch{}},h=[f,m],e[6]=m,e[7]=f,e[8]=g,e[9]=h):(g=e[8],h=e[9]),ge.useEffect(g,h);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>I(sp),e[10]=x):x=e[10];let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=le("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]=E):E=e[11];const S=!m&&"-rotate-90";let C;e[12]!==S?(C=le("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",S),e[12]=S,e[13]=C):C=e[13];let M;e[14]!==C?(M=t.jsx(A,{name:"arrow-down-s",className:C}),e[14]=C,e[15]=M):M=e[15];let k;e[16]!==n?(k=t.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=k):k=e[17];let v;e[18]!==a?(v=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=v):v=e[19];let b;e[20]!==u||e[21]!==m||e[22]!==M||e[23]!==k||e[24]!==v?(b=t.jsxs("button",{type:"button",onClick:x,"aria-expanded":m,"aria-controls":u,className:E,children:[M,k,v]}),e[20]=u,e[21]=m,e[22]=M,e[23]=k,e[24]=v,e[25]=b):b=e[25];const D=!m;let U;e[26]!==o||e[27]!==u||e[28]!==D?(U=t.jsx("div",{id:u,hidden:D,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[26]=o,e[27]=u,e[28]=D,e[29]=U):U=e[29];let T;return e[30]!==b||e[31]!==U?(T=t.jsxs("div",{children:[b,U]}),e[30]=b,e[31]=U,e[32]=T):T=e[32],T};function sp(s){return!s}const np=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},ap=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())},Ji=s=>{const e=ap(np(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 o=Object.keys(i);if(o.length===1&&o[0]==="*"){a[r]=i["*"];continue}a[r]=i}return Object.keys(a).length>0?a:void 0},rp=({onItemSelect:s})=>{const{t:e}=ot(),[n,a]=l.useState(null),[r,i]=l.useState(""),[o,d]=l.useState(null),[c,f]=l.useState(null),[u,p]=l.useState(!1),[m,I]=l.useState(null),{selectedAgentName:g,agents:h,setSelectedAgent:x,setAgentDraft:E,createAgent:S,deleteAgent:C,loadAgents:M}=$a(Ps(w=>({selectedAgentName:w.selectedAgentName,agents:w.agents,setSelectedAgent:w.setSelectedAgent,setAgentDraft:w.setAgentDraft,createAgent:w.createAgent,deleteAgent:w.deleteAgent,loadAgents:w.loadAgents})));l.useEffect(()=>{M()},[M]);const k="bg-background",v=()=>{const w="new-agent";let H=w,Q=1;for(;h.some(z=>z.name===H);)H=`${w}-${Q}`,Q++;E({name:H,scope:"user"}),x(H),s?.()},b=async w=>{if(Dn(w)){q.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(w),f("delete")},D=async w=>{Dn(w)&&(d(w),f("reset"))},U=()=>{d(null),f(null)},T=async()=>{if(!(!o||!c)){p(!0);try{const w=await C(o.name,o.scope);w.ok?(w.requiresManualRestart?q.warning(e("settings.agents.page.toast.savedManualRestart")):c==="delete"?q.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):q.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),U()):c==="delete"?q.error(e("settings.agents.sidebar.toast.deleteFailed")):q.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(w){const H=w instanceof Error?w.message:"",Q=/built-in|not deletable|not found/i.test(H);c==="delete"?q.error(e(Q?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):q.error(e("settings.agents.sidebar.toast.resetFailed"))}p(!1)}},F=w=>{const H=w.name;let Q=1,z=`${H}-copy`;for(;h.some(ne=>ne.name===z);)Q++,z=`${H}-copy-${Q}`;const L=w,X=w.model?.providerID&&w.model?.modelID?`${w.model.providerID}/${w.model.modelID}`:null,$=w;E({name:z,scope:L.scope||"user",description:w.description,model:X,variant:w.variant,temperature:w.temperature,top_p:w.topP,prompt:w.prompt,mode:w.mode,permission:Ji(w.permission),disable:$.disable}),x(z)},j=w=>{i(w.name),a(w)},P=async()=>{if(!n)return;const w=r.trim().replace(/\s+/g,"-");if(!w){q.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(w===n.name){a(null);return}if(h.some(L=>L.name===w)){q.error(e("settings.agents.sidebar.toast.agentExists"));return}const H=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,Q=n,z=await S({name:w,description:n.description,model:H,variant:n.variant,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Ji(n.permission),disable:Q.disable,scope:Q.scope});if(z.ok){const L=await C(n.name,Q.scope);L.ok?(z.requiresManualRestart||L.requiresManualRestart?q.warning(e("settings.agents.page.toast.savedManualRestart")):q.success(e("settings.agents.sidebar.toast.agentRenamed",{name:w})),x(w)):q.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else q.error(e("settings.agents.sidebar.toast.renameFailed"));a(null)},O=w=>{switch(w){case"primary":return t.jsx(A,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(A,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(A,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},R=h.filter(w=>!Ed(w)),V=R.filter(Dn),B=R.filter(w=>!Dn(w)),{groupedCustomAgents:ee,ungroupedCustomAgents:Y}=ge.useMemo(()=>{const w={},H=[];for(const z of B){const L=z;L.group?(w[L.group]||(w[L.group]=[]),w[L.group].push(z)):H.push(z)}return{groupedCustomAgents:Object.keys(w).sort((z,L)=>z.localeCompare(L)).map(z=>({name:z,agents:w[z]})),ungroupedCustomAgents:H}},[B]);return t.jsxs("div",{className:le("flex h-full flex-col",k),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),t.jsx(na,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:R.length})}),t.jsx(J,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:v,children:t.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(qt,{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(A,{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:[V.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")}),V.map(w=>t.jsx(rr,{agent:w,isSelected:g===w.name,onSelect:()=>{x(w.name),s?.()},onReset:()=>D(w),onDuplicate:()=>F(w),getAgentModeIcon:O,isMenuOpen:m===w.name,onMenuOpenChange:H=>I(H?w.name:null)},w.name))]}),B.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),ee.map(({name:w,agents:H})=>t.jsx(zr,{label:w,count:H.length,storageKey:"agents",children:H.map(Q=>t.jsx(rr,{agent:Q,isSelected:g===Q.name,onSelect:()=>{x(Q.name),s?.()},onRename:()=>j(Q),onDelete:()=>b(Q),onDuplicate:()=>F(Q),getAgentModeIcon:O,isMenuOpen:m===Q.name,onMenuOpenChange:z=>I(z?Q.name:null)},Q.name))},w)),Y.map(w=>t.jsx(rr,{agent:w,isSelected:g===w.name,onSelect:()=>{x(w.name),s?.()},onRename:()=>j(w),onDelete:()=>b(w),onDuplicate:()=>F(w),getAgentModeIcon:O,isMenuOpen:m===w.name,onMenuOpenChange:H=>I(H?w.name:null)},w.name))]})]})}),t.jsx(Kt,{open:o!==null&&c!==null,onOpenChange:w=>{!w&&!u&&U()},children:t.jsxs(Ut,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(Ht,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),t.jsxs(Zt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:U,disabled:u,children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:T,disabled:u,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx(Kt,{open:n!==null,onOpenChange:w=>!w&&a(null),children:t.jsxs(Ut,{children:[t.jsxs(Bt,{children:[t.jsx($t,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(Ht,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(tt,{value:r,onChange:w=>i(w.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:w=>{w.key==="Enter"&&P()}}),t.jsxs(Zt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:P,children:e("settings.common.actions.rename")})]})]})})]})},rr=s=>{const e=st.c(52),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,getAgentModeIcon:f,isMenuOpen:u,onMenuOpenChange:p}=s,{t:m}=ot(),I=n;let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=ta(),e[0]=g):g=e[0];const h=g,[x,E]=l.useState(!1);let S;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==m?(S=Q=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(Q,{onClick:z=>{z.stopPropagation(),d()},children:[t.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),t.jsxs(Q,{onClick:z=>{z.stopPropagation(),c()},children:[t.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),o&&t.jsxs(Q,{onClick:z=>{z.stopPropagation(),o()},children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),m("settings.common.actions.reset")]}),i&&t.jsxs(Q,{onClick:z=>{z.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=o,e[5]=m,e[6]=S):S=e[6];const C=S,M=a?"bg-interactive-selection":"hover:bg-interactive-hover";let k;e[7]!==M?(k=le("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",M),e[7]=M,e[8]=k):k=e[8];let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=h?void 0:Q=>{Q.preventDefault(),E(!0)},e[9]=v):v=e[9];let b;e[10]!==k?(b=t.jsx("div",{className:k,onContextMenu:v}),e[10]=k,e[11]=b):b=e[11];let D;e[12]!==n.name?(D=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[12]=n.name,e[13]=D):D=e[13];let U;e[14]!==n.mode||e[15]!==f?(U=f(n.mode),e[14]=n.mode,e[15]=f,e[16]=U):U=e[16];let T;e[17]!==n||e[18]!==I.scope||e[19]!==m?(T=(I.scope||Dn(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:Dn(n)?m("settings.agents.sidebar.badge.system"):I.scope}),e[17]=n,e[18]=I.scope,e[19]=m,e[20]=T):T=e[20];let F;e[21]!==D||e[22]!==U||e[23]!==T?(F=t.jsxs("div",{className:"flex items-center gap-1.5",children:[D,U,T]}),e[21]=D,e[22]=U,e[23]=T,e[24]=F):F=e[24];let j;e[25]!==n.description?(j=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[25]=n.description,e[26]=j):j=e[26];let P;e[27]!==r||e[28]!==F||e[29]!==j?(P=t.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[F,j]}),e[27]=r,e[28]=F,e[29]=j,e[30]=P):P=e[30];let O;e[31]!==p?(O=Q=>{Q&&E(!1),p(Q)},e[31]=p,e[32]=O):O=e[32];let R;e[33]===Symbol.for("react.memo_cache_sentinel")?(R=t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=R):R=e[33];let V;e[34]!==C?(V=t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:C(ws)}),e[34]=C,e[35]=V):V=e[35];let B;e[36]!==u||e[37]!==O||e[38]!==V?(B=t.jsxs(gs,{open:u,onOpenChange:O,children:[R,V]}),e[36]=u,e[37]=O,e[38]=V,e[39]=B):B=e[39];let ee;e[40]!==P||e[41]!==B?(ee=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,B]}),e[40]=P,e[41]=B,e[42]=ee):ee=e[42];let Y;e[43]!==ee||e[44]!==b?(Y=t.jsx(nn,{render:b,children:ee}),e[43]=ee,e[44]=b,e[45]=Y):Y=e[45];let w;e[46]!==C?(w=t.jsx(an,{className:"w-fit min-w-20",children:C(qs)}),e[46]=C,e[47]=w):w=e[47];let H;return e[48]!==x||e[49]!==Y||e[50]!==w?(H=t.jsxs(sn,{open:x,onOpenChange:E,children:[Y,w]}),e[48]=x,e[49]=Y,e[50]=w,e[51]=H):H=e[51],H};function Qi(s,e,n){return Math.min(n,Math.max(e,s))}function ip(s){if(!Number.isFinite(s))return 0;const e=String(s);if(e.includes("e-")){const[,a]=e.split("e-");return Number(a)||0}const n=e.split(".");return n.length===2?n[1].length:0}function Yi(s,e){const n=ip(e);return n<=0?s:Number(s.toFixed(n))}const js=ge.forwardRef((s,e)=>{const n=st.c(125);let a,r,i,o,d,c,f,u,p,m,I,g,h;n[0]!==s?({value:h,onValueChange:f,min:p,max:m,step:I,className:a,containerClassName:r,onBlur:d,disabled:i,fallbackValue:o,onClear:c,emptyLabel:g,...u}=s,n[0]=s,n[1]=a,n[2]=r,n[3]=i,n[4]=o,n[5]=d,n[6]=c,n[7]=f,n[8]=u,n[9]=p,n[10]=m,n[11]=I,n[12]=g,n[13]=h):(a=n[1],r=n[2],i=n[3],o=n[4],d=n[5],c=n[6],f=n[7],u=n[8],p=n[9],m=n[10],I=n[11],g=n[12],h=n[13]);const x=p===void 0?-1/0:p,E=m===void 0?1/0:m,S=I===void 0?1:I,C=g===void 0?"—":g,{t:M}=ot();let k;n[14]!==h?(k=()=>h===void 0?"":String(h),n[14]=h,n[15]=k):k=n[15];const[v,b]=ge.useState(k),{isMobile:D}=Is(),U=ge.useRef(!1),T=ge.useRef(null);let F;n[16]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{if(typeof document>"u"||typeof window>"u")return;T.current?.();const Ae=Fe=>{Fe.preventDefault(),Fe.stopPropagation(),Fe.stopImmediatePropagation?.(),T.current?.()},Pe=window.setTimeout(()=>{T.current?.()},700),Re=()=>{window.clearTimeout(Pe),document.removeEventListener("click",Ae,!0),T.current=null};T.current=Re,document.addEventListener("click",Ae,!0)},n[16]=F):F=n[16];const j=F;let P,O;n[17]===Symbol.for("react.memo_cache_sentinel")?(P=()=>()=>{T.current?.()},O=[],n[17]=P,n[18]=O):(P=n[17],O=n[18]),ge.useEffect(P,O);let R,V;n[19]!==h?(V=()=>{b(h===void 0?"":String(h))},R=[h],n[19]=h,n[20]=R,n[21]=V):(R=n[20],V=n[21]),ge.useEffect(V,R);let B;e:{if(h!==void 0){B=h;break e}if(o!==void 0){B=o;break e}if(Number.isFinite(x)){B=x;break e}B=0}const ee=B;let Y;n[22]!==E||n[23]!==x||n[24]!==f||n[25]!==S?(Y=Ae=>{const Pe=Qi(Ae,x,E);f(Yi(Pe,S))},n[22]=E,n[23]=x,n[24]=f,n[25]=S,n[26]=Y):Y=n[26];const w=Y;let H;n[27]!==w||n[28]!==c?(H=Ae=>{const Pe=Ae.target.value;if(b(Pe),Pe.trim()===""){c?.();return}const Re=Number(Pe);Number.isFinite(Re)&&w(Re)},n[27]=w,n[28]=c,n[29]=H):H=n[29];const Q=H;let z;n[30]!==v||n[31]!==E||n[32]!==x||n[33]!==d||n[34]!==c||n[35]!==f||n[36]!==S||n[37]!==h?(z=Ae=>{if(v.trim()===""){c||b(h===void 0?"":String(h)),d?.(Ae);return}const Pe=Number(v);if(!Number.isFinite(Pe))b(h===void 0?"":String(h));else{const Re=Qi(Pe,x,E),Fe=Yi(Re,S);Fe!==h&&f(Fe),b(String(Fe))}d?.(Ae)},n[30]=v,n[31]=E,n[32]=x,n[33]=d,n[34]=c,n[35]=f,n[36]=S,n[37]=h,n[38]=z):z=n[38];const L=z,X=!!(i||ee>=E),$=!!(i||ee<=x);let ne;n[39]!==ee||n[40]!==w||n[41]!==$||n[42]!==S?(ne=()=>{$||w(ee-S)},n[39]=ee,n[40]=w,n[41]=$,n[42]=S,n[43]=ne):ne=n[43];const re=ne;let _;n[44]!==ee||n[45]!==w||n[46]!==X||n[47]!==S?(_=()=>{X||w(ee+S)},n[44]=ee,n[45]=w,n[46]=X,n[47]=S,n[48]=_):_=n[48];const oe=_;let fe;if(n[49]!==a||n[50]!==r||n[51]!==$||n[52]!==v||n[53]!==C||n[54]!==re||n[55]!==oe||n[56]!==X||n[57]!==D||n[58]!==M||n[59]!==h){fe=Symbol.for("react.early_return_sentinel");e:{const Ae=Re=>Fe=>{Fe.preventDefault(),Fe.stopPropagation(),U.current=!0,j(),Re()},Pe=Re=>Fe=>{if(U.current){U.current=!1,Fe.preventDefault(),Fe.stopPropagation();return}Re()};if(D){let Re;n[61]!==r?(Re=le("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",r),n[61]=r,n[62]=Re):Re=n[62];let Fe;n[63]!==M?(Fe=M("numberInput.actions.decreaseAria"),n[63]=M,n[64]=Fe):Fe=n[64];const Ue=Ae(re),_e=Pe(re),Ke=!$&&"active:bg-interactive-hover";let qe;n[65]!==Ke?(qe=le("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",Ke),n[65]=Ke,n[66]=qe):qe=n[66];let ce;n[67]===Symbol.for("react.memo_cache_sentinel")?(ce=t.jsx(A,{name:"subtract",className:"block h-4 w-4"}),n[67]=ce):ce=n[67];const G=t.jsx("button",{type:"button","aria-label":Fe,disabled:$,onTouchStart:Ue,onClick:_e,className:qe,children:ce});let pe;n[68]!==a?(pe=le("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",a),n[68]=a,n[69]=pe):pe=n[69];const je=h===void 0?C:v;let Ee;n[70]!==pe||n[71]!==je?(Ee=t.jsx("div",{className:pe,"aria-live":"polite",children:je}),n[70]=pe,n[71]=je,n[72]=Ee):Ee=n[72];let Se;n[73]!==M?(Se=M("numberInput.actions.increaseAria"),n[73]=M,n[74]=Se):Se=n[74];const Ve=Ae(oe),Z=Pe(oe),y=!X&&"active:bg-interactive-hover";let ue;n[75]!==y?(ue=le("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",y),n[75]=y,n[76]=ue):ue=n[76];let Ie;n[77]===Symbol.for("react.memo_cache_sentinel")?(Ie=t.jsx(A,{name:"add",className:"block h-4 w-4"}),n[77]=Ie):Ie=n[77];const Oe=t.jsx("button",{type:"button","aria-label":Se,disabled:X,onTouchStart:Ve,onClick:Z,className:ue,children:Ie});let We;n[78]!==Re||n[79]!==G||n[80]!==Ee||n[81]!==Oe?(We=t.jsxs("div",{className:Re,children:[G,Ee,Oe]}),n[78]=Re,n[79]=G,n[80]=Ee,n[81]=Oe,n[82]=We):We=n[82],fe=We;break e}}n[49]=a,n[50]=r,n[51]=$,n[52]=v,n[53]=C,n[54]=re,n[55]=oe,n[56]=X,n[57]=D,n[58]=M,n[59]=h,n[60]=fe}else fe=n[60];if(fe!==Symbol.for("react.early_return_sentinel"))return fe;let xe;n[83]!==r?(xe=le("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",r),n[83]=r,n[84]=xe):xe=n[84];let Ce;n[85]!==M?(Ce=M("numberInput.actions.decreaseAria"),n[85]=M,n[86]=Ce):Ce=n[86];let ve;n[87]!==ee||n[88]!==w||n[89]!==S?(ve=()=>w(ee-S),n[87]=ee,n[88]=w,n[89]=S,n[90]=ve):ve=n[90];let we,ye;n[91]===Symbol.for("react.memo_cache_sentinel")?(we=le("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),ye=t.jsx(A,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=we,n[92]=ye):(we=n[91],ye=n[92]);let se;n[93]!==$||n[94]!==Ce||n[95]!==ve?(se=t.jsx("button",{type:"button","aria-label":Ce,disabled:$,onClick:ve,className:we,children:ye}),n[93]=$,n[94]=Ce,n[95]=ve,n[96]=se):se=n[96];const de=u.inputMode??"numeric";let be;n[97]!==a?(be=le("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",a),n[97]=a,n[98]=be):be=n[98];let W;n[99]!==i||n[100]!==v||n[101]!==L||n[102]!==Q||n[103]!==u||n[104]!==e||n[105]!==de||n[106]!==be?(W=t.jsx("input",{...u,ref:e,type:"text",inputMode:de,value:v,onChange:Q,onBlur:L,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:be}),n[99]=i,n[100]=v,n[101]=L,n[102]=Q,n[103]=u,n[104]=e,n[105]=de,n[106]=be,n[107]=W):W=n[107];let te;n[108]!==M?(te=M("numberInput.actions.increaseAria"),n[108]=M,n[109]=te):te=n[109];let ae;n[110]!==ee||n[111]!==w||n[112]!==S?(ae=()=>w(ee+S),n[110]=ee,n[111]=w,n[112]=S,n[113]=ae):ae=n[113];let me,Me;n[114]===Symbol.for("react.memo_cache_sentinel")?(me=le("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Me=t.jsx(A,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=me,n[115]=Me):(me=n[114],Me=n[115]);let Ne;n[116]!==X||n[117]!==te||n[118]!==ae?(Ne=t.jsx("button",{type:"button","aria-label":te,disabled:X,onClick:ae,className:me,children:Me}),n[116]=X,n[117]=te,n[118]=ae,n[119]=Ne):Ne=n[119];let De;return n[120]!==xe||n[121]!==se||n[122]!==W||n[123]!==Ne?(De=t.jsxs("div",{className:xe,children:[se,W,Ne]}),n[120]=xe,n[121]=se,n[122]=W,n[123]=Ne,n[124]=De):De=n[124],De});js.displayName="NumberInput";const Xi=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Pa=s=>s==="allow"||s==="ask"||s==="deny",gn=(s,e)=>`${s}::${e}`,rn=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&Pa(n.action)&&e.set(gn(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},ma=s=>{const e=new Map;for(const n of rn(s))e.set(gn(n.permission,n.pattern),n);return e},Zi=s=>[...s].sort((e,n)=>{const a=e.permission.localeCompare(n.permission);return a!==0?a:e.pattern.localeCompare(n.pattern)}),op=(s,e)=>{const n=Zi(rn(s)),a=Zi(rn(e));return n.length!==a.length?!1:n.every((r,i)=>{const o=a[i];return r.permission===o.permission&&r.pattern===o.pattern&&r.action===o.action})},lp=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",cp=(s,e)=>rn(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),ir=s=>{if(Array.isArray(s))return rn(s);if(Pa(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(Pa(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))Pa(i)&&e.push({permission:n,pattern:r,action:i})}return e},dp=(s,e)=>{const n=rn(e),a={};for(const i of n)(a[i.permission]||={})[i.pattern]=i.action;const r={};for(const[i,o]of Object.entries(a))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){r[i]=o["*"];continue}r[i]=o}return Object.keys(r).length===0?s:(s!=="allow"&&(r["*"]=s),r)},mp=(s,e)=>{const n=xn(e);if(!n)return[];const r=s.find(i=>i.id===n.providerId)?.models?.find(i=>i.id===n.modelId);return r?.variants?Object.keys(r.variants):[]},up=()=>{const{t:s}=ot(),{isMobile:e}=Is(),n=lt(G=>G.providers),{selectedAgentName:a,getAgentByName:r,createAgent:i,updateAgent:o,agents:d,agentDraft:c,setAgentDraft:f}=$a(Ps(G=>({selectedAgentName:G.selectedAgentName,getAgentByName:G.getAgentByName,createAgent:G.createAgent,updateAgent:G.updateAgent,agents:G.agents,agentDraft:G.agentDraft,setAgentDraft:G.setAgentDraft}))),u=a?r(a):null,p=!!(c&&c.name===a&&!u),[m,I]=l.useState(""),[g,h]=l.useState("user"),[x,E]=l.useState(""),[S,C]=l.useState("subagent"),[M,k]=l.useState(""),[v,b]=l.useState(""),[D,U]=l.useState(void 0),[T,F]=l.useState(void 0),[j,P]=l.useState(""),[O,R]=l.useState("allow"),[V,B]=l.useState([]),[ee,Y]=l.useState([]),[w,H]=l.useState(""),[Q,z]=l.useState("*"),[L,X]=l.useState(!1),[$,ne]=l.useState(!1),re=l.useRef(null),_=ys(G=>G.currentDirectory??null),[oe,fe]=l.useState([]),xe=l.useMemo(()=>mp(n,M),[M,n]),Ce=xe.length>0,ve=l.useMemo(()=>!v||!xe.includes(v)?"__default":v,[v,xe]),we=Ce&&(!v||xe.includes(v)),ye=Md(G=>G.permission);l.useEffect(()=>{let G=!1;return(async()=>{const je=await vs.listToolIds({directory:_});if(G)return;const Ee=new Set(["write","patch","multiedit"]),Se=je.map(Ve=>typeof Ve=="string"?Ve.trim():"").filter(Boolean).filter(Ve=>Ve!=="*").filter(Ve=>Ve!=="invalid").filter(Ve=>!Ee.has(Ve));fe(Array.from(new Set(Se)).sort((Ve,Z)=>Ve.localeCompare(Z)))})(),()=>{G=!0}},[_]);const se=l.useMemo(()=>{const G=new Set;for(const pe of d){const je=rn(ir(pe.permission));for(const Ee of je)Ee.permission&&Ee.permission!=="*"&&Ee.permission!=="invalid"&&G.add(Ee.permission)}for(const pe of Object.values(ye))for(const je of pe){const Ee=je.permission?.trim();Ee&&Ee!=="invalid"&&G.add(Ee)}for(const pe of oe)G.add(pe);return Array.from(G).sort((pe,je)=>pe.localeCompare(je))},[d,ye,oe]),de=l.useMemo(()=>ma(V),[V]),be=l.useMemo(()=>ma(ee),[ee]),W=l.useCallback(G=>be.get(gn(G,"*"))?.action,[be]),te=l.useCallback(G=>ee.filter(pe=>pe.permission===G&&pe.pattern!=="*").sort((pe,je)=>pe.pattern.localeCompare(je.pattern)),[ee]),ae=l.useMemo(()=>{const G=new Set;for(const pe of Xi)G.add(pe);for(const pe of se)G.add(pe);return Array.from(G).sort((pe,je)=>pe.localeCompare(je))},[se]),me=l.useCallback(G=>{const pe=G==="*"?O:W(G)??O,je=te(G),Ee=!1,Se=je.reduce((Z,y)=>(Z[y.action]=(Z[y.action]??0)+1,Z),{allow:0,ask:0,deny:0}),Ve=["allow","ask","deny"].filter(Z=>Se[Z]>0).map(Z=>`${Se[Z]} ${Z}`).join(", ");return{defaultAction:pe,patternRulesCount:je.length,patternSummary:Ve,hasDefaultHint:Ee}},[te,W,O]),Me=l.useCallback(G=>s(G==="allow"?"settings.common.permission.allow":G==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),Ne=l.useCallback(G=>G==="global"?s("settings.common.scope.global"):Me(G),[Me,s]),De=l.useMemo(()=>{const G=new Set;for(const pe of Xi)G.add(pe);for(const pe of se)G.add(pe);return Array.from(G).sort((pe,je)=>pe.localeCompare(je))},[se]),Ae=l.useCallback((G,pe,je)=>{Y(Ee=>{const Se=ma(Ee);return Se.set(gn(G,pe),{permission:G,pattern:pe,action:je}),Array.from(Se.values())})},[]),Pe=l.useCallback((G,pe)=>{Y(je=>{const Ee=ma(je);return Ee.delete(gn(G,pe)),Array.from(Ee.values())})},[]),Re=l.useCallback((G,pe)=>{const je=de.get(gn(G,pe));if(je){Ae(G,pe,je.action);return}Pe(G,pe)},[de,Pe,Ae]),Fe=l.useCallback((G,pe,je)=>{Ae(G,pe,je)},[Ae]),Ue=l.useCallback(G=>{R(G),Y(pe=>pe.filter(je=>!(je.pattern==="*"&&je.action===G)))},[]),_e=l.useCallback(G=>{const pe=w.trim();if(!pe){q.error(s("settings.agents.page.toast.permissionNameRequired"));return}const je=Q.trim()||"*";if(pe==="*"&&je==="*"){Ue(G),H(""),z("*");return}je==="*"&&pe!=="*"&&G===O?Pe(pe,"*"):Ae(pe,je,G),H(""),z("*")},[O,w,Q,Pe,Ue,s,Ae]),Ke=l.useCallback(G=>G==="*"?s("settings.agents.page.permissions.defaultLabel"):G==="webfetch"?"WebFetch":G==="websearch"?"WebSearch":G==="codesearch"?"CodeSearch":G==="doom_loop"?"Doom Loop":G==="external_directory"?"External Directory":G==="todowrite"?"TodoWrite":G==="todoread"?"TodoRead":G.split(/[_-]+/g).filter(Boolean).map(pe=>pe.charAt(0).toUpperCase()+pe.slice(1)).join(" "),[s]);l.useEffect(()=>{H(""),z("*");const G=pe=>{const je=rn(pe),Ee=lp(je),Se=cp(je,Ee);return R(Ee),B(Se),Y(Se),{global:Ee,rules:Se}};if(p&&c){const pe=c.name||"",je=c.scope||"user",Ee=c.description||"",Se=c.mode||"subagent",Ve=c.model||"",Z=c.variant||"",y=c.temperature??void 0,ue=c.top_p??void 0,Ie=c.prompt||"";I(pe),h(je),E(Ee),C(Se),k(Ve),b(Z),U(y),F(ue),P(Ie);const Oe=ir(c.permission),We=G(Oe);re.current={draftName:pe,draftScope:je,description:Ee,mode:Se,model:Ve,variant:Z,temperature:y,topP:ue,prompt:Ie,globalPermission:We.global,permissionRules:We.rules};return}if(u&&a===u.name){const pe=u.description||"",je=u.mode||"subagent",Ee=u.model?.providerID&&u.model?.modelID?`${u.model.providerID}/${u.model.modelID}`:"",Se=u.variant||"",Ve=u.temperature,Z=u.topP,y=u.prompt||"";E(pe),C(je),k(Ee),b(Se),U(Ve),F(Z),P(y);const ue=G(ir(u.permission));re.current={draftName:"",draftScope:"user",description:pe,mode:je,model:Ee,variant:Se,temperature:Ve,topP:Z,prompt:y,globalPermission:ue.global,permissionRules:ue.rules}}},[c,p,u,a]);const qe=l.useMemo(()=>{const G=re.current;return G?!!(p&&(m!==G.draftName||g!==G.draftScope)||x!==G.description||S!==G.mode||M!==G.model||v!==G.variant||D!==G.temperature||T!==G.topP||j!==G.prompt||O!==G.globalPermission||!op(ee,G.permissionRules)):!1},[x,m,g,O,p,S,M,ee,j,D,T,v]),ce=async()=>{const G=p?m.trim().replace(/\s+/g,"-"):a?.trim();if(!G){q.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(p&&d.some(pe=>pe.name===G)){q.error(s("settings.agents.sidebar.toast.agentExists"));return}ne(!0);try{const pe=M.trim(),je=v.trim(),Ee=j.trim(),Se=dp(O,ee),Ve={name:G,description:x.trim()||void 0,mode:S,model:pe===""?null:pe,variant:je===""?null:je||void 0,temperature:D??null,top_p:T??null,prompt:Ee||(p?void 0:null),permission:Se,scope:p?g:void 0};let Z;p?(Z=await i(Ve),Z.ok&&f(null)):Z=await o(G,Ve),Z.ok?Z.requiresManualRestart?q.warning(s("settings.agents.page.toast.savedManualRestart")):q.success(s(p?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):q.error(s(p?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(pe){console.error("Error saving agent:",pe);const je=pe instanceof Error&&pe.message?pe.message:s("settings.agents.page.toast.saveUnexpectedError");q.error(je)}finally{ne(!1)}};return a?t.jsx(qt,{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(tt,{value:m,onChange:G=>I(G.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Tt,{value:g,onValueChange:G=>h(G),children:[t.jsx(Ft,{className:"w-fit min-w-[100px]",children:t.jsx(zt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ht,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(hs,{value:x,onChange:G=>E(G.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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.modeTooltip")})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":S==="primary",onClick:()=>C("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":S==="subagent",onClick:()=>C("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":S==="all",onClick:()=>C("all"),className:"!font-normal",children:s("settings.agents.page.mode.all")})]})]})})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.modelParameters")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{"data-settings-item":"agents.model",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(La,{providerId:xn(M)?.providerId??"",modelId:xn(M)?.modelId??"",onChange:(G,pe)=>{k(G&&pe?`${G}/${pe}`:""),b("")}})})]}),t.jsxs("div",{"data-settings-item":"agents.variant",className:le("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:le("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{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:le("flex items-center gap-2",e?"w-full":"w-fit"),children:we?t.jsxs(Tt,{value:ve,onValueChange:G=>b(G==="__default"?"":G),children:[t.jsx(Ft,{className:le("max-w-full",e?"w-full":"w-fit min-w-[10rem]"),children:t.jsx(zt,{placeholder:s("settings.agents.page.field.variantPlaceholder"),children:G=>G==="__default"?s("chat.modelControls.default"):G})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"__default",children:s("chat.modelControls.default")}),xe.map(G=>t.jsx(ht,{value:G,children:G},G))]})]}):t.jsxs(t.Fragment,{children:[t.jsx(tt,{value:v,onChange:G=>b(G.target.value),placeholder:s("settings.agents.page.field.variantPlaceholder"),disabled:!M&&!v,className:le("h-7 w-40",e&&"w-full")}),v&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>b(""),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(A,{name:"close",className:"h-3.5 w-3.5"})})]})})]}),t.jsxs("div",{"data-settings-item":"agents.temperature",className:le("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:le("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{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:le("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(js,{value:D,fallbackValue:.7,onValueChange:U,onClear:()=>U(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),D!==void 0&&t.jsx(J,{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(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{"data-settings-item":"agents.top-p",className:le("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:le("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{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:le("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(js,{value:T,fallbackValue:.9,onValueChange:F,onClear:()=>F(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),T!==void 0&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(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(A,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),t.jsxs("div",{"data-settings-item":"agents.system-prompt",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.systemPrompt")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(hs,{value:j,onChange:G=>P(G.target.value),placeholder:s("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),t.jsxs("div",{"data-settings-item":"agents.permissions",className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.toolPermissions")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>X(G=>!G),children:s(L?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),L?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(Tt,{value:O,onValueChange:G=>Ue(G),children:[t.jsx(Ft,{className:"w-[100px]",children:t.jsx(zt,{children:Me(O)})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ht,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ht,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:ae.filter(G=>G!=="*").map(G=>{const pe=Ke(G),{defaultAction:je,patternRulesCount:Ee}=me(G),Se=W(G),Ve=Se??"global",Z=te(G),y=["allow","ask","deny"].filter(ue=>ue!==O);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:pe}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:G})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Ee>0?s("settings.agents.page.permissions.globalSummary",{summary:je}):je})]}),t.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Se&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>Re(G,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Tt,{value:Ve,onValueChange:ue=>{if(ue==="global"){Pe(G,"*");return}Ae(G,"*",ue)},children:[t.jsx(Ft,{className:"w-[90px]",children:t.jsx(zt,{children:Ne(Ve)})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"global",children:s("settings.common.scope.global")}),y.map(ue=>t.jsx(ht,{value:ue,className:"capitalize",children:Me(ue)},ue))]})]})]}),Z.map(ue=>{const Ie=gn(ue.permission,ue.pattern),Oe=de.get(Ie),We=!Oe,rt=!!(Oe&&Oe.action!==ue.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:ue.pattern}),We&&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")}),(We||rt)&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>We?Pe(ue.permission,ue.pattern):Re(ue.permission,ue.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Tt,{value:ue.action,onValueChange:it=>Fe(ue.permission,ue.pattern,it),children:[t.jsx(Ft,{className:"w-[90px]",children:t.jsx(zt,{children:Me(ue.action)})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ht,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ht,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},Ie)})]})]},G)})}),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(Tt,{value:w,onValueChange:H,children:[t.jsx(Ft,{className:"w-full sm:w-[160px]",children:w?t.jsx("span",{className:"truncate",children:Ke(w)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Lt,{children:De.map(G=>t.jsx(ht,{value:G,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:Ke(G)})})},G))})]}),t.jsx(tt,{value:Q,onChange:G=>z(G.target.value),placeholder:s("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>_e("allow"),children:s("settings.common.permission.allow")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>_e("ask"),children:s("settings.common.permission.ask")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>_e("deny"),children:s("settings.common.permission.deny")})]})]})]})]}):t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ae.map((G,pe)=>{const{defaultAction:je,patternRulesCount:Ee,patternSummary:Se,hasDefaultHint:Ve}=me(G),Z=Ke(G),y=Ve?`${je} (env blocked)`:je;return t.jsxs("div",{className:le("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",pe>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:Z}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:G})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Ee>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:y})}):t.jsx("span",{className:le("typography-micro capitalize px-1.5 py-0.5 rounded",y==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":y==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:y}),Ee>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:Se})})]})]},G)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:ce,disabled:$||!qe,size:"xs",className:"!font-normal",children:s($?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{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")})]})})},pp="~/.config/opencode/AGENTS.md",$l=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},gp=s=>s.length>0&&!s.endsWith(`
|
|
2
|
-
`)?`${s}
|
|
3
|
-
`:s,ua={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},hp=(s,e)=>s==="custom"?e:Td(s),fp=s=>s==="custom"?"custom":Sl(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"},to=async(s,e)=>{const n=await pt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(s)});if(!n.ok)throw new Error(await $l(n,e))},xp=()=>{const{t:s}=ot(),[e,n]=l.useState(""),[a,r]=l.useState(ua.responseStyleEnabled),[i,o]=l.useState(ua.responseStylePreset),[d,c]=l.useState(ua.responseStyleCustomInstructions),[f,u]=l.useState(!0),[p,m]=l.useState(!1),[I,g]=l.useState(""),h=l.useRef(null);l.useEffect(()=>{const C=new AbortController;return(async()=>{try{const[k,v]=await Promise.all([pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:C.signal}),pt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:C.signal})]);let b=ua;if(k.ok){const D=await k.json();b={...b,responseStyleEnabled:D.responseStyleEnabled===!0,responseStylePreset:fp(D.responseStylePreset),responseStyleCustomInstructions:typeof D.responseStyleCustomInstructions=="string"?D.responseStyleCustomInstructions:""},typeof D.globalBehaviorPrompt=="string"&&(b={...b,prompt:D.globalBehaviorPrompt})}if(!b.prompt.trim()&&v.ok){const D=await v.json();typeof D.content=="string"&&(b={...b,prompt:D.content})}n(b.prompt),r(b.responseStyleEnabled),o(b.responseStylePreset),c(b.responseStyleCustomInstructions),g(b.prompt),h.current={enabled:b.responseStyleEnabled,preset:b.responseStylePreset,custom:b.responseStyleCustomInstructions}}catch(k){k.name!=="AbortError"&&console.warn("Failed to load behavior settings:",k)}finally{u(!1)}})(),()=>C.abort()},[]),l.useEffect(()=>{if(f)return;const C=h.current;if(C&&C.enabled===a&&C.preset===i&&C.custom===d)return;const M={enabled:a,preset:i,custom:d},k=setTimeout(async()=>{try{await to({responseStyleEnabled:M.enabled,responseStylePreset:M.preset,responseStyleCustomInstructions:M.custom},s("settings.behavior.page.toast.saveFailed")),h.current=M}catch(v){const b=v instanceof Error?v.message:s("settings.behavior.page.toast.saveFailed");q.error(b)}},400);return()=>clearTimeout(k)},[a,i,d,f,s]);const x=hp(i,d),E=e!==I,S=async()=>{m(!0);try{const C=gp(e),M=await pt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:C})});if(!M.ok)throw new Error(await $l(M,s("settings.behavior.page.toast.saveFailed")));await to({globalBehaviorPrompt:C},s("settings.behavior.page.toast.saveFailed")),n(C),g(C),q.success(s("settings.behavior.page.toast.saved"))}catch(C){console.error("Failed to save behavior:",C);const M=C instanceof Error?C.message:s("settings.behavior.page.toast.saveFailed");q.error(M)}finally{m(!1)}};return t.jsx(qt,{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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{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:pp})})]})})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsx(hs,{value:e,onChange:C=>n(C.target.value),placeholder:s("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),t.jsx(J,{onClick:S,disabled:p||!E||f,size:"xs",className:"!font-normal",children:s(p?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),t.jsxs("div",{"data-settings-item":"behavior.response-style",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.responseStyle")}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{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(St,{checked:a,onChange:r,disabled:f,ariaLabel:s("settings.behavior.page.responseStyle.enableAria")}),s("settings.behavior.page.responseStyle.enable")]}),t.jsxs(Tt,{value:i,onValueChange:C=>o(C),disabled:f||!a,children:[t.jsx(Ft,{className:"w-full sm:w-56",size:"lg",children:t.jsx(zt,{children:C=>C==="custom"?s("settings.behavior.page.responseStyle.option.custom"):Sl(C)?s(eo[C]):null})}),t.jsxs(Lt,{children:[Rd.map(C=>t.jsx(ht,{value:C,children:s(eo[C])},C)),t.jsx(ht,{value:"custom",children:s("settings.behavior.page.responseStyle.option.custom")})]})]}),t.jsx(hs,{value:x,onChange:C=>c(C.target.value),placeholder:s("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!a||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},bp=s=>{const e=st.c(169),{onItemSelect:n}=s,{t:a}=ot(),[r,i]=l.useState(null),[o,d]=l.useState(""),[c,f]=l.useState(null),[u,p]=l.useState(null),[m,I]=l.useState(!1),[g,h]=l.useState(null),{selectedCommandName:x,commands:E,setSelectedCommand:S,setCommandDraft:C,createCommand:M,deleteCommand:k,loadCommands:v}=Ba(Ps(yp)),b=Hs(vp),D=Hs(jp);let U,T;e[0]!==v||e[1]!==D?(U=()=>{v(),D()},T=[v,D],e[0]=v,e[1]=D,e[2]=U,e[3]=T):(U=e[2],T=e[3]),l.useEffect(U,T);let F;e[4]!==b?(F=new Set(b.map(wp)),e[4]=b,e[5]=F):F=e[5];const j=F;let P;if(e[6]!==E||e[7]!==j){let he;e[9]!==j?(he=et=>!j.has(et.name),e[9]=j,e[10]=he):he=e[10],P=E.filter(he),e[6]=E,e[7]=j,e[8]=P}else P=e[8];const O=P;let R,V;e[11]!==x||e[12]!==S||e[13]!==j?(R=()=>{x&&j.has(x)&&S(null)},V=[x,S,j],e[11]=x,e[12]=S,e[13]=j,e[14]=R,e[15]=V):(R=e[14],V=e[15]),l.useEffect(R,V);let B;e[16]!==E||e[17]!==n||e[18]!==C||e[19]!==S?(B=()=>{let he="new-command",et=1;for(;E.some(Xe=>Xe.name===he);)he=`new-command-${et}`,et++;C({name:he,scope:"user"}),S(he),n?.()},e[16]=E,e[17]=n,e[18]=C,e[19]=S,e[20]=B):B=e[20];const ee=B;let Y;e[21]!==a?(Y=async he=>{if(Rn(he)){q.error(a("settings.commands.sidebar.toast.builtInCannotDelete"));return}f(he),p("delete")},e[21]=a,e[22]=Y):Y=e[22];const w=Y;let H;e[23]===Symbol.for("react.memo_cache_sentinel")?(H=async he=>{Rn(he)&&(f(he),p("reset"))},e[23]=H):H=e[23];const Q=H;let z;e[24]===Symbol.for("react.memo_cache_sentinel")?(z=()=>{f(null),p(null)},e[24]=z):z=e[24];const L=z;let X;e[25]!==c||e[26]!==u||e[27]!==k||e[28]!==a?(X=async()=>{if(!c||!u)return;I(!0),await k(c.name)?(u==="delete"?q.success(a("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):q.success(a("settings.commands.sidebar.toast.commandReset",{name:c.name})),L()):u==="delete"?q.error(a("settings.commands.sidebar.toast.deleteFailed")):q.error(a("settings.commands.sidebar.toast.resetFailed")),I(!1)},e[25]=c,e[26]=u,e[27]=k,e[28]=a,e[29]=X):X=e[29];const $=X;let ne;e[30]!==E||e[31]!==C||e[32]!==S?(ne=he=>{const et=he.name;let Xe=1,He=`${et}-copy`;for(;E.some(bt=>bt.name===He);)Xe++,He=`${et}-copy-${Xe}`;C({name:He,scope:he.scope||"user",description:he.description,template:he.template,agent:he.agent,model:he.model}),S(He)},e[30]=E,e[31]=C,e[32]=S,e[33]=ne):ne=e[33];const re=ne;let _;e[34]===Symbol.for("react.memo_cache_sentinel")?(_=he=>{d(he.name),i(he)},e[34]=_):_=e[34];const oe=_;let fe;e[35]!==E||e[36]!==M||e[37]!==k||e[38]!==r||e[39]!==o||e[40]!==S||e[41]!==a?(fe=async()=>{if(!r)return;const he=o.trim().replace(/\s+/g,"-");if(!he){q.error(a("settings.commands.sidebar.toast.commandNameRequired"));return}if(he===r.name){i(null);return}if(E.some(Xe=>Xe.name===he)){q.error(a("settings.commands.sidebar.toast.commandExists"));return}await M({name:he,description:r.description,template:r.template,agent:r.agent,model:r.model})?await k(r.name)?(q.success(`Command renamed to "${he}"`),S(he)):q.error(a("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):q.error(a("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=E,e[36]=M,e[37]=k,e[38]=r,e[39]=o,e[40]=S,e[41]=a,e[42]=fe):fe=e[42];const xe=fe;let Ce,ve,we,ye,se,de;if(e[43]!==O||e[44]!==ee||e[45]!==w||e[46]!==re||e[47]!==n||e[48]!==g||e[49]!==x||e[50]!==S||e[51]!==a){const he=O.filter(Rn),et=O.filter(Np);e[58]===Symbol.for("react.memo_cache_sentinel")?(se=le("flex h-full flex-col","bg-background"),e[58]=se):se=e[58];let Xe;e[59]!==a?(Xe=a("settings.commands.sidebar.title"),e[59]=a,e[60]=Xe):Xe=e[60];let He;e[61]!==Xe?(He=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:Xe}),e[61]=Xe,e[62]=He):He=e[62];let bt;e[63]===Symbol.for("react.memo_cache_sentinel")?(bt=t.jsx(na,{className:"mb-3"}),e[63]=bt):bt=e[63];let wt;e[64]!==O.length||e[65]!==a?(wt=a("settings.commands.sidebar.total",{count:O.length}),e[64]=O.length,e[65]=a,e[66]=wt):wt=e[66];let Pt;e[67]!==wt?(Pt=t.jsx("span",{className:"typography-meta text-muted-foreground",children:wt}),e[67]=wt,e[68]=Pt):Pt=e[68];let ie;e[69]===Symbol.for("react.memo_cache_sentinel")?(ie=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[69]=ie):ie=e[69];let Be;e[70]!==ee?(Be=t.jsx(J,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:ee,children:ie}),e[70]=ee,e[71]=Be):Be=e[71];let Je;e[72]!==Pt||e[73]!==Be?(Je=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Pt,Be]}),e[72]=Pt,e[73]=Be,e[74]=Je):Je=e[74],e[75]!==He||e[76]!==Je?(de=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[He,bt,Je]}),e[75]=He,e[76]=Je,e[77]=de):de=e[77],Ce=qt,ve="flex-1 min-h-0",we="space-y-1 px-3 py-2",ye=O.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{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:[he.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")}),[...he].sort(kp).map(Ge=>t.jsx(so,{command:Ge,isSelected:x===Ge.name,onSelect:()=>{S(Ge.name),n?.()},onReset:()=>Q(Ge),onDuplicate:()=>re(Ge),isMenuOpen:g===Ge.name,onMenuOpenChange:ut=>h(ut?Ge.name:null)},Ge.name))]}),et.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.commands.sidebar.section.custom")}),[...et].sort(Sp).map(Ge=>t.jsx(so,{command:Ge,isSelected:x===Ge.name,onSelect:()=>{S(Ge.name),n?.()},onRename:()=>oe(Ge),onDelete:()=>w(Ge),onDuplicate:()=>re(Ge),isMenuOpen:g===Ge.name,onMenuOpenChange:ut=>h(ut?Ge.name:null)},Ge.name))]})]}),e[43]=O,e[44]=ee,e[45]=w,e[46]=re,e[47]=n,e[48]=g,e[49]=x,e[50]=S,e[51]=a,e[52]=Ce,e[53]=ve,e[54]=we,e[55]=ye,e[56]=se,e[57]=de}else Ce=e[52],ve=e[53],we=e[54],ye=e[55],se=e[56],de=e[57];let be;e[78]!==Ce||e[79]!==ve||e[80]!==we||e[81]!==ye?(be=t.jsx(Ce,{outerClassName:ve,className:we,children:ye}),e[78]=Ce,e[79]=ve,e[80]=we,e[81]=ye,e[82]=be):be=e[82];const W=c!==null&&u!==null;let te;e[83]!==m?(te=he=>{!he&&!m&&L()},e[83]=m,e[84]=te):te=e[84];let ae;e[85]!==u||e[86]!==a?(ae=a(u==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=u,e[86]=a,e[87]=ae):ae=e[87];let me;e[88]!==ae?(me=t.jsx($t,{children:ae}),e[88]=ae,e[89]=me):me=e[89];let Me;e[90]!==c?.name||e[91]!==u||e[92]!==a?(Me=u==="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]=u,e[92]=a,e[93]=Me):Me=e[93];let Ne;e[94]!==Me?(Ne=t.jsx(Ht,{children:Me}),e[94]=Me,e[95]=Ne):Ne=e[95];let De;e[96]!==me||e[97]!==Ne?(De=t.jsxs(Bt,{children:[me,Ne]}),e[96]=me,e[97]=Ne,e[98]=De):De=e[98];let Ae;e[99]!==a?(Ae=a("settings.common.actions.cancel"),e[99]=a,e[100]=Ae):Ae=e[100];let Pe;e[101]!==m||e[102]!==Ae?(Pe=t.jsx(J,{size:"sm",variant:"ghost",onClick:L,disabled:m,children:Ae}),e[101]=m,e[102]=Ae,e[103]=Pe):Pe=e[103];let Re;e[104]!==u||e[105]!==a?(Re=a(u==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=u,e[105]=a,e[106]=Re):Re=e[106];let Fe;e[107]!==$||e[108]!==m||e[109]!==Re?(Fe=t.jsx(J,{size:"sm",onClick:$,disabled:m,children:Re}),e[107]=$,e[108]=m,e[109]=Re,e[110]=Fe):Fe=e[110];let Ue;e[111]!==Pe||e[112]!==Fe?(Ue=t.jsxs(Zt,{children:[Pe,Fe]}),e[111]=Pe,e[112]=Fe,e[113]=Ue):Ue=e[113];let _e;e[114]!==De||e[115]!==Ue?(_e=t.jsxs(Ut,{className:"max-w-md",children:[De,Ue]}),e[114]=De,e[115]=Ue,e[116]=_e):_e=e[116];let Ke;e[117]!==W||e[118]!==te||e[119]!==_e?(Ke=t.jsx(Kt,{open:W,onOpenChange:te,children:_e}),e[117]=W,e[118]=te,e[119]=_e,e[120]=Ke):Ke=e[120];const qe=r!==null;let ce;e[121]===Symbol.for("react.memo_cache_sentinel")?(ce=he=>!he&&i(null),e[121]=ce):ce=e[121];let G;e[122]!==a?(G=a("settings.commands.sidebar.renameDialog.title"),e[122]=a,e[123]=G):G=e[123];let pe;e[124]!==G?(pe=t.jsx($t,{children:G}),e[124]=G,e[125]=pe):pe=e[125];const je=r?.name??"";let Ee;e[126]!==a||e[127]!==je?(Ee=a("settings.commands.sidebar.renameDialog.description",{name:je}),e[126]=a,e[127]=je,e[128]=Ee):Ee=e[128];let Se;e[129]!==Ee?(Se=t.jsx(Ht,{children:Ee}),e[129]=Ee,e[130]=Se):Se=e[130];let Ve;e[131]!==pe||e[132]!==Se?(Ve=t.jsxs(Bt,{children:[pe,Se]}),e[131]=pe,e[132]=Se,e[133]=Ve):Ve=e[133];let Z;e[134]===Symbol.for("react.memo_cache_sentinel")?(Z=he=>d(he.target.value),e[134]=Z):Z=e[134];let y;e[135]!==a?(y=a("settings.commands.sidebar.renameDialog.placeholder"),e[135]=a,e[136]=y):y=e[136];let ue;e[137]!==xe?(ue=he=>{he.key==="Enter"&&xe()},e[137]=xe,e[138]=ue):ue=e[138];let Ie;e[139]!==o||e[140]!==y||e[141]!==ue?(Ie=t.jsx(tt,{value:o,onChange:Z,placeholder:y,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:ue}),e[139]=o,e[140]=y,e[141]=ue,e[142]=Ie):Ie=e[142];let Oe;e[143]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>i(null),e[143]=Oe):Oe=e[143];let We;e[144]!==a?(We=a("settings.common.actions.cancel"),e[144]=a,e[145]=We):We=e[145];let rt;e[146]!==We?(rt=t.jsx(J,{size:"sm",variant:"ghost",onClick:Oe,children:We}),e[146]=We,e[147]=rt):rt=e[147];let it;e[148]!==a?(it=a("settings.common.actions.rename"),e[148]=a,e[149]=it):it=e[149];let nt;e[150]!==xe||e[151]!==it?(nt=t.jsx(J,{size:"sm",onClick:xe,children:it}),e[150]=xe,e[151]=it,e[152]=nt):nt=e[152];let dt;e[153]!==rt||e[154]!==nt?(dt=t.jsxs(Zt,{children:[rt,nt]}),e[153]=rt,e[154]=nt,e[155]=dt):dt=e[155];let Ye;e[156]!==Ve||e[157]!==Ie||e[158]!==dt?(Ye=t.jsxs(Ut,{children:[Ve,Ie,dt]}),e[156]=Ve,e[157]=Ie,e[158]=dt,e[159]=Ye):Ye=e[159];let $e;e[160]!==qe||e[161]!==Ye?($e=t.jsx(Kt,{open:qe,onOpenChange:ce,children:Ye}),e[160]=qe,e[161]=Ye,e[162]=$e):$e=e[162];let mt;return e[163]!==se||e[164]!==de||e[165]!==be||e[166]!==Ke||e[167]!==$e?(mt=t.jsxs("div",{className:se,children:[de,be,Ke,$e]}),e[163]=se,e[164]=de,e[165]=be,e[166]=Ke,e[167]=$e,e[168]=mt):mt=e[168],mt},so=s=>{const e=st.c(47),{command:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,isMenuOpen:f,onMenuOpenChange:u}=s,{t:p}=ot();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=ta(),e[0]=m):m=e[0];const I=m,[g,h]=l.useState(!1);let x;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==p?(x=Y=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(Y,{onClick:w=>{w.stopPropagation(),d()},children:[t.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),t.jsxs(Y,{onClick:w=>{w.stopPropagation(),c()},children:[t.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),o&&t.jsxs(Y,{onClick:w=>{w.stopPropagation(),o()},children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),i&&t.jsxs(Y,{onClick:w=>{w.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{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]=o,e[5]=p,e[6]=x):x=e[6];const E=x,S=a?"bg-interactive-selection":"hover:bg-interactive-hover";let C;e[7]!==S?(C=le("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",S),e[7]=S,e[8]=C):C=e[8];let M;e[9]===Symbol.for("react.memo_cache_sentinel")?(M=I?void 0:Y=>{Y.preventDefault(),h(!0)},e[9]=M):M=e[9];let k;e[10]!==C?(k=t.jsx("div",{className:C,onContextMenu:M}),e[10]=C,e[11]=k):k=e[11];let v;e[12]!==n.name?(v=t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[12]=n.name,e[13]=v):v=e[13];let b;e[14]!==n||e[15]!==p?(b=(n.scope||Rn(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:Rn(n)?p("settings.agents.sidebar.badge.system"):n.scope}),e[14]=n,e[15]=p,e[16]=b):b=e[16];let D;e[17]!==v||e[18]!==b?(D=t.jsxs("div",{className:"flex items-center gap-2",children:[v,b]}),e[17]=v,e[18]=b,e[19]=D):D=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 T;e[22]!==r||e[23]!==U||e[24]!==D?(T=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:[D,U]}),e[22]=r,e[23]=U,e[24]=D,e[25]=T):T=e[25];let F;e[26]!==u?(F=Y=>{Y&&h(!1),u(Y)},e[26]=u,e[27]=F):F=e[27];let j;e[28]===Symbol.for("react.memo_cache_sentinel")?(j=t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=j):j=e[28];let P;e[29]!==E?(P=t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:E(ws)}),e[29]=E,e[30]=P):P=e[30];let O;e[31]!==f||e[32]!==F||e[33]!==P?(O=t.jsxs(gs,{open:f,onOpenChange:F,children:[j,P]}),e[31]=f,e[32]=F,e[33]=P,e[34]=O):O=e[34];let R;e[35]!==T||e[36]!==O?(R=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[T,O]}),e[35]=T,e[36]=O,e[37]=R):R=e[37];let V;e[38]!==R||e[39]!==k?(V=t.jsx(nn,{render:k,children:R}),e[38]=R,e[39]=k,e[40]=V):V=e[40];let B;e[41]!==E?(B=t.jsx(an,{className:"w-fit min-w-20",children:E(qs)}),e[41]=E,e[42]=B):B=e[42];let ee;return e[43]!==g||e[44]!==V||e[45]!==B?(ee=t.jsxs(sn,{open:g,onOpenChange:h,children:[V,B]}),e[43]=g,e[44]=V,e[45]=B,e[46]=ee):ee=e[46],ee};function yp(s){return{selectedCommandName:s.selectedCommandName,commands:s.commands,setSelectedCommand:s.setSelectedCommand,setCommandDraft:s.setCommandDraft,createCommand:s.createCommand,deleteCommand:s.deleteCommand,loadCommands:s.loadCommands}}function vp(s){return s.skills}function jp(s){return s.loadSkills}function wp(s){return s.name}function Np(s){return!Rn(s)}function kp(s,e){return s.name.localeCompare(e.name)}function Sp(s,e){return s.name.localeCompare(e.name)}const Cp=()=>{const{t:s}=ot(),{selectedCommandName:e,getCommandByName:n,createCommand:a,updateCommand:r,commands:i,commandDraft:o,setCommandDraft:d}=Ba(Ps(F=>({selectedCommandName:F.selectedCommandName,getCommandByName:F.getCommandByName,createCommand:F.createCommand,updateCommand:F.updateCommand,commands:F.commands,commandDraft:F.commandDraft,setCommandDraft:F.setCommandDraft}))),c=e?n(e):null,f=!!(o&&o.name===e&&!c),[u,p]=l.useState(""),[m,I]=l.useState("user"),[g,h]=l.useState(""),[x,E]=l.useState(""),[S,C]=l.useState(""),[M,k]=l.useState(""),[v,b]=l.useState(!1),D=l.useRef(null);l.useEffect(()=>{if(f&&o){const F=o.name||"",j=o.scope||"user",P=o.description||"",O=o.agent||"",R=o.model||"",V=o.template||"";p(F),I(j),h(P),E(O),C(R),k(V),D.current={draftName:F,draftScope:j,description:P,agent:O,model:R,template:V}}else if(c){const F=c.description||"",j=c.agent||"",P=c.model||"",O=c.template||"";h(F),E(j),C(P),k(O),D.current={draftName:"",draftScope:"user",description:F,agent:j,model:P,template:O}}},[c,f,e,i,o]);const U=l.useMemo(()=>{const F=D.current;return F?!!(f&&(u!==F.draftName||m!==F.draftScope)||g!==F.description||x!==F.agent||S!==F.model||M!==F.template):!1},[x,g,u,m,f,S,M]),T=async()=>{const F=f?u.trim().replace(/\s+/g,"-"):e?.trim();if(!F){q.error(s("settings.commands.sidebar.toast.commandNameRequired"));return}if(!M.trim()){q.error(s("settings.commands.page.toast.templateRequired"));return}if(f&&i.some(j=>j.name===F)){q.error(s("settings.commands.sidebar.toast.commandExists"));return}b(!0);try{const j=x.trim(),P=S.trim(),O=M.trim(),R={name:F,description:g.trim()||void 0,agent:j===""?null:j,model:P===""?null:P,template:O,scope:f?m:void 0};let V;f?(V=await a(R),V&&d(null)):V=await r(F,R),V?q.success(s(f?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):q.error(s(f?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(j){console.error("Error saving command:",j),q.error(s("settings.commands.page.toast.saveUnexpectedError"))}finally{b(!1)}};return e?t.jsx(qt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:f?s("settings.commands.page.title.new"):`/${e}`}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(f?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.identity")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[f&&t.jsxs("div",{"data-settings-item":"commands.name",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.commands.page.field.commandName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),t.jsx(tt,{value:u,onChange:F=>p(F.target.value),placeholder:s("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Tt,{value:m,onValueChange:F=>I(F),children:[t.jsx(Ft,{className:"w-fit min-w-[100px]",children:t.jsx(zt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ht,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(hs,{value:g,onChange:F=>h(F.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(Cl,{agentName:x,onChange:F=>E(F)})})]}),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(La,{providerId:xn(S)?.providerId??"",modelId:xn(S)?.modelId??"",onChange:(F,j)=>{C(F&&j?`${F}/${j}`:"")}})})]})]})]}),t.jsxs("div",{"data-settings-item":"commands.template",className:"mb-2",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.template")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(hs,{value:M,onChange:F=>k(F.target.value),placeholder:s("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),t.jsx("div",{className:"mt-2 px-2",children:t.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",s("settings.commands.page.templateHint.userInput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",s("settings.commands.page.templateHint.shellOutput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"@file"})," ",s("settings.commands.page.templateHint.fileContents")]})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:T,disabled:v||!U,size:"xs",className:"!font-normal",children:s(v?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{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")})]})})},no=s=>{switch(s){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},ao=s=>{const e=st.c(5),{tone:n,enabled:a}=s;if(!a){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=o):o=e[0],o}let r;e[1]!==n?(r=le("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},Pp=s=>{const e=st.c(120),{onItemSelect:n}=s,{t:a}=ot(),{mcpServers:r,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:d,loadMcpConfigs:c,deleteMcp:f}=Ln(Ps(Ip)),u=ys(Dp);let p;e[0]!==u?(p=Se=>Se.getStatusForDirectory(u??null),e[0]=u,e[1]=p):p=e[1];const m=cs(p),I=cs(Ap),g=cs(Ep),[h,x]=l.useState(null),[E,S]=l.useState(!1),[C,M]=l.useState(null),[k,v]=l.useState(null),[b,D]=l.useState(!1);let U;e[2]!==r?(U=r.filter(Mp),e[2]=r,e[3]=U):U=e[3];const T=U;let F;e[4]!==r?(F=r.filter(Rp),e[4]=r,e[5]=F):F=e[5];const j=F;let P,O;e[6]!==c?(P=()=>{c()},O=[c],e[6]=c,e[7]=P,e[8]=O):(P=e[7],O=e[8]),l.useEffect(P,O);let R;e[9]!==u||e[10]!==g||e[11]!==b||e[12]!==I?(R=()=>{if(b)return;D(!0);const Se=new Promise(Tp);Promise.all([I({directory:u,silent:!0}),Se]).then(()=>{const Ve=g(u);Ve&&q.error(Ve)}).finally(()=>{D(!1)})},e[9]=u,e[10]=g,e[11]=b,e[12]=I,e[13]=R):R=e[13];const V=R;let B;e[14]!==r||e[15]!==n||e[16]!==d||e[17]!==o?(B=()=>{let Se="new-mcp-server",Ve=1;for(;r.some(y=>y.name===Se);)Se=`new-mcp-server-${Ve}`,Ve++;d({name:Se,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(Se),n?.()},e[14]=r,e[15]=n,e[16]=d,e[17]=o,e[18]=B):B=e[18];const ee=B;let Y;e[19]!==f||e[20]!==h||e[21]!==a?(Y=async()=>{if(!h)return;S(!0);const Se=await f(h.name);Se.ok?Se.reloadFailed?q.warning(Se.message||`MCP server "${h.name}" deleted, but OpenCode reload failed`,{description:Se.warning||a("settings.mcp.sidebar.toast.refreshListIfStale")}):q.success(Se.message||a("settings.mcp.sidebar.toast.serverDeleted",{name:h.name})):q.error(a("settings.mcp.sidebar.toast.deleteFailed")),x(null),S(!1)},e[19]=f,e[20]=h,e[21]=a,e[22]=Y):Y=e[22];const w=Y;let H;e[23]!==a?(H=(Se,Ve)=>t.jsxs(Ve,{onClick:Z=>{Z.stopPropagation(),x(Se)},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]}),e[23]=a,e[24]=H):H=e[24];const Q=H;let z;e[25]===Symbol.for("react.memo_cache_sentinel")?(z=le("flex h-full flex-col","bg-background"),e[25]=z):z=e[25];let L;e[26]!==a?(L=a("settings.mcp.sidebar.title"),e[26]=a,e[27]=L):L=e[27];let X;e[28]!==L?(X=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:L}),e[28]=L,e[29]=X):X=e[29];let $;e[30]!==a?($=a("settings.mcp.sidebar.actions.refreshStatusAria"),e[30]=a,e[31]=$):$=e[31];let ne;e[32]!==a?(ne=a("settings.mcp.sidebar.actions.refreshStatusTitle"),e[32]=a,e[33]=ne):ne=e[33];const re=b&&"animate-spin";let _;e[34]!==re?(_=le("h-4 w-4",re),e[34]=re,e[35]=_):_=e[35];let oe;e[36]!==_?(oe=t.jsx(A,{name:"refresh",className:_}),e[36]=_,e[37]=oe):oe=e[37];let fe;e[38]!==V||e[39]!==b||e[40]!==$||e[41]!==ne||e[42]!==oe?(fe=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:b,onClick:V,"aria-label":$,title:ne,children:oe}),e[38]=V,e[39]=b,e[40]=$,e[41]=ne,e[42]=oe,e[43]=fe):fe=e[43];let xe;e[44]!==X||e[45]!==fe?(xe=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[X,fe]}),e[44]=X,e[45]=fe,e[46]=xe):xe=e[46];let Ce;e[47]===Symbol.for("react.memo_cache_sentinel")?(Ce=t.jsx(na,{className:"mb-3"}),e[47]=Ce):Ce=e[47];let ve;e[48]!==r.length||e[49]!==a?(ve=a("settings.mcp.sidebar.total",{count:r.length}),e[48]=r.length,e[49]=a,e[50]=ve):ve=e[50];let we;e[51]!==ve?(we=t.jsx("span",{className:"typography-meta text-muted-foreground",children:ve}),e[51]=ve,e[52]=we):we=e[52];let ye;e[53]!==a?(ye=a("settings.mcp.sidebar.actions.addServerTitle"),e[53]=a,e[54]=ye):ye=e[54];let se;e[55]===Symbol.for("react.memo_cache_sentinel")?(se=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[55]=se):se=e[55];let de;e[56]!==ee||e[57]!==ye?(de=t.jsx(J,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:ee,title:ye,children:se}),e[56]=ee,e[57]=ye,e[58]=de):de=e[58];let be;e[59]!==we||e[60]!==de?(be=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[we,de]}),e[59]=we,e[60]=de,e[61]=be):be=e[61];let W;e[62]!==xe||e[63]!==be?(W=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[xe,Ce,be]}),e[62]=xe,e[63]=be,e[64]=W):W=e[64];let te;e[65]!==r.length||e[66]!==m||e[67]!==n||e[68]!==C||e[69]!==T||e[70]!==Q||e[71]!==k||e[72]!==i||e[73]!==d||e[74]!==o||e[75]!==a||e[76]!==j?(te=t.jsx(qt,{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(A,{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:[T.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")}),T.map(Se=>{const Ve=m[Se.name],Z=no(Ve?.status),y=i===Se.name,ue=ta();return t.jsxs(sn,{open:k===Se.name,onOpenChange:Ie=>v(Ie?Se.name:null),children:[t.jsxs(nn,{render:t.jsx("div",{className:le("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",y?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ue?void 0:Ie=>{Ie.preventDefault(),v(Se.name)}}),children:[t.jsxs("button",{onClick:()=>{o(Se.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(ao,{tone:Z,enabled:Se.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Se.name}),t.jsx("span",{title:Se.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Se.type==="local"?t.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(A,{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:Se.type==="local"?Se.command?.join(" ")??"":Se.url??""})]}),t.jsxs(gs,{open:C===Se.name,onOpenChange:Ie=>{Ie&&v(null),M(Ie?Se.name:null)},children:[t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:Q(Se,ws)})]})]}),t.jsx(an,{className:"w-fit min-w-20",children:Q(Se,qs)})]},Se.name)})]}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.mcp.sidebar.group.userServers")}),j.map(Se=>{const Ve=m[Se.name],Z=no(Ve?.status),y=i===Se.name,ue=ta();return t.jsxs(sn,{open:k===Se.name,onOpenChange:Ie=>v(Ie?Se.name:null),children:[t.jsxs(nn,{render:t.jsx("div",{className:le("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",y?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ue?void 0:Ie=>{Ie.preventDefault(),v(Se.name)}}),children:[t.jsxs("button",{onClick:()=>{o(Se.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(ao,{tone:Z,enabled:Se.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Se.name}),t.jsx("span",{title:Se.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Se.type==="local"?t.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(A,{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:Se.type==="local"?Se.command?.join(" ")??"":Se.url??""})]}),t.jsxs(gs,{open:C===Se.name,onOpenChange:Ie=>{Ie&&v(null),M(Ie?Se.name:null)},children:[t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:Q(Se,ws)})]})]}),t.jsx(an,{className:"w-fit min-w-20",children:Q(Se,qs)})]},Se.name)})]})]})}),e[65]=r.length,e[66]=m,e[67]=n,e[68]=C,e[69]=T,e[70]=Q,e[71]=k,e[72]=i,e[73]=d,e[74]=o,e[75]=a,e[76]=j,e[77]=te):te=e[77];const ae=h!==null;let me;e[78]!==E?(me=Se=>{!Se&&!E&&x(null)},e[78]=E,e[79]=me):me=e[79];let Me;e[80]!==a?(Me=a("settings.mcp.sidebar.deleteDialog.title"),e[80]=a,e[81]=Me):Me=e[81];let Ne;e[82]!==Me?(Ne=t.jsx($t,{children:Me}),e[82]=Me,e[83]=Ne):Ne=e[83];const De=h?.name||"";let Ae;e[84]!==a||e[85]!==De?(Ae=a("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:De}),e[84]=a,e[85]=De,e[86]=Ae):Ae=e[86];let Pe;e[87]===Symbol.for("react.memo_cache_sentinel")?(Pe=t.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[87]=Pe):Pe=e[87];let Re;e[88]!==Ae?(Re=t.jsxs(Ht,{children:[Ae," ",Pe,"."]}),e[88]=Ae,e[89]=Re):Re=e[89];let Fe;e[90]!==Ne||e[91]!==Re?(Fe=t.jsxs(Bt,{children:[Ne,Re]}),e[90]=Ne,e[91]=Re,e[92]=Fe):Fe=e[92];let Ue;e[93]===Symbol.for("react.memo_cache_sentinel")?(Ue=()=>x(null),e[93]=Ue):Ue=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]!==E||e[97]!==_e?(Ke=t.jsx(J,{size:"sm",variant:"ghost",onClick:Ue,disabled:E,children:_e}),e[96]=E,e[97]=_e,e[98]=Ke):Ke=e[98];let qe;e[99]!==E||e[100]!==a?(qe=a(E?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[99]=E,e[100]=a,e[101]=qe):qe=e[101];let ce;e[102]!==w||e[103]!==E||e[104]!==qe?(ce=t.jsx(J,{size:"sm",onClick:w,disabled:E,children:qe}),e[102]=w,e[103]=E,e[104]=qe,e[105]=ce):ce=e[105];let G;e[106]!==Ke||e[107]!==ce?(G=t.jsxs(Zt,{children:[Ke,ce]}),e[106]=Ke,e[107]=ce,e[108]=G):G=e[108];let pe;e[109]!==Fe||e[110]!==G?(pe=t.jsxs(Ut,{className:"max-w-md",children:[Fe,G]}),e[109]=Fe,e[110]=G,e[111]=pe):pe=e[111];let je;e[112]!==ae||e[113]!==me||e[114]!==pe?(je=t.jsx(Kt,{open:ae,onOpenChange:me,children:pe}),e[112]=ae,e[113]=me,e[114]=pe,e[115]=je):je=e[115];let Ee;return e[116]!==W||e[117]!==te||e[118]!==je?(Ee=t.jsxs("div",{className:z,children:[W,te,je]}),e[116]=W,e[117]=te,e[118]=je,e[119]=Ee):Ee=e[119],Ee};function Ip(s){return{mcpServers:s.mcpServers,selectedMcpName:s.selectedMcpName,setSelectedMcp:s.setSelectedMcp,setMcpDraft:s.setMcpDraft,loadMcpConfigs:s.loadMcpConfigs,deleteMcp:s.deleteMcp}}function Dp(s){return s.currentDirectory}function Ap(s){return s.refresh}function Ep(s){return s.getErrorForDirectory}function Mp(s){return s.scope==="project"}function Rp(s){return s.scope!=="project"}function Tp(s){return setTimeout(s,500)}function Ls(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function Wn(s){return Array.isArray(s)&&s.every(e=>typeof e=="string")}function Ts(s,e){return e!==void 0?{ok:!1,error:s,parsed:e}:{ok:!1,error:s}}function pa(s,e,n){const a=Fp(n),r=typeof n.url=="string"?n.url.trim():"",i=ro(n,"env","environment"),o=ro(n,"headers"),d=Lp(n),c=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",f=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",u=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():"",m=Op(n),I=zp(n);return{ok:!0,name:s,type:e,command:a,url:r,environment:i,headers:o,oauthEnabled:d,oauthClientId:c,oauthClientSecret:f,oauthScope:u,oauthRedirectUri:p,timeout:m,enabled:I}}function Fp(s){const e=s.command,n=s.args;if(Wn(e)&&Wn(n))return[...e,...n];if(Wn(e))return e;if(typeof e=="string"&&e.trim()){const a=e.trim().split(/\s+/);return Wn(n)?[...a,...n]:a}return Wn(n)?n:[]}function ro(s,...e){for(const n of e){const a=s[n];if(!Ls(a))continue;const r=Object.entries(a).filter(([i,o])=>i&&typeof o=="string");if(r.length>0)return r.map(([i,o])=>({key:i,value:String(o)}))}return[]}function Lp(s){if(s.oauth===!1||s.oauth===null||s.oauth===void 0||!Ls(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 Op(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 zp(s){return"disabled"in s&&s.disabled===!0?!1:"enabled"in s?!!s.enabled:!0}function Kp(s){const e=s.mcpServers;if(Ls(e)){const a=Object.keys(e);if(a.length===1){const r=a[0],i=e[r];if(Ls(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"&&Ls(r)});if(n.length===1){const a=n[0],r=s[a];if(Bl(r))return{name:a,entry:r}}return null}function Bl(s){return s.type==="local"||s.type==="remote"||Array.isArray(s.command)||typeof s.url=="string"||Array.isArray(s.args)}function Up(s,e){let n;try{const d=s.trim();if(!d)return Ts("No JSON content provided");n=JSON.parse(d)}catch(d){return Ts(d instanceof Error?`Invalid JSON: ${d.message}`:"Invalid JSON")}if(!Ls(n))return Ts("Expected a JSON object, not an array or primitive");const a=n,r=a.mcpServers;if(Ls(r)){const d=Object.keys(r);if(d.length===0)return Ts("mcpServers object is empty",n);if(d.length>1)return Ts("Paste one server at a time. Found "+d.length+" servers in mcpServers",n);const c=d[0],f=r[c];return Ls(f)?pa(c,ga(f),f):Ts("Server entry is not a valid object",n)}const i=a.mcp;if(Ls(i)){const d=Object.keys(i);if(d.length===0)return Ts("mcp object is empty",n);if(d.length>1)return Ts("Paste one server at a time. Found "+d.length+" servers in mcp",n);const c=d[0],f=i[c];return Ls(f)?pa(c,ga(f),f):Ts("Server entry in mcp is not a valid object",n)}const o=Kp(a);if(o)return pa(o.name,ga(o.entry),o.entry);if(Bl(a)){const d=ga(a),c=typeof a.name=="string"&&a.name.trim()?a.name.trim():e?.fallbackName;return pa(c,d,a)}return Ts("No recognizable MCP server configuration found in JSON",n)}function ga(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 $p(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 Bp="/mcp/oauth/callback",Vp=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}},_p=s=>{const e=Hp(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}},Vl=s=>{const e=s.get("state");return typeof e!="string"?null:e.trim()||null},Hp=s=>{if(typeof s!="string"||!s.trim())return null;const e=Vp(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}},bn=Fc,yn=s=>{const e=st.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 o;e[5]!==n||e[6]!==a?(o=n&&ge.isValidElement(a)?{render:a}:{children:a},e[5]=n,e[6]=a,e[7]=o):o=e[7];const d=o;let c;e[8]!==r?(c=le("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",r),e[8]=r,e[9]=c):c=e[9];let f;return e[10]!==i||e[11]!==d||e[12]!==c?(f=t.jsx(Tc,{className:c,...i,...d}),e[10]=i,e[11]=d,e[12]=c,e[13]=f):f=e[13],f},vn=s=>{const e=st.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=le("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(Lc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i};function Wp(s){const e=[];let n="",a=!1,r=!1;for(let i=0;i<s.length;i++){const o=s[i];if(o==="'"&&!r){a=!a;continue}if(o==='"'&&!a){r=!r;continue}if((o===" "||o===" ")&&!a&&!r){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function qp(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:_p(n.searchParams),stateKey:Vl(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Gp=({value:s,onChange:e,pasteCommandTitle:n,pasteCommandLabel:a,pasteSuccess:r,clipboardReadFailed:i,preview:o})=>{const[d,c]=l.useState(()=>s.join(`
|
|
4
|
-
`)),f=l.useRef(s);l.useEffect(()=>{JSON.stringify(f.current)!==JSON.stringify(s)&&(f.current=s,c(s.join(`
|
|
5
|
-
`)))},[s]);const u=m=>{const I=m.split(`
|
|
6
|
-
`).filter(g=>g.trim().length>0);e(I)},p=async()=>{try{const I=(await navigator.clipboard.readText()).trim(),g=I.includes(`
|
|
7
|
-
`)?I.split(`
|
|
8
|
-
`).filter(h=>h.trim()):Wp(I);c(g.join(`
|
|
9
|
-
`)),e(g),q.success(r(g.length))}catch{q.error(i)}};return t.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[t.jsx("div",{className:"flex items-center justify-end gap-2",children:t.jsxs(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:p,type:"button",title:n,children:[t.jsx(A,{name:"clipboard",className:"h-3 w-3"}),a]})}),t.jsx(hs,{value:d,onChange:m=>{c(m.target.value),u(m.target.value)},onBlur:()=>{const m=d.split(`
|
|
10
|
-
`).map(I=>I.trimEnd()).join(`
|
|
11
|
-
`);c(m),u(m)},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:o(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((m,I)=>t.jsxs("span",{className:"block",children:[t.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",I,"]"]}),m]},I))})})]})]})},Jp=s=>s.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),io=({value:s,onChange:e,keyTransform:n=Jp,keyPlaceholder:a="API_KEY",keyInputClassName:r="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:o="Paste KEY=VALUE lines from clipboard",noPairsFoundError:d,importSuccess:c,clipboardReadFailed:f,keyLabel:u,valueLabel:p,valuePlaceholder:m,hideValueTitle:I,showValueTitle:g,addVariable:h,plainTextWarning:x,removeVariableAria:E})=>{const[S,C]=l.useState(new Set),M=()=>e([...s,{key:"",value:""}]),k=T=>{e(s.filter((F,j)=>j!==T)),C(F=>{const j=new Set(F);return j.delete(T),j})},v=(T,F,j)=>{const P=[...s];P[T]={...P[T],[F]:j},e(P)},b=T=>{C(F=>{const j=new Set(F);return j.has(T)?j.delete(T):j.add(T),j})},D=async()=>{try{const T=await navigator.clipboard.readText(),F=[];for(const P of T.split(`
|
|
15
|
-
`)){const O=P.trim();if(!O||O.startsWith("#"))continue;const R=O.indexOf("=");if(R===-1)continue;const V=O.slice(0,R).trim();let B=O.slice(R+1).trim();(B.startsWith('"')&&B.endsWith('"')||B.startsWith("'")&&B.endsWith("'"))&&(B=B.slice(1,-1)),V&&F.push({key:V,value:B})}if(F.length===0){q.error(d);return}const j=[...s];for(const P of F){const O=j.findIndex(R=>R.key===P.key);O!==-1?j[O]=P:j.push(P)}e(j),q.success(c(F.length))}catch{q.error(f)}},U=s.some(T=>T.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:u}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:p})]}),t.jsxs(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:D,type:"button",title:o,children:[t.jsx(A,{name:"clipboard",className:"h-3 w-3"}),i]})]}),t.jsx("div",{className:"space-y-1.5",children:s.map((T,F)=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(tt,{value:T.key,onChange:j=>v(F,"key",n(j.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(tt,{type:S.has(F)?"text":"password",value:T.value,onChange:j=>v(F,"value",j.target.value),placeholder:m,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:()=>b(F),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:S.has(F)?I:g,children:S.has(F)?t.jsx(A,{name:"eye-off",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"eye",className:"h-3.5 w-3.5"})})]}),t.jsx(J,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>k(F),"aria-label":E,children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},F))}),t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:M,type:"button",children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),h]}),U&&t.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},oo=s=>{const e=st.c(14),{status:n,enabled:a,getStatusLabel:r,variant:i}=s,o=i===void 0?"compact":i;if(!a||!n)return null;let d,c;if(e[0]!==r||e[1]!==n||e[2]!==o){c=Symbol.for("react.early_return_sentinel");e:{const m={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(o==="pill"){const I=le("typography-micro font-medium rounded-full px-2 py-0.5",m.text,m.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:I,children:["● ",g]});break e}d=le("typography-micro font-medium",m.text)}e[0]=r,e[1]=n,e[2]=o,e[3]=d,e[4]=c}else d=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let f;e[8]!==r||e[9]!==n?(f=r(n),e[8]=r,e[9]=n,e[10]=f):f=e[10];let u;return e[11]!==d||e[12]!==f?(u=t.jsxs("span",{className:d,children:["● ",f]}),e[11]=d,e[12]=f,e[13]=u):u=e[13],u},Qp=(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")}},Yp=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)]"}},Xp=(s,e,n,a)=>!!(s==="failed"||s==="needs_auth"||s==="needs_client_registration"||e||n||a),lo=(s,e)=>{if(typeof window>"u")return null;const n=new URL(Bp,Kn()||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()},Zp=async s=>{const e=await pt("/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")}},eg=async s=>{const e=await pt(`/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},qn=async s=>{typeof s!="string"||!s.trim()||await pt(`/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},tg=(s,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${s??"__none__"}::${n}`},sg=()=>{const{t:s}=ot(),e=l.useCallback((ke,vt)=>s(ke,vt),[s]),{selectedMcpName:n,mcpServers:a,mcpDraft:r,setMcpDraft:i,setSelectedMcp:o,getMcpByName:d,createMcp:c,updateMcp:f,deleteMcp:u}=Ln(Ps(ke=>({selectedMcpName:ke.selectedMcpName,mcpServers:ke.mcpServers,mcpDraft:ke.mcpDraft,setMcpDraft:ke.setMcpDraft,setSelectedMcp:ke.setSelectedMcp,getMcpByName:ke.getMcpByName,createMcp:ke.createMcp,updateMcp:ke.updateMcp,deleteMcp:ke.deleteMcp}))),p=ys(ke=>ke.currentDirectory),m=l.useMemo(()=>fs(),[]),I=cs(ke=>ke.getStatusForDirectory(p??null)),g=cs(ke=>ke.getDiagnosticForDirectory(p??null)),h=cs(ke=>ke.refresh),x=cs(ke=>ke.connect),E=cs(ke=>ke.disconnect),S=cs(ke=>ke.startAuth),C=cs(ke=>ke.completeAuth),M=cs(ke=>ke.clearAuth),k=cs(ke=>ke.testConnection),v=n?d(n):null,b=!!(r&&r.name===n&&!v),[D,U]=l.useState(""),[T,F]=l.useState("user"),[j,P]=l.useState("local"),[O,R]=l.useState([]),[V,B]=l.useState(""),[ee,Y]=l.useState([]),[w,H]=l.useState([]),[Q,z]=l.useState(!0),[L,X]=l.useState(""),[$,ne]=l.useState(""),[re,_]=l.useState(""),[oe,fe]=l.useState(""),[xe,Ce]=l.useState(""),[ve,we]=l.useState(!0),[ye,se]=l.useState(!1),[de,be]=l.useState(!1),[W,te]=l.useState(!1),[ae,me]=l.useState(!1),[Me,Ne]=l.useState(!1),[De,Ae]=l.useState(!1),[Pe,Re]=l.useState(!1),[Fe,Ue]=l.useState(!1),[_e,Ke]=l.useState(null),[qe,ce]=l.useState(null),[G,pe]=l.useState(""),[je,Ee]=l.useState(!1),Se=l.useRef(0),Ve=l.useRef(!1),[Z,y]=l.useState(!1),[ue,Ie]=l.useState(!1),[Oe,We]=l.useState(""),[rt,it]=l.useState(null),nt=l.useMemo(()=>tg(n,p),[p,n]),dt=l.useRef(nt),Ye=l.useRef(null),$e=l.useCallback(()=>{Ke(null),ce(null),pe(""),Ee(!1),Se.current=0,Ue(!1),Ne(!1),Ae(!1),Ve.current=!1},[]),mt=l.useCallback(()=>{We(""),it(null),Ie(!0)},[]),he=l.useCallback(async()=>{try{const ke=await navigator.clipboard.readText();We(ke),it(null)}catch{q.error(s("settings.mcp.page.toast.clipboardReadFailed"))}},[s]),et=l.useCallback(()=>{const ke=Up(Oe,{fallbackName:D});if(!ke.ok){it(ke.error);return}const Nt=$p(ke,{name:D,scope:T,type:j,command:O,url:V,environment:ee,headers:w,oauthEnabled:Q,oauthClientId:L,oauthClientSecret:$,oauthScope:re,oauthRedirectUri:oe,timeout:xe,enabled:ve},{isNewServer:b});U(Nt.name),P(Nt.type),R(Nt.command??[]),B(Nt.url??""),Y(Nt.environment??[]),H(Nt.headers??[]),z(Nt.oauthEnabled??!1),X(Nt.oauthClientId??""),ne(Nt.oauthClientSecret??""),_(Nt.oauthScope??""),fe(Nt.oauthRedirectUri??""),Ce(Nt.timeout??""),we(Nt.enabled??!0),Ie(!1),We(""),it(null),q.success(s("settings.mcp.page.toast.configImported"))},[Oe,D,T,j,O,V,ee,w,Q,L,$,re,oe,xe,ve,b,s]);l.useEffect(()=>{if(b&&r){U(r.name),F(r.scope||"user"),P(r.type),R(r.command),B(r.url),Y(r.environment),H(r.headers),z(r.oauthEnabled),X(r.oauthClientId),ne(r.oauthClientSecret),_(r.oauthScope),fe(r.oauthRedirectUri),Ce(r.timeout),we(r.enabled),y(!1),Ye.current={mcpType:r.type,command:r.command,url:r.url,envEntries:r.environment,headerEntries:r.headers,oauthEnabled:r.oauthEnabled,oauthClientId:r.oauthClientId,oauthClientSecret:r.oauthClientSecret,oauthScope:r.oauthScope,oauthRedirectUri:r.oauthRedirectUri,timeout:r.timeout,enabled:r.enabled};return}if(v){F(v.scope==="project"?"project":"user");const ke=Oi(v.environment),vt=v.type==="remote"?v:null,Nt=Oi(vt?.headers),Ze=vt?.oauth,kt=Ze&&typeof Ze=="object"?Ze:null,Wt=Ze!==!1,Jt=v.type,as=Jt==="local"?v.command??[]:[],zs=Jt==="remote"?v.url??"":"",xs=typeof vt?.timeout=="number"&&Number.isFinite(vt.timeout)?String(vt.timeout):"";P(Jt),R(as),B(zs),Y(ke),H(Nt),z(Wt),X(Wt?kt?.clientId??"":""),ne(Wt?kt?.clientSecret??"":""),_(Wt?kt?.scope??"":""),fe(Wt?kt?.redirectUri??"":""),Ce(xs),we(v.enabled),y(!1),Ye.current={mcpType:Jt,command:as,url:zs,envEntries:ke,headerEntries:Nt,oauthEnabled:Wt,oauthClientId:Wt?kt?.clientId??"":"",oauthClientSecret:Wt?kt?.clientSecret??"":"",oauthScope:Wt?kt?.scope??"":"",oauthRedirectUri:Wt?kt?.redirectUri??"":"",timeout:xs,enabled:v.enabled}}},[v,b,r]);const Xe=l.useMemo(()=>{const ke=Ye.current;return ke?j!==ke.mcpType||ve!==ke.enabled||JSON.stringify(O)!==JSON.stringify(ke.command)||V!==ke.url||JSON.stringify(ee)!==JSON.stringify(ke.envEntries)||JSON.stringify(w)!==JSON.stringify(ke.headerEntries)||Q!==ke.oauthEnabled||L!==ke.oauthClientId||$!==ke.oauthClientSecret||re!==ke.oauthScope||oe!==ke.oauthRedirectUri||xe!==ke.timeout:!1},[j,O,V,ee,w,Q,L,$,re,oe,xe,ve]),He=async()=>{const ke=b?D.trim():n??"";if(!ke){q.error(s("settings.mcp.page.toast.nameRequired"));return}if(b&&a.some(Nt=>Nt.name===ke)){q.error(s("settings.mcp.page.toast.serverNameExists"));return}if(j==="local"&&O.filter(Boolean).length===0){q.error(s("settings.mcp.page.toast.localCommandRequired"));return}if(j==="remote"&&!V.trim()){q.error(s("settings.mcp.page.toast.remoteUrlRequired"));return}const vt={name:ke,scope:T,type:j,command:O,url:V,environment:ee,headers:w,oauthEnabled:Q,oauthClientId:L,oauthClientSecret:$,oauthScope:re,oauthRedirectUri:oe,timeout:xe,enabled:ve};se(!0);try{const Nt=b?await c(vt):await f(ke,vt);Nt.ok?(await qn(qe),$e(),b&&(i(null),o(ke)),await h({directory:p,silent:!0}),Nt.reloadFailed?q.warning(Nt.message||s(b?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Nt.warning||s("settings.mcp.page.toast.retryRefreshHint")}):q.success(Nt.message||s(b?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):q.error(s("settings.mcp.page.toast.saveFailed"))}catch(Nt){q.error(Nt instanceof Error?Nt.message:s("settings.mcp.page.toast.unexpectedError"))}finally{se(!1)}},bt=async()=>{if(!n)return;te(!0);const ke=await u(n);ke.ok?(await qn(qe),$e(),ke.reloadFailed?q.warning(ke.message||s("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:ke.warning||s("settings.mcp.page.toast.refreshListIfStale")}):q.success(ke.message||s("settings.mcp.page.toast.serverDeleted",{name:n})),be(!1)):q.error(s("settings.mcp.page.toast.deleteFailed")),te(!1)},wt=async()=>{if(n){me(!0);try{if(I[n]?.status==="connected")await E(n,p),q.success(s("settings.mcp.page.toast.disconnected"));else{await x(n,p),await h({directory:p,silent:!0});const vt=cs.getState().getStatusForDirectory(p??null)[n];vt?.status==="connected"?q.success(s("settings.mcp.page.toast.connected")):vt?.status==="needs_auth"?q.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):vt?.status==="needs_client_registration"?q.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):vt?.status==="failed"?q.error(vt.error||s("settings.mcp.page.toast.connectionFailed")):q.message(s("settings.mcp.page.toast.connectionAttemptFinished"));return}await h({directory:p,silent:!0})}catch(ke){q.error(ke instanceof Error?ke.message:s("settings.mcp.page.toast.connectionFailed"))}finally{me(!1)}}},Pt=l.useCallback(()=>b?(q.error(s("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):Xe?(q.error(s("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[Xe,b,s]),ie=l.useCallback(async(ke=!1)=>{try{await h({directory:p,silent:ke})}catch(vt){ke||q.error(vt instanceof Error?vt.message:s("settings.mcp.page.toast.refreshStatusFailed"))}},[p,h,s]);l.useEffect(()=>{ie(!0)},[ie]),l.useEffect(()=>{dt.current=nt,me(!1),Re(!1),$e()},[$e,nt]);const Be=l.useCallback(async()=>{if(!n||j!=="remote"||!Pt())return;Ne(!0);const ke=nt;let vt=null;try{const Nt=cs.getState().getStatusForDirectory(p??null)[n]?.status;Ve.current=Nt==="needs_auth"||Nt==="needs_client_registration";const Ze=lo(n,p);if(!Ze)throw new Error(s("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!oe.trim()&&!m){const as=await f(n,{oauthEnabled:Q,oauthClientId:L,oauthClientSecret:$,oauthScope:re,oauthRedirectUri:Ze});if(!as.ok)throw new Error(s("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(as.reloadFailed)throw new Error(as.warning||as.message||s("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(dt.current!==ke)return;fe(Ze),Ye.current=Ye.current?{...Ye.current,oauthRedirectUri:Ze}:Ye.current}const kt=await S(n,p),Wt=Vl(new URL(kt).searchParams);if(Wt&&(vt=Wt,await Zp({state:Wt,name:n,directory:p})),dt.current!==ke)return;Ke(kt),ce(Wt??null),Ee(!0),Se.current=0;const Jt=await Ws(kt);if(dt.current!==ke)return;Jt?q.message(s(m?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):q.error(s("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Nt){await qn(vt),dt.current===ke&&q.error(or(Nt,s("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{dt.current===ke&&Ne(!1)}},[p,m,j,L,$,Q,oe,re,Pt,nt,n,S,s,e,f]),Je=l.useCallback(async()=>{if(!n||!Pt())return;Ae(!0);const ke=nt;try{if(await M(n,p),dt.current!==ke)return;Ke(null),ce(null),pe(""),Ee(!1),Se.current=0,await qn(qe),q.success(s("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(vt){dt.current===ke&&q.error(or(vt,s("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{dt.current===ke&&Ae(!1)}},[qe,M,p,Pt,nt,n,s,e]),Ge=l.useCallback(async()=>{if(!_e)return;if((await fn(_e)).ok){q.success(s("settings.mcp.page.toast.authorizationUrlCopied"));return}q.error(s("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[_e,s]),ut=l.useCallback(async()=>{const ke=qp(G);if(!ke.code){q.error(s("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const vt=ke.stateKey?await eg(ke.stateKey):null,Nt=ke.context??vt,Ze=Nt?.name??n,kt=Nt?.directory??p;if(!Ze){q.error(s("settings.mcp.page.toast.missingServerDetails"));return}if(!Nt&&!Pt())return;Ue(!0);const Wt=nt;try{if(await C(Ze,ke.code,kt),await qn(ke.stateKey??qe),dt.current!==Wt)return;pe(""),Ke(null),ce(null),Ee(!1),Se.current=0,q.success(Ze===n?s("settings.mcp.page.toast.authorizationCompleted"):s("settings.mcp.page.toast.authorizationCompletedFor",{name:Ze}))}catch(Jt){dt.current===Wt&&q.error(or(Jt,s("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{dt.current===Wt&&Ue(!1)}},[G,qe,C,p,Pt,nt,n,s,e]),yt=l.useCallback(async()=>{if(!(!n||!Pt())){if(!ve){q.error(s("settings.mcp.page.toast.enableServerBeforeTest"));return}Re(!0);try{const ke=await k(n,p),vt=ke.status?.status;ke.warning?q.warning(ke.warning):vt==="connected"?q.success(s("settings.mcp.page.toast.connectionTestSucceeded")):vt==="needs_auth"?q.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):vt==="needs_client_registration"?q.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):vt==="failed"?q.error(ke.status?.error||ke.error||s("settings.mcp.page.toast.connectionTestFailed")):ke.error?q.error(ke.error):q.message(s("settings.mcp.page.toast.connectionTestFinished"))}catch(ke){q.error(ke instanceof Error?ke.message:s("settings.mcp.page.toast.connectionTestFailed"))}finally{Re(!1)}}},[p,ve,Pt,n,s,k]);if(l.useEffect(()=>{if(!je||!n)return;const ke=window.setInterval(()=>{(async()=>{Se.current+=1,await h({directory:p,silent:!0});const vt=cs.getState().getStatusForDirectory(p??null)[n];if(vt){if(Ve.current&&vt.status!=="needs_auth"&&vt.status!=="needs_client_registration"){Ee(!1),Se.current=0,Ve.current=!1,Ke(null),pe(""),vt.status==="connected"&&q.success(s("settings.mcp.page.toast.authorizationCompleted"));return}if(!Ve.current&&vt.status==="failed"){Ee(!1),Se.current=0,Ve.current=!1,q.error(vt.error||s("settings.mcp.page.toast.authorizationFailed"));return}Se.current>=30&&(Ee(!1),Se.current=0,Ve.current=!1,q.message(s("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(ke)}},[p,je,h,n,s]),!n)return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{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 gt=I[n],Et=n?g[n]:void 0,Qt=gt??Et,es=gt?.status==="connected",ts=gt?.status==="needs_auth"||gt?.status==="needs_client_registration",ss=m?null:lo(n,p),_t=Qp(Qt?.status,e,Qt&&"error"in Qt?Qt.error:void 0),ns=ke=>{switch(ke){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 ke}};return t.jsxs(qt,{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:[b?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(oo,{status:Qt?.status,enabled:ve,getStatusLabel:ns,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:b?s("settings.mcp.page.header.configureNewServer"):s("settings.mcp.page.header.transport",{type:s(j==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!b&&t.jsxs(t.Fragment,{children:[t.jsx(J,{variant:es?"outline":"default",size:"xs",className:"!font-normal",onClick:wt,disabled:ae||!ve,children:s(ae?"settings.mcp.page.actions.working":es?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),j==="remote"&&t.jsxs(t.Fragment,{children:[t.jsx(J,{variant:ts?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{Be()},disabled:Me||!ve,children:s(Me?"settings.mcp.page.actions.starting":ts?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{Je()},disabled:De||!ve,children:s(De?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),es&&t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{yt()},disabled:Pe||!ve,children:s(Pe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!b&&Xp(Qt?.status,_e,ts,je)&&t.jsx("div",{className:"mb-6 px-2",children:t.jsxs("div",{className:le("rounded-lg border p-3",Yp(Qt?.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(oo,{status:Qt?.status,enabled:ve,getStatusLabel:ns})]}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:_t}),t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:T==="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:!es&&t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yt()},disabled:Pe||!ve,children:s(Pe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),_e&&t.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.authorizationUrl")}),t.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:_e}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ws(_e)},children:[t.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.mcp.page.actions.openInBrowser")]}),t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ge()},children:[t.jsx(A,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.actions.copyLink")]})]})]})}),j==="remote"&&(ts||je||_e)&&t.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.auth.manualFallbackTitle")}),t.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.manualFallbackDescription")})]}),t.jsx(hs,{value:G,onChange:ke=>pe(ke.target.value),placeholder:s("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ut()},disabled:Fe,children:s(Fe?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),je&&t.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.waitingForOpenCode")})]})}),t.jsxs("div",{"data-settings-item":"mcp.server",className:"mb-6",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.mcp.page.server.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[b&&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(tt,{value:D,onChange:ke=>U(ke.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(Tt,{value:T,onValueChange:ke=>F(ke),children:[t.jsx(Ft,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:s(T==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:T==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ht,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),b&&t.jsx("div",{className:"py-1.5",children:t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:mt,type:"button",title:s("settings.mcp.page.server.importJsonTitle"),children:[t.jsx(A,{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":ve,onClick:()=>we(!ve),onKeyDown:ke=>{(ke.key===" "||ke.key==="Enter")&&(ke.preventDefault(),we(!ve))},children:[t.jsx(St,{checked:ve,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(J,{variant:"chip",size:"xs","aria-pressed":j==="local",onClick:()=>P("local"),className:"!font-normal",children:s("settings.mcp.page.transport.local")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":j==="remote",onClick:()=>P("remote"),className:"!font-normal",children:s("settings.mcp.page.transport.remote")})]})]})})]})]}),t.jsxs("div",{"data-settings-item":"mcp.command",className:"mb-6",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s(j==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:j==="local"?t.jsx(Gp,{value:O,onChange:R,pasteCommandTitle:s("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:s("settings.mcp.page.connection.pasteCommand"),pasteSuccess:ke=>s("settings.mcp.page.toast.pastedArgumentsCount",{count:ke}),clipboardReadFailed:s("settings.mcp.page.toast.clipboardReadFailed"),preview:ke=>s("settings.mcp.page.connection.previewArgs",{count:ke})}):t.jsx(tt,{value:V,onChange:ke=>B(ke.target.value),placeholder:s("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),j==="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(bn,{open:Z,onOpenChange:y,children:[t.jsxs(yn,{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(Q?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",w.length," ",s("settings.mcp.page.advanced.headers"),xe?` · ${xe}ms`:"",")"]})]}),Z?t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(vn,{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(tt,{type:"number",min:"1",step:"1",value:xe,onChange:ke=>Ce(ke.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"),w.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",w.length,")"]})]}),t.jsx(io,{value:w,onChange:H,keyTransform:ke=>ke.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:ke=>s("settings.mcp.page.toast.importedVariablesCount",{count:ke}),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":Q,onClick:()=>z(!Q),onKeyDown:ke=>{(ke.key===" "||ke.key==="Enter")&&(ke.preventDefault(),z(!Q))},children:[t.jsx(St,{checked:Q,onChange:z,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(tt,{value:L,onChange:ke=>X(ke.target.value),placeholder:s("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!Q,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(tt,{value:$,onChange:ke=>ne(ke.target.value),placeholder:s("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!Q,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(tt,{value:re,onChange:ke=>_(ke.target.value),placeholder:s("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!Q,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(tt,{value:oe,onChange:ke=>fe(ke.target.value),placeholder:s("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!Q,"data-bwignore":"true","data-1p-ignore":"true"})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:s("settings.mcp.page.advanced.oauthHint")}),ss&&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:ss})]})]})]})})]})})]}),t.jsxs("div",{"data-settings-item":"mcp.environment",className:"mb-2",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[s("settings.mcp.page.env.title"),ee.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ee.length,")"]})]})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:ee.length===0?t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Y([{key:"",value:""}]),children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.mcp.page.env.addEnvironmentVariable")]}):t.jsx(io,{value:ee,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:ke=>s("settings.mcp.page.toast.importedVariablesCount",{count:ke}),clipboardReadFailed:s("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:s("settings.mcp.page.env.key"),valueLabel:s("settings.mcp.page.env.value"),valuePlaceholder:s("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:s("settings.mcp.page.env.hide"),showValueTitle:s("settings.mcp.page.env.show"),addVariable:s("settings.mcp.page.env.addVariable"),plainTextWarning:s("settings.mcp.page.env.plainTextWarning"),removeVariableAria:s("settings.mcp.page.env.removeVariableAria")})})]}),t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[t.jsx(J,{onClick:He,disabled:ye||!Xe&&!b,size:"xs",className:"!font-normal",children:s(ye?"settings.common.actions.saving":b?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!b&&t.jsx(J,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>be(!0),children:s("settings.common.actions.delete")})]})]}),t.jsx(Kt,{open:ue,onOpenChange:ke=>{ke||(Ie(!1),We(""),it(null))},children:t.jsxs(Ut,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("settings.mcp.page.importDialog.title")}),t.jsx(Ht,{children:s("settings.mcp.page.importDialog.description")})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx(hs,{value:Oe,onChange:ke=>{We(ke.target.value),it(null)},placeholder:`{
|
|
16
|
-
"mcpServers": {
|
|
17
|
-
"postgres": {
|
|
18
|
-
"command": "npx",
|
|
19
|
-
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),rt&&t.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:rt}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:he,type:"button",children:[t.jsx(A,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),t.jsxs(Zt,{children:[t.jsx(J,{variant:"outline",onClick:()=>{Ie(!1),We(""),it(null)},className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(J,{onClick:et,disabled:!Oe.trim(),size:"sm",children:s("settings.common.actions.import")})]})]})}),t.jsx(Kt,{open:de,onOpenChange:ke=>{!ke&&!W&&be(!1)},children:t.jsxs(Ut,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("settings.mcp.page.deleteDialog.title",{name:n??""})}),t.jsxs(Ht,{children:[s("settings.mcp.page.deleteDialog.descriptionPrefix")," ",t.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",s("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),t.jsxs(Zt,{children:[t.jsx(J,{variant:"outline",onClick:()=>be(!1),disabled:W,className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(J,{variant:"destructive",size:"sm",onClick:bt,disabled:W,children:s(W?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},ng=({transform:s})=>({...s,y:0}),ag=s=>{const e=st.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:o,listeners:d,setNodeRef:c,transform:f,transition:u,isDragging:p}=Uc(i);let m;e[2]!==f?(m=$c.Transform.toString(f),e[2]=f,e[3]=m):m=e[3];let I;e[4]!==m||e[5]!==u?(I={transform:m,transition:u},e[4]=m,e[5]=u,e[6]=I):I=e[6];const g=p&&"opacity-50";let h;e[7]!==r||e[8]!==g?(h=le("h-full rounded-md",r,g),e[7]=r,e[8]=g,e[9]=h):h=e[9];let x;return e[10]!==o||e[11]!==a||e[12]!==n||e[13]!==d||e[14]!==c||e[15]!==I||e[16]!==h?(x=t.jsx("div",{ref:c,"data-sortable-tab-id":n,style:I,className:h,...o,...d,children:a}),e[10]=o,e[11]=a,e[12]=n,e[13]=d,e[14]=c,e[15]=I,e[16]=h,e[17]=x):x=e[17],x},rg=s=>{const e=st.c(6),{id:n,children:a,className:r}=s;let i;e[0]!==r?(i=le("h-full",r),e[0]=r,e[1]=i):i=e[1];let o;return e[2]!==a||e[3]!==n||e[4]!==i?(o=t.jsx("div",{className:i,"data-sortable-tab-id":n,children:a}),e[2]=a,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},jn=s=>{const e=st.c(121),{items:n,activeId:a,onSelect:r,onClose:i,onReorder:o,layoutMode:d,variant:c,activePillInsetClassName:f,activePillButtonClassName:u,inactiveTabsIconOnly:p,iconOnlyActiveTab:m,animateActivePill:I,activePillLowercase:g,className:h}=s,x=d===void 0?"scrollable":d,E=c===void 0?"default":c,S=p===void 0?!1:p,C=m===void 0?!1:m,M=g===void 0?!0:g,{t:k}=ot(),v=Le(ig),{isTablet:b}=Is(),D=v||b,U=l.useRef(null);let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T={left:!1,right:!1},e[0]=T):T=e[0];const[F,j]=l.useState(T);let P;e[1]!==n?(P=n.map(og),e[1]=n,e[2]=P):P=e[2];const O=P,R=x==="scrollable",V=E==="default",B=E==="active-pill",ee=E==="animated",Y=B||ee,w=V,H=Y||w,Q=B&&R,z=Y,L=I??ee,X=typeof o=="function",$=X?ag:rg;let ne;e[3]===Symbol.for("react.memo_cache_sentinel")?(ne=new Map,e[3]=ne):ne=e[3];const re=l.useRef(ne),[_,oe]=l.useState(null);let fe;e[4]===Symbol.for("react.memo_cache_sentinel")?(fe={activationConstraint:{distance:8}},e[4]=fe):fe=e[4];const xe=Oc(zc(Kc,fe)),Ce=lg;let ve;e[5]===Symbol.for("react.memo_cache_sentinel")?(ve=(Ye,$e)=>{if($e){re.current.set(Ye,$e);return}re.current.delete(Ye)},e[5]=ve):ve=e[5];const we=ve;let ye;e[6]!==a||e[7]!==H?(ye=()=>{if(!H||!a){oe(cg);return}const Ye=U.current,$e=re.current.get(a);if(!Ye||!$e){oe(dg);return}let mt=0,he=0,et=$e;for(;et&&et!==Ye;)mt=mt+et.offsetLeft,he=he+et.offsetTop,et=et.offsetParent;const Xe={left:mt,top:he,width:$e.offsetWidth,height:$e.offsetHeight};oe(He=>Ce(He,Xe)?He:Xe)},e[6]=a,e[7]=H,e[8]=ye):ye=e[8];const se=ye;let de;e[9]!==R?(de=()=>{if(!R){j({left:!1,right:!1});return}const Ye=U.current;if(!Ye){j({left:!1,right:!1});return}j({left:Ye.scrollLeft>2,right:Ye.scrollLeft+Ye.clientWidth<Ye.scrollWidth-2})},e[9]=R,e[10]=de):de=e[10];const be=de;let W;e[11]!==R||e[12]!==be?(W=()=>{if(!R){j({left:!1,right:!1});return}const Ye=U.current;if(!Ye)return;be(),Ye.addEventListener("scroll",be,{passive:!0});const $e=new ResizeObserver(be);return $e.observe(Ye),()=>{Ye.removeEventListener("scroll",be),$e.disconnect()}},e[11]=R,e[12]=be,e[13]=W):W=e[13];let te;e[14]!==R||e[15]!==n.length||e[16]!==be?(te=[R,n.length,be],e[14]=R,e[15]=n.length,e[16]=be,e[17]=te):te=e[17],l.useEffect(W,te);let ae;e[18]!==a||e[19]!==se||e[20]!==H?(ae=()=>{if(!H){oe(null);return}se();const Ye=U.current;if(!Ye)return;const $e=new ResizeObserver(se);if($e.observe(Ye),a){const mt=re.current.get(a);mt&&$e.observe(mt)}return()=>{$e.disconnect()}},e[18]=a,e[19]=se,e[20]=H,e[21]=ae):ae=e[21];let me;e[22]!==a||e[23]!==n.length||e[24]!==se||e[25]!==H?(me=[a,n.length,se,H],e[22]=a,e[23]=n.length,e[24]=se,e[25]=H,e[26]=me):me=e[26],l.useEffect(ae,me);let Me;e[27]!==se?(Me=()=>{se()},e[27]=se,e[28]=Me):Me=e[28],l.useLayoutEffect(Me);let Ne;e[29]!==a||e[30]!==R||e[31]!==be?(Ne=()=>{if(!R||!a)return;const Ye=U.current;if(!Ye)return;const $e=window.requestAnimationFrame(()=>{const mt=typeof window.CSS?.escape=="function"?window.CSS.escape(a):a.replace(/"/g,'\\"'),he=Ye.querySelector(`[data-sortable-tab-id="${mt}"]`);he&&(he.scrollIntoView({block:"nearest",inline:"nearest"}),be())});return()=>{window.cancelAnimationFrame($e)}},e[29]=a,e[30]=R,e[31]=be,e[32]=Ne):Ne=e[32];let De;e[33]!==a||e[34]!==R||e[35]!==n.length||e[36]!==be?(De=[a,R,n.length,be],e[33]=a,e[34]=R,e[35]=n.length,e[36]=be,e[37]=De):De=e[37],l.useEffect(Ne,De);let Ae;e[38]!==o?(Ae=Ye=>{if(!o)return;const{active:$e,over:mt}=Ye;!mt||$e.id===mt.id||o(String($e.id),String(mt.id))},e[38]=o,e[39]=Ae):Ae=e[39];const Pe=Ae;let Re;e[40]!==h?(Re=le("relative flex h-full min-w-0 flex-1",h),e[40]=h,e[41]=Re):Re=e[41];let Fe;e[42]!==R||e[43]!==F||e[44]!==Y?(Fe=R&&F.left?t.jsx("div",{className:le("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]=F,e[44]=Y,e[45]=Fe):Fe=e[45];let Ue;e[46]!==R||e[47]!==F||e[48]!==Y?(Ue=R&&F.right?t.jsx("div",{className:le("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]=F,e[48]=Y,e[49]=Ue):Ue=e[49];const _e=Y?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Ke=Y&&"@container/pill-tabs",qe=Y&&"pill-tabs__track",ce=Y&&(f??"gap-0.5 py-0.5"),G=w&&"items-center overflow-y-hidden",pe=z&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_2%,transparent)] p-0.5 gap-0.5",je=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Ee;e[50]!==_e||e[51]!==Ke||e[52]!==qe||e[53]!==ce||e[54]!==G||e[55]!==pe||e[56]!==je?(Ee=le("relative flex h-full min-w-0 flex-1",_e,Ke,qe,ce,G,pe,je),e[50]=_e,e[51]=Ke,e[52]=qe,e[53]=ce,e[54]=G,e[55]=pe,e[56]=je,e[57]=Ee):Ee=e[57];let Se;e[58]!==R?(Se=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=Se):Se=e[59];let Ve;e[60]!==k?(Ve=k("sortableTabsStrip.aria.tabs"),e[60]=k,e[61]=Ve):Ve=e[61];let Z;e[62]!==_||e[63]!==L||e[64]!==Y?(Z=Y&&_?t.jsx("div",{className:le("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(${_.left}px, ${_.top}px, 0)`,width:`${_.width}px`,height:`${_.height}px`,transition:L?"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]=_,e[63]=L,e[64]=Y,e[65]=Z):Z=e[65];let y;e[66]!==_||e[67]!==w?(y=w&&_?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(${_.left}px, 0, 0)`,width:`${_.width}px`},"aria-hidden":!0}):null,e[66]=_,e[67]=w,e[68]=y):y=e[68];let ue;if(e[69]!==$||e[70]!==a||e[71]!==u||e[72]!==M||e[73]!==D||e[74]!==C||e[75]!==S||e[76]!==B||e[77]!==v||e[78]!==R||e[79]!==n||e[80]!==i||e[81]!==r||e[82]!==Q||e[83]!==Y){let Ye;e[85]!==$||e[86]!==a||e[87]!==u||e[88]!==M||e[89]!==D||e[90]!==C||e[91]!==S||e[92]!==B||e[93]!==v||e[94]!==R||e[95]!==i||e[96]!==r||e[97]!==Q||e[98]!==Y?(Ye=$e=>{const mt=$e.id===a,he=S&&Y&&!mt&&!!$e.icon,et=!he,Xe=!!$e.icon&&(!C||mt),He=S&&Y&&mt&&!R&&!Q,bt=$e.closable!==!1&&!!i,wt=bt&&!!$e.icon,Pt=R||Q?void 0:Y?He?"flex-none basis-auto":v?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",ie=bt?Je=>{Je.button===1&&(Je.preventDefault(),Je.stopPropagation(),i?.($e.id))}:void 0,Be=bt?mg:void 0;return t.jsx($,{id:$e.id,className:Pt,children:t.jsxs("div",{ref:Je=>we($e.id,Je),onAuxClick:ie,onMouseDown:Be,className:le("group flex h-full min-w-0 flex-nowrap items-center",R||Q?"shrink-0":Y?"w-full":"w-full min-w-0",Y?"relative z-10 bg-transparent":mt?"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":mt,"aria-label":he?$e.title??$e.label:void 0,onClick:()=>r($e.id),className:le(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&&M?"lowercase":null,Y&&(he?"gap-0":"gap-1.5"),Y?Q?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":he?"px-2 !min-w-0 text-center":He?"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?u??(B?v?"h-[38px]":"h-[31px]":"h-7"):null,Y?mt?"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:[Xe?t.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[t.jsx("span",{className:le("flex items-center justify-center transition-opacity",wt&&(D?"opacity-0":"group-hover:opacity-0")),children:$e.icon}),wt?t.jsx("span",{role:"button",tabIndex:-1,className:le("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",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:ug,onClick:Je=>{Je.stopPropagation(),i?.($e.id)},"aria-label":$e.closeLabel??`Close ${$e.label} tab`,title:$e.closeLabel??`Close ${$e.label} tab`,children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,et?t.jsx("span",{className:"animated-tabs__label truncate",children:$e.label}):null]}):t.jsxs("span",{className:le("flex min-w-0 flex-nowrap items-center gap-1.5",!R&&"justify-center"),children:[Xe?t.jsxs("span",{className:le("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",mt?"text-[var(--primary-base)]":"text-muted-foreground"),children:[t.jsx("span",{className:le("flex items-center justify-center transition-opacity",wt&&(D?"opacity-0":"group-hover:opacity-0")),children:$e.icon}),wt?t.jsx("span",{role:"button",tabIndex:-1,className:le("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",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:pg,onClick:Je=>{Je.stopPropagation(),i?.($e.id)},"aria-label":$e.closeLabel??`Close ${$e.label} tab`,title:$e.closeLabel??`Close ${$e.label} tab`,children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,t.jsx("span",{className:"truncate leading-[1.2]",children:$e.label})]})}),bt&&!wt?t.jsx("button",{type:"button",onPointerDown:gg,onClick:Je=>{Je.stopPropagation(),i?.($e.id)},className:le("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?mt?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":mt?"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(A,{name:"close",className:"h-3 w-3"})}):null]})},$e.id)},e[85]=$,e[86]=a,e[87]=u,e[88]=M,e[89]=D,e[90]=C,e[91]=S,e[92]=B,e[93]=v,e[94]=R,e[95]=i,e[96]=r,e[97]=Q,e[98]=Y,e[99]=Ye):Ye=e[99],ue=n.map(Ye),e[69]=$,e[70]=a,e[71]=u,e[72]=M,e[73]=D,e[74]=C,e[75]=S,e[76]=B,e[77]=v,e[78]=R,e[79]=n,e[80]=i,e[81]=r,e[82]=Q,e[83]=Y,e[84]=ue}else ue=e[84];let Ie;e[100]!==Ee||e[101]!==Se||e[102]!==Ve||e[103]!==Z||e[104]!==y||e[105]!==ue?(Ie=t.jsxs("div",{ref:U,className:Ee,style:Se,role:"tablist","aria-label":Ve,children:[Z,y,ue]}),e[100]=Ee,e[101]=Se,e[102]=Ve,e[103]=Z,e[104]=y,e[105]=ue,e[106]=Ie):Ie=e[106];let Oe;e[107]!==Re||e[108]!==Fe||e[109]!==Ue||e[110]!==Ie?(Oe=t.jsxs("div",{className:Re,children:[Fe,Ue,Ie]}),e[107]=Re,e[108]=Fe,e[109]=Ue,e[110]=Ie,e[111]=Oe):Oe=e[111];const We=Oe;if(!X)return We;let rt;e[112]===Symbol.for("react.memo_cache_sentinel")?(rt=[ng],e[112]=rt):rt=e[112];let it;e[113]!==O||e[114]!==We?(it=t.jsx(Bc,{items:O,strategy:Vc,children:We}),e[113]=O,e[114]=We,e[115]=it):it=e[115];let nt;e[116]===Symbol.for("react.memo_cache_sentinel")?(nt=t.jsx(_c,{dropAnimation:null}),e[116]=nt):nt=e[116];let dt;return e[117]!==Pe||e[118]!==xe||e[119]!==it?(dt=t.jsxs(Hc,{sensors:xe,collisionDetection:Wc,onDragEnd:Pe,modifiers:rt,children:[it,nt]}),e[117]=Pe,e[118]=xe,e[119]=it,e[120]=dt):dt=e[120],dt};function ig(s){return s.isMobile}function og(s){return s.id}function lg(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 cg(s){return s===null?s:null}function dg(s){return s===null?s:null}function mg(s){s.button===1&&s.preventDefault()}function ug(s){s.stopPropagation()}function pg(s){s.stopPropagation()}function gg(s){s.stopPropagation()}const Ia=()=>{try{const e=os.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=vs.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[PluginsStore] Error resolving config directory:",s)}return null},hg=800,fg=5e3,xg="__default__",Kr=new Map,lr=new Map,bg=1500,_l=s=>s?.trim()||xg,yg=s=>{Kr.delete(_l(s))},ds=ln()(sa(Jr((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=Ia(),r=_l(a),i=Date.now(),o=Kr.get(r)??0,d=e().entries.length>0||e().files.length>0;if(!n?.force&&d&&i-o<fg)return!0;const c=lr.get(r);if(!n?.force&&c)return c;const f=(async()=>{s({isLoading:!0});try{const u=await pt(Zs("/api/config/plugins",a),{headers:Gn(a)});if(!u.ok)throw new Error("Failed to load plugins");const p=await Da(u);return s({entries:p.entries??[],files:p.files??[],isLoading:!1}),Kr.set(r,Date.now()),n?.force||e().loadRegistryInfo(),!0}catch(u){return console.error("[PluginsStore] Failed to load plugins:",u),s({isLoading:!1}),!1}})();lr.set(r,f);try{return await f}finally{lr.delete(r)}},loadRegistryInfo:async n=>{const a=jg(n?.specs??e().entries.map(r=>r.spec));if(a.length===0){s({isLoadingRegistry:!1});return}s({isLoadingRegistry:!0});try{const r=Ia(),i={...e().registryInfo};for(const o of wg(a)){const d=await pt(vg(o,n?.force===!0,r),{headers:Gn(r)});if(!d.ok)throw new Error("Failed to load plugin registry info");const c=await Da(d);for(const f of c.results??[])i[f.spec]=f}s({registryInfo:i,isLoadingRegistry:!1})}catch(r){console.error("[PluginsStore] Failed to load plugin registry info:",r),s({isLoadingRegistry:!1})}},updateToLatest:async n=>{const a=e().entries.find(i=>i.id===n);if(!a)return{ok:!1};const r=e().registryInfo[a.spec];return!r||r.kind!=="npm-ok"||!r.hasUpdate||!r.latestVersion?{ok:!1}:await e().updateEntry(n,{spec:`${r.name}@${r.latestVersion}`})},createEntry:async n=>{const a=await Cn("Creating plugin entry…",async r=>await pt(Zs("/api/config/plugins/entry",r),{method:"POST",headers:ha(r),body:JSON.stringify(co(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,o=await Cn("Updating plugin entry…",async d=>await pt(Zs(`/api/config/plugins/entry/${encodeURIComponent(n)}`,d),{method:"PATCH",headers:ha(d),body:JSON.stringify(co(a))}),e);return o.ok&&i&&e().loadRegistryInfo({specs:[i],force:!0}),o},deleteEntry:async n=>{const a=e().entries.find(i=>i.id===n),r=await Cn("Deleting plugin entry…",async i=>await pt(Zs(`/api/config/plugins/entry/${encodeURIComponent(n)}`,i),{method:"DELETE",headers:Gn(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=Ia(),r=await pt(Zs(`/api/config/plugins/file/${encodeURIComponent(n)}`,a),{headers:Gn(a)});if(!r.ok)throw new Error("Failed to read plugin file");return await Da(r)}catch(a){return console.error("[PluginsStore] Failed to read plugin file:",a),null}},createFile:async n=>Cn("Creating plugin file…",async a=>await pt(Zs("/api/config/plugins/file",a),{method:"POST",headers:ha(a),body:JSON.stringify(n)}),e),updateFile:async(n,a)=>Cn("Updating plugin file…",async r=>await pt(Zs(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{method:"PUT",headers:ha(r),body:JSON.stringify(a)}),e),deleteFile:async n=>{const a=await Cn("Deleting plugin file…",async r=>await pt(Zs(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{method:"DELETE",headers:Gn(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:Zr(),partialize:s=>({selectedId:s.selectedId})}),{name:"plugins-store"}));function Zs(s,e){const n=e?`?directory=${encodeURIComponent(e)}`:"";return`${s}${n}`}function vg(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 jg(s){return Array.from(new Set(s.map(e=>e.trim()).filter(Boolean)))}function wg(s){const e=[];let n=[],a=0;for(const r of s){const i=encodeURIComponent(r),o=n.length===0?i.length:a+1+i.length;n.length>0&&o>bg?(e.push(n),n=[r],a=i.length):(n.push(r),a=o)}return n.length>0&&e.push(n),e}function Gn(s){return s?{"x-opencode-directory":s}:void 0}function ha(s){return{"Content-Type":"application/json",...s?{"x-opencode-directory":s}:{}}}function co(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 Cn(s,e,n){ka(s);let a=!1;try{const r=Ia(),i=await e(r),o=await Da(i).catch(()=>null);if(!i.ok)throw new Error(o?.error||"Failed to update plugin configuration");return yg(r),o?.requiresReload&&(a=!0,await Sa({message:o.message,delayMs:o.reloadDelayMs??hg,scopes:["all"]})),await n().loadPlugins({force:!0}),{ok:!0,reloadFailed:o?.reloadFailed===!0,message:o?.message,warning:o?.warning}}catch(r){return console.error("[PluginsStore] Failed to update plugin configuration:",r),{ok:!1}}finally{a||Ca()}}async function Da(s){return await s.json()}const Ng=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function kg(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 Sg=({open:s,onOpenChange:e,defaultScope:n="user"})=>{const{t:a}=ot(),r=ds(R=>R.createEntry),i=ds(R=>R.createFile),[o,d]=l.useState("npm"),[c,f]=l.useState(""),[u,p]=l.useState(""),[m,I]=l.useState(""),[g,h]=l.useState(""),[x,E]=l.useState(n),[S,C]=l.useState(!1),M=l.useCallback(()=>{f(""),p(""),I(""),h(""),E(n)},[n]);l.useEffect(()=>{s&&(d("npm"),M())},[s,M]);const k=R=>{R!==o&&(d(R),M())},v=l.useMemo(()=>kg(u),[u]),b=!v.ok,D=o==="file"&&m.trim()!==""&&!Ng.test(m.trim()),U=(o==="npm"||o==="path")&&c.trim()==="",T=o==="file"&&g.trim()==="",F=o==="file"&&m.trim()==="",j=S||b||o==="npm"&&U||o==="path"&&U||o==="file"&&(F||D||T),P=async()=>{if(!j){C(!0);try{let R;o==="file"?R=await i({fileName:m.trim(),content:g,scope:x}):R=await r({spec:c.trim(),options:v.ok?v.value:void 0,scope:x}),R.ok?(q.success(R.message||a("settings.plugins.toast.created")),R.reloadFailed&&q.warning(a("settings.plugins.toast.reloadFailed")),e(!1)):q.error(R.message||a("settings.plugins.sidebar.toast.deleteFailed"))}finally{C(!1)}}},O=l.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(Kt,{open:s,onOpenChange:R=>{!R&&S||e(R)},children:t.jsxs(Ut,{className:"max-w-xl",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:a("settings.plugins.dialog.add.title")}),t.jsx(Ht,{children:a("settings.plugins.sidebar.empty.description")})]}),t.jsx(jn,{items:O,activeId:o,onSelect:R=>k(R),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),t.jsxs("div",{className:"flex flex-col gap-4",children:[(o==="npm"||o==="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(tt,{id:"plugin-spec",value:c,onChange:R=>f(R.target.value),placeholder:a("settings.plugins.page.field.spec.placeholder"),"aria-invalid":U?!1:void 0,disabled:S}),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(hs,{id:"plugin-options",value:u,onChange:R=>p(R.target.value),rows:5,className:"font-mono",hasError:b,disabled:S}),b&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:a("settings.plugins.page.field.options.invalidJson")})]})]}),o==="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(tt,{id:"plugin-filename",value:m,onChange:R=>I(R.target.value),placeholder:"my-plugin.ts","aria-invalid":D||void 0,disabled:S}),D&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:a("settings.plugins.validation.fileName")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.content")}),t.jsx(hs,{id:"plugin-content",value:g,onChange:R=>h(R.target.value),rows:16,className:"font-mono",disabled:S})]})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.scope")}),t.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(R=>{const V=x===R,B=a(R==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return t.jsxs("button",{type:"button",onClick:()=>E(R),disabled:S,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[t.jsx(tn,{checked:V,onChange:()=>E(R),ariaLabel:B}),t.jsx("span",{className:le("typography-ui-label font-normal",V?"text-foreground":"text-foreground/60"),children:B})]},R)})})]})]}),t.jsxs(Zt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:S,children:a("settings.plugins.dialog.add.action.cancel")}),t.jsxs(J,{size:"sm",onClick:()=>{P()},disabled:j,children:[S?t.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,a("settings.plugins.dialog.add.action.submit")]})]})]})})},Cg=s=>{const e=st.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=ds(a),{t:i}=ot();if(!r)return null;const o=Pg;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(A,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=d):d=e[2];let c;e[3]!==r.latestVersion?(c=t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[d,r.latestVersion]}),e[3]=r.latestVersion,e[4]=c):c=e[4];let f;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==c?(f=o(c,i("settings.plugins.registry.badge.update.tooltip",{current:r.currentVersion??"",latest:r.latestVersion})),e[5]=r.currentVersion,e[6]=r.latestVersion,e[7]=i,e[8]=c,e[9]=f):f=e[9],f}case"npm-missing-version":{let d;e[10]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(A,{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=o(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(A,{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=o(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(A,{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=o(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(A,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=d):d=e[22];let c;return e[23]!==i?(c=o(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(A,{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=o(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(A,{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=o(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 Pg(s,e){return t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:s})}),t.jsx(At,{children:e})]})}const Hl=s=>{const e=st.c(26),{header:n,footer:a,children:r,className:i,variant:o}=s,d=o===void 0?"sidebar":o,c=fs(),f=l.useRef(null),[u,p]=l.useState(!1),[m,I]=l.useState(!1),g=d==="background"||c?"bg-background":"bg-sidebar",h=g==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const j=f.current;if(!j){p(!1),I(!1);return}if(!(j.scrollHeight>j.clientHeight+1)){p(!1),I(!1);return}p(j.scrollTop>1),I(j.scrollTop+j.clientHeight<j.scrollHeight-1)},e[0]=x):x=e[0];const E=x;let S;e[1]===Symbol.for("react.memo_cache_sentinel")?(S=()=>{E()},e[1]=S):S=e[1];let C;e[2]!==r?(C=[r,E],e[2]=r,e[3]=C):C=e[3],l.useEffect(S,C);let M,k;e[4]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{const j=f.current;if(!j)return;const P=()=>E();return j.addEventListener("scroll",P,{passive:!0}),()=>j.removeEventListener("scroll",P)},k=[E],e[4]=M,e[5]=k):(M=e[4],k=e[5]),l.useEffect(M,k);let v;e[6]!==g||e[7]!==i?(v=le("flex h-full flex-col",g,i),e[6]=g,e[7]=i,e[8]=v):v=e[8];let b;e[9]!==r?(b=t.jsx(qt,{ref:f,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:r}),e[9]=r,e[10]=b):b=e[10];let D;e[11]!==h||e[12]!==u?(D=u&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${h} 0%, transparent 100%)`}}),e[11]=h,e[12]=u,e[13]=D):D=e[13];let U;e[14]!==h||e[15]!==m?(U=m&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${h} 0%, transparent 100%)`}}),e[14]=h,e[15]=m,e[16]=U):U=e[16];let T;e[17]!==U||e[18]!==b||e[19]!==D?(T=t.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[b,D,U]}),e[17]=U,e[18]=b,e[19]=D,e[20]=T):T=e[20];let F;return e[21]!==a||e[22]!==n||e[23]!==T||e[24]!==v?(F=t.jsxs("div",{className:v,children:[n,T,a]}),e[21]=a,e[22]=n,e[23]=T,e[24]=v,e[25]=F):F=e[25],F},Ur=s=>{const e=st.c(23),{title:n,metadata:a,selected:r,onSelect:i,icon:o,actions:d,className:c}=s,f=r===void 0?!1:r,u=d&&d.length>0,p=f?"bg-interactive-selection":"hover:bg-interactive-hover";let m;e[0]!==c||e[1]!==p?(m=le("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]=m):m=e[2];let I;e[3]!==n?(I=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=I):I=e[4];let g;e[5]!==o||e[6]!==I?(g=t.jsxs("div",{className:"flex items-center gap-1.5",children:[o,I]}),e[5]=o,e[6]=I,e[7]=g):g=e[7];let h;e[8]!==a?(h=a&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a}),e[8]=a,e[9]=h):h=e[9];let x;e[10]!==i||e[11]!==g||e[12]!==h?(x=t.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[g,h]}),e[10]=i,e[11]=g,e[12]=h,e[13]=x):x=e[13];let E;e[14]!==d||e[15]!==u?(E=u&&t.jsxs(gs,{children:[t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:d.map(Ig)})]}),e[14]=d,e[15]=u,e[16]=E):E=e[16];let S;e[17]!==x||e[18]!==E?(S=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,E]}),e[17]=x,e[18]=E,e[19]=S):S=e[19];let C;return e[20]!==m||e[21]!==S?(C=t.jsx("div",{className:m,children:S}),e[20]=m,e[21]=S,e[22]=C):C=e[22],C};function Ig(s){const e=s.icon;return t.jsxs(ws,{onClick:n=>{n.stopPropagation(),s.onClick()},className:le(s.destructive&&"text-destructive focus:text-destructive"),children:[e&&t.jsx(A,{name:e,className:"h-4 w-4 mr-px"}),s.label]},s.label)}const Dg=s=>s.parsedKind==="npm"?"code-box":"folder",Ag=s=>{const e=st.c(144),{onItemSelect:n,onAddClick:a}=s,{t:r}=ot(),{entries:i,files:o,selectedId:d,setSelected:c,deleteEntry:f,deleteFile:u,loadPlugins:p}=ds(Ps(Eg)),m=ds(Mg),I=ds(Rg),g=ds(Tg),h=ds(Fg),[x,E]=l.useState(null),[S,C]=l.useState(!1),[M,k]=l.useState(!1);let v,b;e[0]!==p?(v=()=>{p()},b=[p],e[0]=p,e[1]=v,e[2]=b):(v=e[1],b=e[2]),l.useEffect(v,b);let D,U;e[3]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{const he=()=>k(!0);return window.addEventListener("openchamber:settings-open-plugin-add",he),()=>window.removeEventListener("openchamber:settings-open-plugin-add",he)},U=[],e[3]=D,e[4]=U):(D=e[3],U=e[4]),l.useEffect(D,U);let T;if(e[5]!==i||e[6]!==m){T={userEntries:0,projectEntries:0};for(const he of i){const et=m[he.spec];et?.kind==="npm-ok"&&et.hasUpdate&&(he.scope==="user"?T.userEntries=T.userEntries+1:he.scope==="project"&&(T.projectEntries=T.projectEntries+1))}e[5]=i,e[6]=m,e[7]=T}else T=e[7];const F=T;let j;e[8]!==i?(j=i.filter(Lg),e[8]=i,e[9]=j):j=e[9];const P=j;let O;e[10]!==i?(O=i.filter(Og),e[10]=i,e[11]=O):O=e[11];const R=O;let V;e[12]!==o?(V=o.filter(zg),e[12]=o,e[13]=V):V=e[13];const B=V;let ee;e[14]!==o?(ee=o.filter(Kg),e[14]=o,e[15]=ee):ee=e[15];const Y=ee,w=i.length+o.length,H=w===0;let Q;e[16]!==a?(Q=()=>{a?a():k(!0)},e[16]=a,e[17]=Q):Q=e[17];const z=Q;let L;e[18]!==n||e[19]!==c?(L=he=>{c(he),n?.()},e[18]=n,e[19]=c,e[20]=L):L=e[20];const X=L;let $;e[21]!==i||e[22]!==m||e[23]!==r||e[24]!==h?($=async he=>{const et=i.find(wt=>wt.id===he);if(!et)return;const Xe=m[et.spec];if(!Xe||Xe.kind!=="npm-ok"||!Xe.hasUpdate||!Xe.latestVersion)return;const He=Xe.latestVersion;(await h(he)).ok?q.success(r("settings.plugins.toast.updatedToLatest",{version:He})):q.error(r("settings.plugins.toast.refreshFailed"))},e[21]=i,e[22]=m,e[23]=r,e[24]=h,e[25]=$):$=e[25];const ne=$;let re;e[26]!==g||e[27]!==r?(re=async()=>{q.info(r("settings.plugins.toast.refreshing"));try{await g({force:!0})}catch{q.error(r("settings.plugins.toast.refreshFailed"))}},e[26]=g,e[27]=r,e[28]=re):re=e[28];const _=re;let oe;e[29]!==f||e[30]!==u||e[31]!==x||e[32]!==r?(oe=async()=>{if(!x)return;C(!0);const he=x.kind==="entry"?await f(x.id):await u(x.id);he.ok?q.success(he.message||r("settings.plugins.sidebar.toast.deleted",{name:x.label})):q.error(r("settings.plugins.sidebar.toast.deleteFailed")),E(null),C(!1)},e[29]=f,e[30]=u,e[31]=x,e[32]=r,e[33]=oe):oe=e[33];const fe=oe;let xe;e[34]!==X||e[35]!==ne||e[36]!==m||e[37]!==d||e[38]!==r?(xe=he=>{const et=m[he.spec],Xe=et?.kind==="npm-ok"&&et.hasUpdate&&!!et.latestVersion,He=[];return Xe&&He.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{ne(he.id)}}),He.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>E({kind:"entry",id:he.id,label:he.spec})}),t.jsx(Ur,{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:he.spec}),t.jsx(Cg,{spec:he.spec})]}),metadata:he.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:d===he.id,onSelect:()=>X(he.id),icon:t.jsx(A,{name:Dg(he),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:He},he.id)},e[34]=X,e[35]=ne,e[36]=m,e[37]=d,e[38]=r,e[39]=xe):xe=e[39];const Ce=xe;let ve;e[40]!==X||e[41]!==d||e[42]!==r?(ve=he=>t.jsx(Ur,{title:he.fileName,metadata:r("settings.plugins.sidebar.kind.file"),selected:d===he.id,onSelect:()=>X(he.id),icon:t.jsx(A,{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:()=>E({kind:"file",id:he.id,label:he.fileName})}]},he.id),e[40]=X,e[41]=d,e[42]=r,e[43]=ve):ve=e[43];const we=ve;let ye;e[44]!==r?(ye=(he,et,Xe)=>{const He=Xe===void 0?0:Xe;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:[he,He>0&&t.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(He===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:He})})]}),et]})},e[44]=r,e[45]=ye):ye=e[45];const se=ye;let de;e[46]!==r?(de=r("settings.plugins.sidebar.title"),e[46]=r,e[47]=de):de=e[47];let be;e[48]!==de?(be=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:de})}),e[48]=de,e[49]=be):be=e[49];let W;e[50]!==r||e[51]!==w?(W=r("settings.plugins.sidebar.total",{count:w}),e[50]=r,e[51]=w,e[52]=W):W=e[52];let te;e[53]!==W?(te=t.jsx("span",{className:"typography-meta text-muted-foreground",children:W}),e[53]=W,e[54]=te):te=e[54];let ae;e[55]!==_?(ae=()=>{_()},e[55]=_,e[56]=ae):ae=e[56];let me;e[57]!==r?(me=r("settings.plugins.sidebar.actions.refresh"),e[57]=r,e[58]=me):me=e[58];let Me;e[59]!==r?(Me=r("settings.plugins.sidebar.actions.refresh"),e[59]=r,e[60]=Me):Me=e[60];const Ne=I?"size-4 animate-spin":"size-4";let De;e[61]!==Ne?(De=t.jsx(A,{name:"refresh",className:Ne}),e[61]=Ne,e[62]=De):De=e[62];let Ae;e[63]!==I||e[64]!==ae||e[65]!==me||e[66]!==Me||e[67]!==De?(Ae=t.jsx(J,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:ae,disabled:I,"aria-label":me,title:Me,children:De}),e[63]=I,e[64]=ae,e[65]=me,e[66]=Me,e[67]=De,e[68]=Ae):Ae=e[68];let Pe;e[69]!==r?(Pe=r("settings.plugins.sidebar.actions.addTitle"),e[69]=r,e[70]=Pe):Pe=e[70];let Re;e[71]!==r?(Re=r("settings.plugins.sidebar.actions.addTitle"),e[71]=r,e[72]=Re):Re=e[72];let Fe;e[73]===Symbol.for("react.memo_cache_sentinel")?(Fe=t.jsx(A,{name:"add",className:"size-4"}),e[73]=Fe):Fe=e[73];let Ue;e[74]!==z||e[75]!==Pe||e[76]!==Re?(Ue=t.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:z,"aria-label":Pe,title:Re,children:Fe}),e[74]=z,e[75]=Pe,e[76]=Re,e[77]=Ue):Ue=e[77];let _e;e[78]!==Ae||e[79]!==Ue?(_e=t.jsxs("div",{className:"flex items-center gap-1",children:[Ae,Ue]}),e[78]=Ae,e[79]=Ue,e[80]=_e):_e=e[80];let Ke;e[81]!==te||e[82]!==_e?(Ke=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[te,_e]}),e[81]=te,e[82]=_e,e[83]=Ke):Ke=e[83];let qe;e[84]!==be||e[85]!==Ke?(qe=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[be,Ke]}),e[84]=be,e[85]=Ke,e[86]=qe):qe=e[86];let ce;e[87]!==H||e[88]!==R||e[89]!==Y||e[90]!==Ce||e[91]!==we||e[92]!==se||e[93]!==r||e[94]!==F||e[95]!==P||e[96]!==B?(ce=H?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.plugins.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.plugins.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[P.length>0&&se(r("settings.plugins.sidebar.group.userEntries"),P.map(Ce),F.userEntries),B.length>0&&se(r("settings.plugins.sidebar.group.userFiles"),B.map(we)),R.length>0&&se(r("settings.plugins.sidebar.group.projectEntries"),R.map(Ce),F.projectEntries),Y.length>0&&se(r("settings.plugins.sidebar.group.projectFiles"),Y.map(we))]}),e[87]=H,e[88]=R,e[89]=Y,e[90]=Ce,e[91]=we,e[92]=se,e[93]=r,e[94]=F,e[95]=P,e[96]=B,e[97]=ce):ce=e[97];let G;e[98]!==qe||e[99]!==ce?(G=t.jsx(Hl,{variant:"background",header:qe,children:ce}),e[98]=qe,e[99]=ce,e[100]=G):G=e[100];let pe;e[101]!==M?(pe=t.jsx(Sg,{open:M,onOpenChange:k}),e[101]=M,e[102]=pe):pe=e[102];const je=x!==null;let Ee;e[103]!==S?(Ee=he=>{!he&&!S&&E(null)},e[103]=S,e[104]=Ee):Ee=e[104];let Se;e[105]!==r?(Se=r("settings.plugins.sidebar.deleteDialog.title"),e[105]=r,e[106]=Se):Se=e[106];let Ve;e[107]!==Se?(Ve=t.jsx($t,{children:Se}),e[107]=Se,e[108]=Ve):Ve=e[108];const Z=x?.label??"";let y;e[109]!==r||e[110]!==Z?(y=r("settings.plugins.sidebar.deleteDialog.description",{name:Z}),e[109]=r,e[110]=Z,e[111]=y):y=e[111];let ue;e[112]!==y?(ue=t.jsx(Ht,{children:y}),e[112]=y,e[113]=ue):ue=e[113];let Ie;e[114]!==Ve||e[115]!==ue?(Ie=t.jsxs(Bt,{children:[Ve,ue]}),e[114]=Ve,e[115]=ue,e[116]=Ie):Ie=e[116];let Oe;e[117]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>E(null),e[117]=Oe):Oe=e[117];let We;e[118]!==r?(We=r("settings.common.actions.cancel"),e[118]=r,e[119]=We):We=e[119];let rt;e[120]!==S||e[121]!==We?(rt=t.jsx(J,{size:"sm",variant:"ghost",onClick:Oe,disabled:S,children:We}),e[120]=S,e[121]=We,e[122]=rt):rt=e[122];let it;e[123]!==S||e[124]!==r?(it=r(S?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=S,e[124]=r,e[125]=it):it=e[125];let nt;e[126]!==fe||e[127]!==S||e[128]!==it?(nt=t.jsx(J,{size:"sm",variant:"destructive",onClick:fe,disabled:S,children:it}),e[126]=fe,e[127]=S,e[128]=it,e[129]=nt):nt=e[129];let dt;e[130]!==rt||e[131]!==nt?(dt=t.jsxs(Zt,{children:[rt,nt]}),e[130]=rt,e[131]=nt,e[132]=dt):dt=e[132];let Ye;e[133]!==Ie||e[134]!==dt?(Ye=t.jsxs(Ut,{className:"max-w-md",children:[Ie,dt]}),e[133]=Ie,e[134]=dt,e[135]=Ye):Ye=e[135];let $e;e[136]!==je||e[137]!==Ee||e[138]!==Ye?($e=t.jsx(Kt,{open:je,onOpenChange:Ee,children:Ye}),e[136]=je,e[137]=Ee,e[138]=Ye,e[139]=$e):$e=e[139];let mt;return e[140]!==G||e[141]!==pe||e[142]!==$e?(mt=t.jsxs(t.Fragment,{children:[G,pe,$e]}),e[140]=G,e[141]=pe,e[142]=$e,e[143]=mt):mt=e[143],mt};function Eg(s){return{entries:s.entries,files:s.files,selectedId:s.selectedId,setSelected:s.setSelected,deleteEntry:s.deleteEntry,deleteFile:s.deleteFile,loadPlugins:s.loadPlugins}}function Mg(s){return s.registryInfo}function Rg(s){return s.isLoadingRegistry}function Tg(s){return s.loadRegistryInfo}function Fg(s){return s.updateToLatest}function Lg(s){return s.scope==="user"}function Og(s){return s.scope==="project"}function zg(s){return s.scope==="user"}function Kg(s){return s.scope==="project"}const $r=s=>{const e=st.c(10),{children:n,className:a,outerClassName:r}=s;let i;e[0]!==r?(i=le("h-full",r),e[0]=r,e[1]=i):i=e[1];let o;e[2]!==a?(o=le("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",a),e[2]=a,e[3]=o):o=e[3];let d;e[4]!==n||e[5]!==o?(d=t.jsx("div",{className:o,children:n}),e[4]=n,e[5]=o,e[6]=d):d=e[6];let c;return e[7]!==i||e[8]!==d?(c=t.jsx(qt,{outerClassName:i,className:"w-full",children:d}),e[7]=i,e[8]=d,e[9]=c):c=e[9],c},Ug=({entryId:s,spec:e})=>{const{t:n}=ot(),a=ds(p=>p.registryInfo[e]),r=ds(p=>p.updateToLatest),[i,o]=l.useState(!1);if(!a)return null;if(a.kind==="npm-ok"){if(!a.hasUpdate||!a.latestVersion)return null;const p=a.latestVersion,m=a.currentVersion??"",I=async()=>{o(!0);try{(await r(s)).ok?q.success(n("settings.plugins.toast.updatedToLatest",{version:p})):q.error(n("settings.plugins.toast.refreshFailed"))}finally{o(!1)}};return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(A,{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:m,latest:p})})]}),t.jsx(J,{variant:"default",size:"sm",onClick:()=>{I()},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(A,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx("p",{className:"typography-micro text-muted-foreground",children:n("settings.plugins.registry.badge.network.tooltip")})})]});const d=a.kind==="path-unreadable",c=d?"var(--status-warning)":"var(--status-error)",f=d?"alert":"error-warning",u=(()=>{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(A,{name:f,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"typography-label",style:{color:c},children:n("settings.plugins.registry.banner.invalid.title")}),t.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:u})]})]})};function $g(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 Wl(s){return!s||Object.keys(s).length===0?"":JSON.stringify(s,null,2)}function mo(s){return{mode:"entry",scope:s.scope,spec:s.spec,optionsJson:Wl(s.options),fileName:"",content:""}}function uo(s,e){return{mode:"file",scope:s.scope,spec:"",optionsJson:"",fileName:s.fileName,content:e}}const po=s=>{const e=st.c(4),{scope:n,label:a}=s;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=le("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},Bg=()=>{const{t:s}=ot(),e=ds(x=>x.selectedId),n=ds(x=>x.entries),a=ds(x=>x.files),r=ds(x=>x.draft),i=ds(x=>x.setDraft),o=ds(x=>x.updateEntry),d=ds(x=>x.updateFile),c=ds(x=>x.readFile),f=l.useMemo(()=>e?n.find(x=>x.id===e)??null:null,[n,e]),u=l.useMemo(()=>e?a.find(x=>x.id===e)??null:null,[a,e]),[p,m]=l.useState(!1),[I,g]=l.useState(!1),h=l.useRef(new Map);if(l.useEffect(()=>{let x=!1;return f?(i(mo(f)),()=>{x=!0}):u?(g(!0),(async()=>{const E=await c(u.id);if(x)return;g(!1);const S=E?.content??"";h.current.set(u.id,S),i(uo(u,S))})(),()=>{x=!0}):(i(null),()=>{x=!0})},[f,u,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(A,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.plugins.page.empty.select")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.plugins.page.empty.add")})]})});if(f&&r&&r.mode==="entry"){const x=$g(r.optionsJson),E=x.ok,S=r.spec!==f.spec||r.optionsJson!==Wl(f.options),C=()=>{i(mo(f))},M=async()=>{if(!E)return;const k=r.spec.trim();if(!k){q.error(s("settings.plugins.validation.specRequired"));return}m(!0);try{const v=await o(f.id,{spec:k,options:x.value});v.ok?v.reloadFailed?q.warning(v.message||s("settings.plugins.toast.reloadFailed"),{description:v.warning}):q.success(v.message||s("settings.plugins.toast.updated")):q.error(v.message||s("settings.plugins.toast.reloadFailed"))}finally{m(!1)}};return t.jsxs($r,{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(po,{scope:f.scope,label:f.scope==="project"?s("settings.plugins.sidebar.group.projectEntries"):s("settings.plugins.sidebar.group.userEntries")})]})}),t.jsx(Ug,{entryId:f.id,spec:f.spec}),t.jsxs("div",{"data-settings-item":"plugins.spec",className:"space-y-1.5",children:[t.jsx("label",{className:"typography-meta text-muted-foreground",children:s("settings.plugins.page.field.spec")}),t.jsx(tt,{value:r.spec,onChange:k=>i({...r,spec:k.target.value}),placeholder:s("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})]}),t.jsxs("div",{"data-settings-item":"plugins.options",className:"space-y-1.5",children:[t.jsx("label",{className:"typography-meta text-muted-foreground",children:s("settings.plugins.page.field.options")}),t.jsx(hs,{value:r.optionsJson,onChange:k=>i({...r,optionsJson:k.target.value}),rows:10,className:le("font-mono typography-meta min-h-[200px]",!E&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!E&&t.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:s("settings.plugins.page.field.options.invalidJson")})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"default",size:"sm",onClick:()=>{M()},disabled:!S||!E||p,children:s("settings.plugins.page.action.save")}),t.jsx(J,{variant:"outline",size:"sm",onClick:C,disabled:!S||p,children:s("settings.plugins.page.action.discard")})]})]})}if(u&&r&&r.mode==="file"){const x=h.current.get(u.id)??"",E=r.content!==x||r.fileName!==u.fileName,S=()=>{(async()=>{g(!0);const k=(await c(u.id))?.content??"";g(!1),h.current.set(u.id,k),i(uo(u,k))})()},C=async()=>{m(!0);try{const M=await d(u.id,{content:r.content});M.ok?(h.current.set(u.id,r.content),M.reloadFailed?q.warning(M.message||s("settings.plugins.toast.reloadFailed"),{description:M.warning}):q.success(M.message||s("settings.plugins.toast.updated"))):q.error(M.message||s("settings.plugins.toast.reloadFailed"))}finally{m(!1)}};return t.jsxs($r,{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(po,{scope:u.scope,label:u.scope==="project"?s("settings.plugins.sidebar.group.projectFiles"):s("settings.plugins.sidebar.group.userFiles")}),t.jsx("span",{className:le("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:u.fileName})]})}),t.jsxs("div",{"data-settings-item":"plugins.content",className:"space-y-1.5",children:[t.jsx("label",{className:"typography-meta text-muted-foreground",children:s("settings.plugins.page.field.content")}),t.jsx(hs,{value:r.content,onChange:M=>i({...r,content:M.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:I})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"default",size:"sm",onClick:()=>{C()},disabled:!E||p||I,children:s("settings.plugins.page.action.save")}),t.jsx(J,{variant:"outline",size:"sm",onClick:S,disabled:p||I,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(A,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Vg="<built-in>",In=s=>s?.path===Vg,_g=s=>{const e=st.c(150),{onItemSelect:n}=s,{t:a}=ot(),[r,i]=l.useState(null),[o,d]=l.useState(""),[c,f]=l.useState(null),[u,p]=l.useState(!1),[m,I]=l.useState(null),{selectedSkillName:g,skills:h,setSelectedSkill:x,setSkillDraft:E,createSkill:S,deleteSkill:C,getSkillDetail:M}=Hs(Ps(Hg));let k;e[0]!==n||e[1]!==x||e[2]!==E||e[3]!==h?(k=()=>{let he="new-skill",et=1;for(;h.some(Xe=>Xe.name===he);)he=`new-skill-${et}`,et++;E({name:he,scope:"user",source:"opencode",description:""}),x(he),n?.()},e[0]=n,e[1]=x,e[2]=E,e[3]=h,e[4]=k):k=e[4];const v=k;let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=async he=>{In(he)||f(he)},e[5]=b):b=e[5];const D=b;let U;e[6]!==c||e[7]!==C||e[8]!==a?(U=async()=>{if(!c)return;if(In(c)){f(null);return}p(!0),await C(c.name)?(q.success(a("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),f(null)):q.error(a("settings.skills.sidebar.toast.deleteSkillFailed")),p(!1)},e[6]=c,e[7]=C,e[8]=a,e[9]=U):U=e[9];const T=U;let F;e[10]!==M||e[11]!==x||e[12]!==E||e[13]!==h||e[14]!==a?(F=async he=>{if(In(he))return;const et=he.name;let Xe=1,He=`${et}-copy`;for(;h.some(wt=>wt.name===He);)Xe++,He=`${et}-copy-${Xe}`;const bt=await M(he.name);if(!bt){q.error(a("settings.skills.sidebar.toast.duplicateLoadFailed"));return}E({name:He,scope:he.scope||"user",source:he.source||"opencode",description:(bt.sources.md.fields.includes("description"),""),instructions:""}),x(He)},e[10]=M,e[11]=x,e[12]=E,e[13]=h,e[14]=a,e[15]=F):F=e[15];const j=F;let P;e[16]===Symbol.for("react.memo_cache_sentinel")?(P=he=>{In(he)||(d(he.name),i(he))},e[16]=P):P=e[16];const O=P;let R;e[17]!==S||e[18]!==C||e[19]!==M||e[20]!==r||e[21]!==o||e[22]!==x||e[23]!==h||e[24]!==a?(R=async()=>{if(!r)return;if(In(r)){i(null);return}const he=o.trim().replace(/\s+/g,"-").toLowerCase();if(!he){q.error(a("settings.skills.page.toast.skillNameRequired"));return}if(he===r.name){i(null);return}if(h.some(He=>He.name===he)){q.error(a("settings.skills.page.toast.skillExists"));return}if(!await M(r.name)){q.error(a("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await S({name:he,description:"Renamed skill",scope:r.scope,source:r.source})?await C(r.name)?(q.success(`Skill renamed to "${he}"`),x(he)):q.error(a("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):q.error(a("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=S,e[18]=C,e[19]=M,e[20]=r,e[21]=o,e[22]=x,e[23]=h,e[24]=a,e[25]=R):R=e[25];const V=R;let B;e[26]!==h?(B=h.filter(Wg),e[26]=h,e[27]=B):B=e[27];const ee=B;let Y;e[28]!==h?(Y=h.filter(qg),e[28]=h,e[29]=Y):Y=e[29];const w=Y;let H;e[30]===Symbol.for("react.memo_cache_sentinel")?(H=function(et){const Xe={},He=[];for(const wt of et)wt.group?(Xe[wt.group]||(Xe[wt.group]=[]),Xe[wt.group].push(wt)):He.push(wt);const bt=Object.keys(Xe).sort(Gg).map(wt=>({name:wt,skills:[...Xe[wt]].sort(Jg)}));return He.sort(Qg),{sortedGroups:bt,ungrouped:He}},e[30]=H):H=e[30];const Q=H;let z;e[31]!==ee?(z=Q(ee),e[31]=ee,e[32]=z):z=e[32];const L=z;let X;e[33]!==w?(X=Q(w),e[33]=w,e[34]=X):X=e[34];const $=X;let ne;e[35]===Symbol.for("react.memo_cache_sentinel")?(ne=le("flex h-full flex-col","bg-background"),e[35]=ne):ne=e[35];let re;e[36]!==a?(re=a("settings.skills.sidebar.title"),e[36]=a,e[37]=re):re=e[37];let _;e[38]!==re?(_=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:re}),e[38]=re,e[39]=_):_=e[39];let oe;e[40]===Symbol.for("react.memo_cache_sentinel")?(oe=t.jsx(na,{className:"mb-3"}),e[40]=oe):oe=e[40];let fe;e[41]!==h.length||e[42]!==a?(fe=a("settings.skills.sidebar.total",{count:h.length}),e[41]=h.length,e[42]=a,e[43]=fe):fe=e[43];let xe;e[44]!==fe?(xe=t.jsx("span",{className:"typography-meta text-muted-foreground",children:fe}),e[44]=fe,e[45]=xe):xe=e[45];let Ce;e[46]===Symbol.for("react.memo_cache_sentinel")?(Ce=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[46]=Ce):Ce=e[46];let ve;e[47]!==v?(ve=t.jsx(J,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:v,children:Ce}),e[47]=v,e[48]=ve):ve=e[48];let we;e[49]!==xe||e[50]!==ve?(we=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[xe,ve]}),e[49]=xe,e[50]=ve,e[51]=we):we=e[51];let ye;e[52]!==_||e[53]!==we?(ye=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[_,oe,we]}),e[52]=_,e[53]=we,e[54]=ye):ye=e[54];let se;e[55]!==L||e[56]!==$||e[57]!==j||e[58]!==n||e[59]!==m||e[60]!==ee||e[61]!==g||e[62]!==x||e[63]!==h.length||e[64]!==a||e[65]!==w?(se=t.jsx(qt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:h.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.skills.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.skills.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[ee.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.skills.sidebar.section.project")}),L.sortedGroups.map(he=>{const{name:et,skills:Xe}=he;return t.jsx(zr,{label:et,count:Xe.length,storageKey:"project-skills",children:Xe.map(He=>t.jsx(fa,{skill:He,isSelected:g===He.name,onSelect:()=>{x(He.name),n?.()},onRename:()=>O(He),onDelete:()=>D(He),onDuplicate:()=>j(He),isMenuOpen:m===He.name,onMenuOpenChange:bt=>I(bt?He.name:null)},He.name))},et)}),L.ungrouped.map(he=>t.jsx(fa,{skill:he,isSelected:g===he.name,onSelect:()=>{x(he.name),n?.()},onRename:()=>O(he),onDelete:()=>D(he),onDuplicate:()=>j(he),isMenuOpen:m===he.name,onMenuOpenChange:et=>I(et?he.name:null)},he.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:a("settings.skills.sidebar.section.user")}),$.sortedGroups.map(he=>{const{name:et,skills:Xe}=he;return t.jsx(zr,{label:et,count:Xe.length,storageKey:"user-skills",children:Xe.map(He=>t.jsx(fa,{skill:He,isSelected:g===He.name,onSelect:()=>{x(He.name),n?.()},onRename:()=>O(He),onDelete:()=>D(He),onDuplicate:()=>j(He),isMenuOpen:m===He.name,onMenuOpenChange:bt=>I(bt?He.name:null)},He.name))},et)}),$.ungrouped.map(he=>t.jsx(fa,{skill:he,isSelected:g===he.name,onSelect:()=>{x(he.name),n?.()},onRename:()=>O(he),onDelete:()=>D(he),onDuplicate:()=>j(he),isMenuOpen:m===he.name,onMenuOpenChange:et=>I(et?he.name:null)},he.name))]})]})}),e[55]=L,e[56]=$,e[57]=j,e[58]=n,e[59]=m,e[60]=ee,e[61]=g,e[62]=x,e[63]=h.length,e[64]=a,e[65]=w,e[66]=se):se=e[66];const de=c!==null;let be;e[67]!==u?(be=he=>{!he&&!u&&f(null)},e[67]=u,e[68]=be):be=e[68];let W;e[69]!==a?(W=a("settings.skills.sidebar.deleteDialog.title"),e[69]=a,e[70]=W):W=e[70];let te;e[71]!==W?(te=t.jsx($t,{children:W}),e[71]=W,e[72]=te):te=e[72];const ae=c?.name??"";let me;e[73]!==a||e[74]!==ae?(me=a("settings.skills.sidebar.deleteDialog.description",{name:ae}),e[73]=a,e[74]=ae,e[75]=me):me=e[75];let Me;e[76]!==me?(Me=t.jsx(Ht,{children:me}),e[76]=me,e[77]=Me):Me=e[77];let Ne;e[78]!==te||e[79]!==Me?(Ne=t.jsxs(Bt,{children:[te,Me]}),e[78]=te,e[79]=Me,e[80]=Ne):Ne=e[80];let De;e[81]===Symbol.for("react.memo_cache_sentinel")?(De=()=>f(null),e[81]=De):De=e[81];let Ae;e[82]!==a?(Ae=a("settings.common.actions.cancel"),e[82]=a,e[83]=Ae):Ae=e[83];let Pe;e[84]!==u||e[85]!==Ae?(Pe=t.jsx(J,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:De,disabled:u,children:Ae}),e[84]=u,e[85]=Ae,e[86]=Pe):Pe=e[86];let Re;e[87]!==a?(Re=a("settings.common.actions.delete"),e[87]=a,e[88]=Re):Re=e[88];let Fe;e[89]!==T||e[90]!==u||e[91]!==Re?(Fe=t.jsx(J,{size:"sm",onClick:T,disabled:u,children:Re}),e[89]=T,e[90]=u,e[91]=Re,e[92]=Fe):Fe=e[92];let Ue;e[93]!==Pe||e[94]!==Fe?(Ue=t.jsxs(Zt,{children:[Pe,Fe]}),e[93]=Pe,e[94]=Fe,e[95]=Ue):Ue=e[95];let _e;e[96]!==Ne||e[97]!==Ue?(_e=t.jsxs(Ut,{className:"max-w-md",children:[Ne,Ue]}),e[96]=Ne,e[97]=Ue,e[98]=_e):_e=e[98];let Ke;e[99]!==de||e[100]!==be||e[101]!==_e?(Ke=t.jsx(Kt,{open:de,onOpenChange:be,children:_e}),e[99]=de,e[100]=be,e[101]=_e,e[102]=Ke):Ke=e[102];const qe=r!==null;let ce;e[103]===Symbol.for("react.memo_cache_sentinel")?(ce=he=>!he&&i(null),e[103]=ce):ce=e[103];let G;e[104]!==a?(G=a("settings.skills.sidebar.renameDialog.title"),e[104]=a,e[105]=G):G=e[105];let pe;e[106]!==G?(pe=t.jsx($t,{children:G}),e[106]=G,e[107]=pe):pe=e[107];const je=r?.name??"";let Ee;e[108]!==a||e[109]!==je?(Ee=a("settings.skills.sidebar.renameDialog.description",{name:je}),e[108]=a,e[109]=je,e[110]=Ee):Ee=e[110];let Se;e[111]!==Ee?(Se=t.jsx(Ht,{children:Ee}),e[111]=Ee,e[112]=Se):Se=e[112];let Ve;e[113]!==pe||e[114]!==Se?(Ve=t.jsxs(Bt,{children:[pe,Se]}),e[113]=pe,e[114]=Se,e[115]=Ve):Ve=e[115];let Z;e[116]===Symbol.for("react.memo_cache_sentinel")?(Z=he=>d(he.target.value),e[116]=Z):Z=e[116];let y;e[117]!==a?(y=a("settings.skills.sidebar.renameDialog.placeholder"),e[117]=a,e[118]=y):y=e[118];let ue;e[119]!==V?(ue=he=>{he.key==="Enter"&&V()},e[119]=V,e[120]=ue):ue=e[120];let Ie;e[121]!==o||e[122]!==y||e[123]!==ue?(Ie=t.jsx(tt,{value:o,onChange:Z,placeholder:y,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:ue}),e[121]=o,e[122]=y,e[123]=ue,e[124]=Ie):Ie=e[124];let Oe;e[125]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>i(null),e[125]=Oe):Oe=e[125];let We;e[126]!==a?(We=a("settings.common.actions.cancel"),e[126]=a,e[127]=We):We=e[127];let rt;e[128]!==We?(rt=t.jsx(J,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Oe,children:We}),e[128]=We,e[129]=rt):rt=e[129];let it;e[130]!==a?(it=a("settings.common.actions.rename"),e[130]=a,e[131]=it):it=e[131];let nt;e[132]!==V||e[133]!==it?(nt=t.jsx(J,{size:"sm",onClick:V,children:it}),e[132]=V,e[133]=it,e[134]=nt):nt=e[134];let dt;e[135]!==rt||e[136]!==nt?(dt=t.jsxs(Zt,{children:[rt,nt]}),e[135]=rt,e[136]=nt,e[137]=dt):dt=e[137];let Ye;e[138]!==Ve||e[139]!==Ie||e[140]!==dt?(Ye=t.jsxs(Ut,{children:[Ve,Ie,dt]}),e[138]=Ve,e[139]=Ie,e[140]=dt,e[141]=Ye):Ye=e[141];let $e;e[142]!==qe||e[143]!==Ye?($e=t.jsx(Kt,{open:qe,onOpenChange:ce,children:Ye}),e[142]=qe,e[143]=Ye,e[144]=$e):$e=e[144];let mt;return e[145]!==ye||e[146]!==se||e[147]!==Ke||e[148]!==$e?(mt=t.jsxs("div",{className:ne,children:[ye,se,Ke,$e]}),e[145]=ye,e[146]=se,e[147]=Ke,e[148]=$e,e[149]=mt):mt=e[149],mt},fa=s=>{const e=st.c(49),{skill:n,isSelected:a,onSelect:r,onDelete:i,onRename:o,onDuplicate:d,isMenuOpen:c,onMenuOpenChange:f}=s,{t:u}=ot();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=ta(),e[0]=p):p=e[0];const m=p;let I;e[1]!==n.source||e[2]!==u?(I=n.source==="claude"?u("settings.skills.sidebar.badge.claude"):n.source==="agents"?u("settings.skills.sidebar.badge.agents"):u("settings.skills.sidebar.badge.opencode"),e[1]=n.source,e[2]=u,e[3]=I):I=e[3];const g=I;let h;e[4]!==n?(h=In(n),e[4]=n,e[5]=h):h=e[5];const x=h,[E,S]=l.useState(!1);let C;e[6]!==i||e[7]!==d||e[8]!==o||e[9]!==u?(C=w=>t.jsxs(t.Fragment,{children:[t.jsxs(w,{onClick:H=>{H.stopPropagation(),o()},children:[t.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),t.jsxs(w,{onClick:H=>{H.stopPropagation(),d()},children:[t.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),t.jsxs(w,{onClick:H=>{H.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]})]}),e[6]=i,e[7]=d,e[8]=o,e[9]=u,e[10]=C):C=e[10];const M=C,k=!x&&E,v=a?"bg-interactive-selection":"hover:bg-interactive-hover";let b;e[11]!==v?(b=le("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",v),e[11]=v,e[12]=b):b=e[12];let D;e[13]!==x?(D=!m&&!x?w=>{w.preventDefault(),S(!0)}:void 0,e[13]=x,e[14]=D):D=e[14];let U;e[15]!==b||e[16]!==D?(U=t.jsx("div",{className:b,onContextMenu:D}),e[15]=b,e[16]=D,e[17]=U):U=e[17];let T;e[18]!==n.name?(T=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[18]=n.name,e[19]=T):T=e[19];let F;e[20]!==n.scope?(F=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]=F):F=e[21];let j;e[22]!==g?(j=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]=j):j=e[23];let P;e[24]!==T||e[25]!==F||e[26]!==j?(P=t.jsxs("div",{className:"flex items-center gap-1.5",children:[T,F,j]}),e[24]=T,e[25]=F,e[26]=j,e[27]=P):P=e[27];let O;e[28]!==r||e[29]!==P?(O=t.jsx("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:P}),e[28]=r,e[29]=P,e[30]=O):O=e[30];let R;e[31]!==x||e[32]!==c||e[33]!==f||e[34]!==M?(R=x?null:t.jsxs(gs,{open:c,onOpenChange:w=>{w&&S(!1),f(w)},children:[t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:M(ws)})]}),e[31]=x,e[32]=c,e[33]=f,e[34]=M,e[35]=R):R=e[35];let V;e[36]!==O||e[37]!==R?(V=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[O,R]}),e[36]=O,e[37]=R,e[38]=V):V=e[38];let B;e[39]!==V||e[40]!==U?(B=t.jsx(nn,{render:U,children:V}),e[39]=V,e[40]=U,e[41]=B):B=e[41];let ee;e[42]!==x||e[43]!==M?(ee=x?null:t.jsx(an,{className:"w-fit min-w-20",children:M(qs)}),e[42]=x,e[43]=M,e[44]=ee):ee=e[44];let Y;return e[45]!==B||e[46]!==ee||e[47]!==k?(Y=t.jsxs(sn,{open:k,onOpenChange:S,children:[B,ee]}),e[45]=B,e[46]=ee,e[47]=k,e[48]=Y):Y=e[48],Y};function Hg(s){return{selectedSkillName:s.selectedSkillName,skills:s.skills,setSelectedSkill:s.setSelectedSkill,setSkillDraft:s.setSkillDraft,createSkill:s.createSkill,deleteSkill:s.deleteSkill,getSkillDetail:s.getSkillDetail}}function Wg(s){return s.scope==="project"}function qg(s){return s.scope==="user"}function Gg(s,e){return s.localeCompare(e)}function Jg(s,e){return s.name.localeCompare(e.name)}function Qg(s,e){return s.name.localeCompare(e.name)}const Yg=s=>s!==null&&typeof s=="object"&&"updateStatus"in s&&typeof s.updateStatus=="function",Xg=s=>{const e=document.createElement("div");e.className="cm-vim-panel";const n=Qc(s);if(!n)return{top:!1,dom:e};n.state.statusbar=e;const a=n.state.vimPlugin;return Yg(a)&&a.updateStatus(),{top:!1,dom:e,destroy(){n.state.statusbar===e&&(n.state.statusbar=null)}}};function go(s){return s?[qc(),Gc.of(Xg),Jc()]:[]}const Zg={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},eh={case:"Match case",re:"Regular expression",word:"Match whole word"};function th(s){const e=s.querySelector(".cm-search");if(e){for(const[n,a]of Object.entries(Zg)){const r=e.querySelector(`button[name="${n}"]`);r&&!r.title&&(r.title=a)}for(const[n,a]of Object.entries(eh)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=a)}}}const cr=new WeakMap;function sh(s,e){const n=Ra(s.state);if(!n.valid)return cr.delete(s),0;const a=cr.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 o=r.next();!o.done;o=r.next())i+=1;return cr.set(s,{query:n,doc:s.state.doc,total:i}),i}function nh(s){const e=Ra(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 o=a.next();!o.done;o=a.next()){const d=o.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=sh(e,n),o=i===0?0:nh(e);r.textContent=i===0?"":`${o}/${i}`}const fo=new wn,xo=new wn,bo=new wn,yo=new wn,vo=new wn,jo=new wn,wo=new wn,No=s=>s,dr=ad,ah=rd,rh=id;class ih extends od{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 ko=(s,e)=>!s||s.length===0?[]:wl.define({create(n){const a=new Qr,r=[...s].sort((i,o)=>i.afterLine-o.afterLine);for(const i of r){const o=n.doc.lines;if(i.afterLine>o)continue;const d=n.doc.line(i.afterLine);a.add(d.to,d.to,Ka.widget({widget:new ih(i.id,e),block:!0,side:1}))}return a.finish()},update(n,a){return n.map(a.changes)},provide:n=>Fs.decorations.from(n)}),So=s=>{if(!s)return[];const e=Math.max(1,s.start),n=Math.max(e,s.end);return jl.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 Qr;for(let i=e;i<=n&&i<=a.state.doc.lines;i+=1){const o=a.state.doc.line(i);r.add(o.from,o.from,Ka.line({class:"oc-cm-selected-line"}))}return r.finish()}},{decorations:a=>a.decorations})};function Co({value:s,onChange:e,extensions:n,className:a,readOnly:r,lineNumbersConfig:i,highlightLines:o,onViewReady:d,onViewDestroy:c,blockWidgets:f,enableSearch:u,searchOpen:p,onSearchOpenChange:m,vimMode:I}){const g=l.useRef(null),h=l.useRef(null),x=l.useRef(s),E=l.useRef(e),S=l.useRef(d),C=l.useRef(c),M=l.useRef(m),k=l.useRef(f),v=l.useRef(I),b=l.useRef(new Map),[D,U]=l.useState([]),T=l.useCallback(j=>{const P=(j??[]).map(O=>{const R=b.current.get(O.id);return R?{id:O.id,content:O.content,container:R}:null}).filter(O=>O!==null);U(O=>O.length===P.length&&O.every((R,V)=>{const B=P[V];return R.id===B.id&&R.content===B.content&&R.container===B.container})?O:P)},[]),F=l.useCallback(j=>{const P=g.current,O=j??h.current;if(!P||!O)return;const R=O.dom.querySelector(".cm-gutters"),V=R instanceof HTMLElement?R.getBoundingClientRect().width:0;P.style.setProperty("--oc-editor-gutter-width",`${V}px`)},[]);return l.useEffect(()=>{x.current=s},[s]),l.useEffect(()=>{E.current=e},[e]),l.useEffect(()=>{S.current=d,C.current=c},[d,c]),l.useEffect(()=>{M.current=m},[m]),l.useEffect(()=>{k.current=f,T(f)},[f,T]),l.useEffect(()=>{if(!g.current)return;const j=(()=>{if(typeof document>"u")return null;const O=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(O)return O;const R=window.__OPENCHAMBER_CSP_NONCE__;return typeof R=="string"&&R.length>0?R:null})(),P=Yc.create({doc:x.current,extensions:[...j?[Fs.cspNonce.of(j)]:[],Xc({fixed:!0}),fo.of(ii(i)),Zc(),ed.of(" "),wo.of(go(I)),Ja.of([td,...sd,...nd]),Fs.updateListener.of(O=>{F(O.view),(O.viewportChanged||O.geometryChanged)&&T(k.current);const R=oi(O.startState),V=oi(O.state);R!==V&&M.current?.(V);const B=!Ra(O.startState).eq(Ra(O.state));if(V&&(R!==V||B||O.docChanged||O.selectionSet)&&ho(O.view.dom,O.view,R!==V||B||O.docChanged),!O.docChanged)return;const ee=O.state.doc.toString();x.current=ee,E.current(ee),T(k.current)}),xo.of(Fs.editable.of(!r)),bo.of(n??[]),yo.of(So(o)),vo.of(ko(f,b.current)),jo.of(u?[li({top:!0}),Ja.of(No(ci))]:[])]});return h.current=new Fs({state:P,parent:g.current}),dr(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{F(h.current),T(k.current)}),h.current&&S.current?.(h.current),()=>{C.current?.(),h.current?.destroy(),h.current=null,U([])}},[k,F,T]),l.useEffect(()=>{const j=h.current;j&&(j.dispatch({effects:[fo.reconfigure(ii(i)),xo.reconfigure(Fs.editable.of(!r)),bo.reconfigure(n??[]),yo.reconfigure(So(o)),vo.reconfigure(ko(f,b.current)),jo.reconfigure(u?[li({top:!0}),Ja.of(No(ci))]:[])]}),dr(j,j.state.doc.length,200),j.requestMeasure(),requestAnimationFrame(()=>{F(j),T(k.current)}))},[n,o,i,r,f,u,F,T]),l.useEffect(()=>{const j=h.current;if(!j){v.current=I;return}v.current!==I&&(v.current=I,j.dispatch({effects:wo.reconfigure(go(I))}))},[I]),l.useEffect(()=>{const j=h.current;!j||u===!1||(p?(ah(j),requestAnimationFrame(()=>{th(j.dom),ho(j.dom,j,!0)})):rh(j))},[p,u]),l.useEffect(()=>{const j=h.current;if(!j)return;const P=j.state.doc.toString();P!==s&&(j.dispatch({changes:{from:0,to:P.length,insert:s}}),dr(j,j.state.doc.length,300),j.requestMeasure(),requestAnimationFrame(()=>F(j)))},[s,F]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:g,className:le("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)}),D.map(j=>Na.createPortal(j.content,j.container,j.id))]})}const oh=s=>{const e=st.c(11),{currentMode:n,onToggle:a}=s,r=n==="preview",i=r?"Switch to edit mode":"Switch to preview mode",o=r?"Edit":"Preview";let d;e[0]!==r?(d=r?t.jsx(A,{name:"eye",className:"size-4","aria-hidden":"true"}):t.jsx(A,{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(Dt,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"sm",onClick:a,"aria-label":i,className:"h-5 w-5 p-0",children:d})}),e[2]=i,e[3]=a,e[4]=d,e[5]=c):c=e[5];let f;e[6]!==o?(f=t.jsx(At,{sideOffset:8,children:o}),e[6]=o,e[7]=f):f=e[7];let u;return e[8]!==c||e[9]!==f?(u=t.jsxs(It,{children:[c,f]}),e[8]=c,e[9]=f,e[10]=u):u=e[10],u},Cs=ln()(sa(Jr((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 Ud();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 Kd();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 zd();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=Os()?.settings;if(r)try{const o=(await r.load())?.settings||{};a=n(o.defaultGitIdentityId)}catch{}}if(a===null)try{const r=await pt("/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 Ct({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 Od(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(o=>o.id===n);if(!r)throw new Error("Profile not found");const i={...r,...a};return await Ld(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 Fd(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:Zr(),partialize:s=>({selectedProfileId:s.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Cs);const lh=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,ch=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},dh=async()=>{try{const s=Os()?.settings;if(s)return(await s.load())?.settings||{};const e=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},mh=s=>{const e=st.c(160),{open:n,onOpenChange:a}=s,{t:r}=ot(),i=Vs(uh),o=Vs(ph),d=Vs(gh),c=Vs(hh),f=Vs(fh),u=Cs(xh),p=Cs(bh),[m,I]=l.useState(""),[g,h]=l.useState(""),[x,E]=l.useState("");let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[0]=S):S=e[0];const[C,M]=l.useState(S),[k,v]=l.useState(null),[b,D]=l.useState(!1);let U;e[1]===Symbol.for("react.memo_cache_sentinel")?(U=[],e[1]=U):U=e[1];const[T,F]=l.useState(U),[j,P]=l.useState(null),O=l.useRef(0);let R;e[2]===Symbol.for("react.memo_cache_sentinel")?(R=he=>{O.current=O.current+1,D(!1),v(null),he?.clearIdentity&&(F([]),P(null))},e[2]=R):R=e[2];const V=R;let B,ee;e[3]!==p||e[4]!==n?(B=()=>{n&&(O.current=O.current+1,I(""),h(""),E(""),v(null),D(!1),F([]),P(null),p(),(async()=>{const he=await dh(),et=Array.isArray(he?.skillCatalogs)?he?.skillCatalogs:[];M(et||[])})())},ee=[n,p],e[3]=p,e[4]=n,e[5]=B,e[6]=ee):(B=e[5],ee=e[6]),l.useEffect(B,ee);let Y;e[7]!==g?(Y=g.trim(),e[7]=g,e[8]=Y):Y=e[8];const w=Y;let H;e[9]!==x?(H=x.trim(),e[9]=x,e[10]=H):H=e[10];const Q=H;let z;if(e[11]!==C||e[12]!==w||e[13]!==Q){let he;e[15]!==w||e[16]!==Q?(he=et=>{const Xe=(et.source||"").trim(),He=(et.subpath||"").trim();return Xe===w&&He===Q},e[15]=w,e[16]=Q,e[17]=he):he=e[17],z=C.some(he),e[11]=C,e[12]=w,e[13]=Q,e[14]=z}else z=e[14];const L=z;let X;e[18]!==u||e[19]!==j||e[20]!==m||e[21]!==i||e[22]!==g||e[23]!==x||e[24]!==r?(X=async()=>{const he=g.trim();if(!he){q.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||I(ch(he)),D(!1),v(null);const et=O.current+1;O.current=et;const Xe=await i({source:he,subpath:x.trim()||void 0,gitIdentityId:j||void 0});if(O.current!==et)return;if(!Xe.ok){if(Xe.error?.kind==="authRequired"){if(fs()){q.error(r("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const bt=Xe.error.identities||[];if(F(bt),!j&&bt.length>0){const wt=u&&u!=="global"&&bt.some(Pt=>Pt.id===u)?u:bt[0].id;P(wt)}q.error(r("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}q.error(Xe.error?.message||r("settings.skills.catalog.add.toast.scanFailed"));return}const He=Xe.items?.length||0;if(v(He),He===0){q.error(r("settings.skills.catalog.add.toast.noSkillsFound")),D(!1);return}F([]),D(!0),q.success(r("settings.skills.catalog.shared.toast.foundSkills",{count:He}))},e[18]=u,e[19]=j,e[20]=m,e[21]=i,e[22]=g,e[23]=x,e[24]=r,e[25]=X):X=e[25];const $=X;let ne;e[26]!==C||e[27]!==j||e[28]!==L||e[29]!==m||e[30]!==o||e[31]!==d||e[32]!==a||e[33]!==b||e[34]!==c||e[35]!==g||e[36]!==x||e[37]!==r?(ne=async()=>{const he=m.trim(),et=g.trim(),Xe=x.trim();if(!he){q.error(r("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!et){q.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!b){q.error(r("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(L){q.error(r("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const He={id:lh(),label:he,source:et,...Xe?{subpath:Xe}:{},...j?{gitIdentityId:j}:{}},bt=[...C,He];try{await Ct({skillCatalogs:bt}),M(bt),q.success(r("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),await d(He.id,{refresh:!0}),c(He.id),a(!1)}catch(wt){const Pt=wt;q.error(Pt instanceof Error?Pt.message:r("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=C,e[27]=j,e[28]=L,e[29]=m,e[30]=o,e[31]=d,e[32]=a,e[33]=b,e[34]=c,e[35]=g,e[36]=x,e[37]=r,e[38]=ne):ne=e[38];const re=ne;let _;e[39]!==r?(_=r("settings.skills.catalog.add.title"),e[39]=r,e[40]=_):_=e[40];let oe;e[41]!==_?(oe=t.jsx($t,{children:_}),e[41]=_,e[42]=oe):oe=e[42];let fe;e[43]!==r?(fe=r("settings.skills.catalog.add.descriptionPrefix"),e[43]=r,e[44]=fe):fe=e[44];let xe;e[45]===Symbol.for("react.memo_cache_sentinel")?(xe=t.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=xe):xe=e[45];let Ce;e[46]!==r?(Ce=r("settings.skills.catalog.add.descriptionSuffix"),e[46]=r,e[47]=Ce):Ce=e[47];let ve;e[48]!==fe||e[49]!==Ce?(ve=t.jsxs(Ht,{children:[fe," ",xe,Ce]}),e[48]=fe,e[49]=Ce,e[50]=ve):ve=e[50];let we;e[51]!==oe||e[52]!==ve?(we=t.jsxs(Bt,{children:[oe,ve]}),e[51]=oe,e[52]=ve,e[53]=we):we=e[53];let ye;e[54]!==r?(ye=r("settings.skills.catalog.add.field.catalogName"),e[54]=r,e[55]=ye):ye=e[55];let se;e[56]!==ye?(se=t.jsx("label",{className:"typography-ui-label text-foreground",children:ye}),e[56]=ye,e[57]=se):se=e[57];let de;e[58]===Symbol.for("react.memo_cache_sentinel")?(de=he=>I(he.target.value),e[58]=de):de=e[58];let be;e[59]!==r?(be=r("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=r,e[60]=be):be=e[60];let W;e[61]!==m||e[62]!==be?(W=t.jsx(tt,{value:m,onChange:de,placeholder:be}),e[61]=m,e[62]=be,e[63]=W):W=e[63];let te;e[64]!==se||e[65]!==W?(te=t.jsxs("div",{className:"space-y-2",children:[se,W]}),e[64]=se,e[65]=W,e[66]=te):te=e[66];let ae;e[67]!==r?(ae=r("settings.skills.catalog.add.field.repository"),e[67]=r,e[68]=ae):ae=e[68];let me;e[69]!==ae?(me=t.jsx("label",{className:"typography-ui-label text-foreground",children:ae}),e[69]=ae,e[70]=me):me=e[70];let Me;e[71]===Symbol.for("react.memo_cache_sentinel")?(Me=he=>{h(he.target.value),V({clearIdentity:!0})},e[71]=Me):Me=e[71];let Ne;e[72]!==r?(Ne=r("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[72]=r,e[73]=Ne):Ne=e[73];let De;e[74]!==g||e[75]!==Ne?(De=t.jsx(tt,{value:g,onChange:Me,placeholder:Ne}),e[74]=g,e[75]=Ne,e[76]=De):De=e[76];let Ae;e[77]!==r?(Ae=r("settings.skills.catalog.add.field.repositoryHint"),e[77]=r,e[78]=Ae):Ae=e[78];let Pe;e[79]!==Ae?(Pe=t.jsx("p",{className:"typography-micro text-muted-foreground",children:Ae}),e[79]=Ae,e[80]=Pe):Pe=e[80];let Re;e[81]!==me||e[82]!==De||e[83]!==Pe?(Re=t.jsxs("div",{className:"space-y-2",children:[me,De,Pe]}),e[81]=me,e[82]=De,e[83]=Pe,e[84]=Re):Re=e[84];let Fe;e[85]!==r?(Fe=r("settings.skills.catalog.add.field.optionalSubpath"),e[85]=r,e[86]=Fe):Fe=e[86];let Ue;e[87]!==Fe?(Ue=t.jsx("label",{className:"typography-ui-label text-foreground",children:Fe}),e[87]=Fe,e[88]=Ue):Ue=e[88];let _e;e[89]===Symbol.for("react.memo_cache_sentinel")?(_e=he=>{E(he.target.value),V({clearIdentity:!0})},e[89]=_e):_e=e[89];let Ke;e[90]!==r?(Ke=r("settings.skills.catalog.shared.field.subpathPlaceholder"),e[90]=r,e[91]=Ke):Ke=e[91];let qe;e[92]!==x||e[93]!==Ke?(qe=t.jsx(tt,{value:x,onChange:_e,placeholder:Ke}),e[92]=x,e[93]=Ke,e[94]=qe):qe=e[94];let ce;e[95]!==Ue||e[96]!==qe?(ce=t.jsxs("div",{className:"space-y-2",children:[Ue,qe]}),e[95]=Ue,e[96]=qe,e[97]=ce):ce=e[97];let G;e[98]!==j||e[99]!==T||e[100]!==r?(G=T.length>0&&!fs()?t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:r("settings.skills.catalog.shared.auth.title")}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:r("settings.skills.catalog.shared.auth.description")})]}),t.jsxs(Tt,{value:j||"",onValueChange:he=>{P(he),V()},children:[t.jsx(Ft,{className:"w-fit",children:t.jsx("span",{children:T.find(he=>he.id===j)?.name||r("settings.skills.catalog.shared.auth.chooseIdentity")})}),t.jsx(Lt,{align:"start",children:T.map(yh)})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:r("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[98]=j,e[99]=T,e[100]=r,e[101]=G):G=e[101];let pe;e[102]!==k||e[103]!==r?(pe=k!==null?t.jsx("div",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.add.scanResult",{count:k})}):null,e[102]=k,e[103]=r,e[104]=pe):pe=e[104];let je;e[105]!==L||e[106]!==r?(je=L?t.jsx("div",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.add.duplicateMessage")}):null,e[105]=L,e[106]=r,e[107]=je):je=e[107];let Ee;e[108]!==te||e[109]!==Re||e[110]!==ce||e[111]!==G||e[112]!==pe||e[113]!==je?(Ee=t.jsxs("div",{className:"space-y-4",children:[te,Re,ce,G,pe,je]}),e[108]=te,e[109]=Re,e[110]=ce,e[111]=G,e[112]=pe,e[113]=je,e[114]=Ee):Ee=e[114];let Se;e[115]!==a?(Se=()=>a(!1),e[115]=a,e[116]=Se):Se=e[116];let Ve;e[117]!==r?(Ve=r("settings.common.actions.cancel"),e[117]=r,e[118]=Ve):Ve=e[118];let Z;e[119]!==Se||e[120]!==Ve?(Z=t.jsx(J,{size:"sm",variant:"ghost",onClick:Se,children:Ve}),e[119]=Se,e[120]=Ve,e[121]=Z):Z=e[121];let y;e[122]!==$?(y=()=>{$()},e[122]=$,e[123]=y):y=e[123];let ue;e[124]!==f||e[125]!==g?(ue=f||!g.trim(),e[124]=f,e[125]=g,e[126]=ue):ue=e[126];let Ie;e[127]===Symbol.for("react.memo_cache_sentinel")?(Ie=t.jsx(A,{name:"git-repository",className:"h-4 w-4"}),e[127]=Ie):Ie=e[127];let Oe;e[128]!==f||e[129]!==r?(Oe=r(f?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[128]=f,e[129]=r,e[130]=Oe):Oe=e[130];let We;e[131]!==y||e[132]!==ue||e[133]!==Oe?(We=t.jsxs(J,{size:"sm",className:"gap-2",variant:"ghost",onClick:y,disabled:ue,children:[Ie,Oe]}),e[131]=y,e[132]=ue,e[133]=Oe,e[134]=We):We=e[134];let rt;e[135]!==re?(rt=()=>{re()},e[135]=re,e[136]=rt):rt=e[136];let it;e[137]!==L||e[138]!==m||e[139]!==b||e[140]!==g?(it=!b||L||!m.trim()||!g.trim(),e[137]=L,e[138]=m,e[139]=b,e[140]=g,e[141]=it):it=e[141];let nt;e[142]!==r?(nt=r("settings.skills.catalog.add.actions.addCatalog"),e[142]=r,e[143]=nt):nt=e[143];let dt;e[144]!==rt||e[145]!==it||e[146]!==nt?(dt=t.jsx(J,{size:"sm",onClick:rt,disabled:it,children:nt}),e[144]=rt,e[145]=it,e[146]=nt,e[147]=dt):dt=e[147];let Ye;e[148]!==Z||e[149]!==We||e[150]!==dt?(Ye=t.jsxs(Zt,{children:[Z,We,dt]}),e[148]=Z,e[149]=We,e[150]=dt,e[151]=Ye):Ye=e[151];let $e;e[152]!==we||e[153]!==Ee||e[154]!==Ye?($e=t.jsxs(Ut,{className:"max-w-xl",children:[we,Ee,Ye]}),e[152]=we,e[153]=Ee,e[154]=Ye,e[155]=$e):$e=e[155];let mt;return e[156]!==a||e[157]!==n||e[158]!==$e?(mt=t.jsx(Kt,{open:n,onOpenChange:a,children:$e}),e[156]=a,e[157]=n,e[158]=$e,e[159]=mt):mt=e[159],mt};function uh(s){return s.scanRepo}function ph(s){return s.loadCatalog}function gh(s){return s.loadSource}function hh(s){return s.setSelectedSource}function fh(s){return s.isScanning}function xh(s){return s.defaultGitIdentityId}function bh(s){return s.loadDefaultGitIdentityId}function yh(s){return t.jsx(ht,{value:s.id,children:s.name},s.id)}const vh=s=>{const e=st.c(85),{open:n,onOpenChange:a,conflicts:r,onConfirm:i}=s,{t:o}=ot();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];const[c,f]=l.useState(d);let u,p;e[1]!==r||e[2]!==n?(u=()=>{if(!n)return;const re={};for(const _ of r)re[_.skillName]="skip";f(re)},p=[n,r],e[1]=r,e[2]=n,e[3]=u,e[4]=p):(u=e[3],p=e[4]),l.useEffect(u,p);let m;e[5]!==r?(m=re=>{const _={};for(const oe of r)_[oe.skillName]=re;f(_)},e[5]=r,e[6]=m):m=e[6];const I=m;let g;e[7]!==r||e[8]!==c?(g=r.length>0&&r.every(re=>c[re.skillName]),e[7]=r,e[8]=c,e[9]=g):g=e[9];const h=g;let x;e[10]!==o?(x=o("settings.skills.catalog.conflicts.title"),e[10]=o,e[11]=x):x=e[11];let E;e[12]!==x?(E=t.jsx($t,{children:x}),e[12]=x,e[13]=E):E=e[13];let S;e[14]!==o?(S=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=S):S=e[15];let C;e[16]!==S?(C=t.jsx(Ht,{children:S}),e[16]=S,e[17]=C):C=e[17];let M;e[18]!==E||e[19]!==C?(M=t.jsxs(Bt,{children:[E,C]}),e[18]=E,e[19]=C,e[20]=M):M=e[20];let k;e[21]!==r.length||e[22]!==o?(k=o("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=o,e[23]=k):k=e[23];let v;e[24]!==k?(v=t.jsx("span",{className:"typography-meta text-muted-foreground",children:k}),e[24]=k,e[25]=v):v=e[25];let b;e[26]!==I?(b=()=>I("skip"),e[26]=I,e[27]=b):b=e[27];let D;e[28]!==o?(D=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=D):D=e[29];let U;e[30]!==b||e[31]!==D?(U=t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:b,children:D}),e[30]=b,e[31]=D,e[32]=U):U=e[32];let T;e[33]!==I?(T=()=>I("overwrite"),e[33]=I,e[34]=T):T=e[34];let F;e[35]!==o?(F=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=F):F=e[36];let j;e[37]!==T||e[38]!==F?(j=t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:T,children:F}),e[37]=T,e[38]=F,e[39]=j):j=e[39];let P;e[40]!==U||e[41]!==j?(P=t.jsxs("div",{className:"flex items-center gap-2",children:[U,j]}),e[40]=U,e[41]=j,e[42]=P):P=e[42];let O;e[43]!==v||e[44]!==P?(O=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[v,P]}),e[43]=v,e[44]=P,e[45]=O):O=e[45];let R;if(e[46]!==r||e[47]!==c||e[48]!==o){let re;e[50]!==c||e[51]!==o?(re=_=>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:_.skillName}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:_.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:_.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),t.jsxs(Tt,{value:c[_.skillName]||"skip",onValueChange:oe=>f(fe=>({...fe,[_.skillName]:oe})),children:[t.jsx(Ft,{className:"w-fit",children:t.jsx("span",{className:"capitalize",children:(c[_.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),t.jsx(ht,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},_.skillName),e[50]=c,e[51]=o,e[52]=re):re=e[52],R=r.map(re),e[46]=r,e[47]=c,e[48]=o,e[49]=R}else R=e[49];let V;e[53]!==R?(V=t.jsx("div",{className:"space-y-2",children:R}),e[53]=R,e[54]=V):V=e[54];let B;e[55]!==O||e[56]!==V?(B=t.jsxs("div",{className:"space-y-3",children:[O,V]}),e[55]=O,e[56]=V,e[57]=B):B=e[57];let ee;e[58]!==a?(ee=()=>a(!1),e[58]=a,e[59]=ee):ee=e[59];let Y;e[60]!==o?(Y=o("settings.common.actions.cancel"),e[60]=o,e[61]=Y):Y=e[61];let w;e[62]!==ee||e[63]!==Y?(w=t.jsx(J,{size:"sm",variant:"ghost",onClick:ee,children:Y}),e[62]=ee,e[63]=Y,e[64]=w):w=e[64];let H;e[65]!==c||e[66]!==i?(H=()=>i(c),e[65]=c,e[66]=i,e[67]=H):H=e[67];const Q=!h;let z;e[68]!==o?(z=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=z):z=e[69];let L;e[70]!==H||e[71]!==Q||e[72]!==z?(L=t.jsx(J,{size:"sm",onClick:H,disabled:Q,children:z}),e[70]=H,e[71]=Q,e[72]=z,e[73]=L):L=e[73];let X;e[74]!==w||e[75]!==L?(X=t.jsxs(Zt,{children:[w,L]}),e[74]=w,e[75]=L,e[76]=X):X=e[76];let $;e[77]!==M||e[78]!==B||e[79]!==X?($=t.jsxs(Ut,{className:"max-w-2xl",children:[M,B,X]}),e[77]=M,e[78]=B,e[79]=X,e[80]=$):$=e[80];let ne;return e[81]!==a||e[82]!==n||e[83]!==$?(ne=t.jsx(Kt,{open:n,onOpenChange:a,children:$}),e[81]=a,e[82]=n,e[83]=$,e[84]=ne):ne=e[84],ne},ei=[{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 ea(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 ql(s){if(s==="user-claude")return{scope:"user",source:"claude"};if(s==="project-claude")return{scope:"project",source:"claude"};const e=ei.find(n=>n.value===s);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const jh=s=>{const e=st.c(124),{open:n,onOpenChange:a,item:r}=s,{t:i}=ot(),o=Vs(wh),d=Vs(Nh),[c,f]=l.useState("user"),[u,p]=l.useState("opencode"),m=os(kh),I=os(Sh),[g,h]=l.useState(null),[x,E]=l.useState(!1);let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[0]=S):S=e[0];const[C,M]=l.useState(S),[k,v]=l.useState(null);let b,D;e[1]!==I||e[2]!==n?(b=()=>{n&&(f("user"),p("opencode"),h(I),E(!1),M([]),v(null))},D=[n,I],e[1]=I,e[2]=n,e[3]=b,e[4]=D):(b=e[3],D=e[4]),l.useEffect(b,D);let U;e[5]!==i?(U=ce=>{switch(ce){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 T=U;let F;e[7]!==i?(F=ce=>{switch(ce){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]=F):F=e[8];const j=F;let P;e:{if(m.length===0){P=null;break e}if(g&&m.some(ce=>ce.id===g)){P=g;break e}if(I&&m.some(ce=>ce.id===I)){P=I;break e}P=m[0]?.id??null}const O=P;let R;e:{if(c!=="project"){R=null;break e}const ce=O;if(!ce){R=null;break e}let G;if(e[9]!==ce||e[10]!==m){let je;e[12]!==ce?(je=Ee=>Ee.id===ce,e[12]=ce,e[13]=je):je=e[13],G=m.find(je),e[9]=ce,e[10]=m,e[11]=G}else G=e[11];R=G?.path??null}const V=R;let B;e[14]!==o||e[15]!==r||e[16]!==a||e[17]!==i?(B=async ce=>{const G={skillDir:ce.skillDir};r?.clawdhub&&(G.clawdhub={slug:r.clawdhub.slug,version:r.clawdhub.version});const pe=await o({source:ce.source,subpath:ce.subpath,gitIdentityId:r?.gitIdentityId,scope:ce.scope,targetSource:ce.targetSource,selections:[G],conflictPolicy:"prompt",conflictDecisions:ce.conflictDecisions},{directory:ce.directoryOverride??null});if(pe.ok){q.success(i("settings.skills.catalog.installSkill.toast.installed")),a(!1);return}if(pe.error?.kind==="conflicts"){v({source:ce.source,subpath:ce.subpath,scope:ce.scope,targetSource:ce.targetSource,skillDir:ce.skillDir,directoryOverride:ce.directoryOverride??null}),M(pe.error.conflicts),E(!0);return}if(pe.error?.kind==="authRequired"){q.error(pe.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}q.error(pe.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=o,e[15]=r,e[16]=a,e[17]=i,e[18]=B):B=e[18];const ee=B;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 w;e[21]!==Y?(w=t.jsx($t,{children:Y}),e[21]=Y,e[22]=w):w=e[22];let H;e[23]!==i?(H=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=H):H=e[24];let Q;e[25]!==r.skillName?(Q=t.jsx("span",{className:"font-semibold text-foreground",children:r.skillName}),e[25]=r.skillName,e[26]=Q):Q=e[26];let z;e[27]!==i?(z=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=z):z=e[28];let L;e[29]!==H||e[30]!==Q||e[31]!==z?(L=t.jsxs(Ht,{children:[H," ",Q," ",z]}),e[29]=H,e[30]=Q,e[31]=z,e[32]=L):L=e[32];let X;e[33]!==w||e[34]!==L?(X=t.jsxs(Bt,{children:[w,L]}),e[33]=w,e[34]=L,e[35]=X):X=e[35];let $;e[36]!==i?($=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=$):$=e[37];let ne;e[38]!==$?(ne=t.jsx("span",{className:"typography-ui-label text-foreground",children:$}),e[38]=$,e[39]=ne):ne=e[39];let re;e[40]!==c||e[41]!==u?(re=ea(c,u),e[40]=c,e[41]=u,e[42]=re):re=e[42];let _;e[43]===Symbol.for("react.memo_cache_sentinel")?(_=ce=>{const G=ql(ce);f(G.scope),p(G.source==="agents"?"agents":"opencode")},e[43]=_):_=e[43];let oe;e[44]!==c?(oe=c==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=oe):oe=e[45];let fe;e[46]!==u?(fe=u==="agents"?t.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=u,e[47]=fe):fe=e[47];let xe;e[48]!==T||e[49]!==c||e[50]!==u?(xe=T(ea(c,u)),e[48]=T,e[49]=c,e[50]=u,e[51]=xe):xe=e[51];let Ce;e[52]!==xe?(Ce=t.jsx("span",{children:xe}),e[52]=xe,e[53]=Ce):Ce=e[53];let ve;e[54]!==oe||e[55]!==fe||e[56]!==Ce?(ve=t.jsxs(Ft,{className:"w-fit gap-1.5",children:[oe,fe,Ce]}),e[54]=oe,e[55]=fe,e[56]=Ce,e[57]=ve):ve=e[57];let we;e[58]!==j||e[59]!==T?(we=ei.map(ce=>t.jsx(ht,{value:ce.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:[ce.scope==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),ce.source==="agents"?t.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:T(ce.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:j(ce.value)})]})},ce.value)),e[58]=j,e[59]=T,e[60]=we):we=e[60];let ye;e[61]!==we?(ye=t.jsx(Lt,{align:"start",children:we}),e[61]=we,e[62]=ye):ye=e[62];let se;e[63]!==re||e[64]!==ve||e[65]!==ye?(se=t.jsxs(Tt,{value:re,onValueChange:_,children:[ve,ye]}),e[63]=re,e[64]=ve,e[65]=ye,e[66]=se):se=e[66];let de;e[67]!==ne||e[68]!==se?(de=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ne,se]}),e[67]=ne,e[68]=se,e[69]=de):de=e[69];let be;e[70]!==m||e[71]!==O||e[72]!==c||e[73]!==i?(be=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")}),m.length===0?t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):t.jsxs(Tt,{value:O??"",onValueChange:ce=>h(ce),disabled:m.length===1,children:[t.jsx(Ft,{className:"w-fit",children:t.jsx(zt,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),t.jsx(Lt,{align:"start",children:m.map(Ch)})]})]}),e[70]=m,e[71]=O,e[72]=c,e[73]=i,e[74]=be):be=e[74];let W;e[75]!==r.warnings?(W=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]=W):W=e[76];let te;e[77]!==de||e[78]!==be||e[79]!==W?(te=t.jsxs("div",{className:"mt-2 space-y-3",children:[de,be,W]}),e[77]=de,e[78]=be,e[79]=W,e[80]=te):te=e[80];let ae;e[81]!==a?(ae=()=>a(!1),e[81]=a,e[82]=ae):ae=e[82];let me;e[83]!==i?(me=i("settings.common.actions.cancel"),e[83]=i,e[84]=me):me=e[84];let Me;e[85]!==ae||e[86]!==me?(Me=t.jsx(J,{size:"sm",variant:"ghost",onClick:ae,children:me}),e[85]=ae,e[86]=me,e[87]=Me):Me=e[87];const Ne=d||!r.installable||c==="project"&&!V;let De;e[88]!==V||e[89]!==ee||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==u?(De=()=>{ee({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:u,skillDir:r.skillDir,directoryOverride:V})},e[88]=V,e[89]=ee,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=u,e[95]=De):De=e[95];let Ae;e[96]!==d||e[97]!==i?(Ae=i(d?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=d,e[97]=i,e[98]=Ae):Ae=e[98];let Pe;e[99]!==Ne||e[100]!==De||e[101]!==Ae?(Pe=t.jsx(J,{size:"sm",disabled:Ne,onClick:De,children:Ae}),e[99]=Ne,e[100]=De,e[101]=Ae,e[102]=Pe):Pe=e[102];let Re;e[103]!==Me||e[104]!==Pe?(Re=t.jsxs(Zt,{children:[Me,Pe]}),e[103]=Me,e[104]=Pe,e[105]=Re):Re=e[105];let Fe;e[106]!==X||e[107]!==te||e[108]!==Re?(Fe=t.jsxs(Ut,{className:"max-w-md",children:[X,te,Re]}),e[106]=X,e[107]=te,e[108]=Re,e[109]=Fe):Fe=e[109];let Ue;e[110]!==a||e[111]!==n||e[112]!==Fe?(Ue=t.jsx(Kt,{open:n,onOpenChange:a,children:Fe}),e[110]=a,e[111]=n,e[112]=Fe,e[113]=Ue):Ue=e[113];let _e;e[114]!==k||e[115]!==ee?(_e=ce=>{k&&(ee({source:k.source,subpath:k.subpath,scope:k.scope,targetSource:k.targetSource,skillDir:k.skillDir,conflictDecisions:ce,directoryOverride:k.directoryOverride??null}),E(!1))},e[114]=k,e[115]=ee,e[116]=_e):_e=e[116];let Ke;e[117]!==C||e[118]!==x||e[119]!==_e?(Ke=t.jsx(vh,{open:x,onOpenChange:E,conflicts:C,onConfirm:_e}),e[117]=C,e[118]=x,e[119]=_e,e[120]=Ke):Ke=e[120];let qe;return e[121]!==Ue||e[122]!==Ke?(qe=t.jsxs(t.Fragment,{children:[Ue,Ke]}),e[121]=Ue,e[122]=Ke,e[123]=qe):qe=e[123],qe};function wh(s){return s.installSkills}function Nh(s){return s.isInstalling}function kh(s){return s.projects}function Sh(s){return s.activeProjectId}function Ch(s){return t.jsx(ht,{value:s.id,children:s.label||s.path},s.id)}const Ph=async()=>{try{const s=Os()?.settings;if(s)return(await s.load())?.settings||{};const e=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Ih=({mode:s,onModeChange:e,showModeTabs:n=!0})=>{const{t:a}=ot(),{sources:r,itemsBySource:i,selectedSourceId:o,setSelectedSource:d,loadCatalog:c,loadSource:f,loadMoreClawdHub:u,isLoadingCatalog:p,isLoadingSource:m,isLoadingMore:I,loadedSourceIds:g,clawdhubHasMoreBySource:h,lastCatalogError:x}=Vs(Ps(w=>({sources:w.sources,itemsBySource:w.itemsBySource,selectedSourceId:w.selectedSourceId,setSelectedSource:w.setSelectedSource,loadCatalog:w.loadCatalog,loadSource:w.loadSource,loadMoreClawdHub:w.loadMoreClawdHub,isLoadingCatalog:w.isLoadingCatalog,isLoadingSource:w.isLoadingSource,isLoadingMore:w.isLoadingMore,loadedSourceIds:w.loadedSourceIds,clawdhubHasMoreBySource:w.clawdhubHasMoreBySource,lastCatalogError:w.lastCatalogError}))),[E,S]=l.useState(""),[C,M]=l.useState(!1),[k,v]=l.useState(!1),[b,D]=l.useState(null),[U,T]=l.useState(!1),[F,j]=l.useState(!1);l.useEffect(()=>{c()},[c]),l.useEffect(()=>{o&&(g[o]||f(o))},[o,g,f]);const P=l.useMemo(()=>o?i[o]||[]:[],[i,o]),O=l.useMemo(()=>{const w=E.trim().toLowerCase();return w?P.filter(H=>{const Q=H.skillName.toLowerCase(),z=(H.description||"").toLowerCase(),L=(H.frontmatterName||"").toLowerCase();return Q.includes(w)||z.includes(w)||L.includes(w)}):P},[P,E]),R=l.useMemo(()=>r.find(w=>w.id===o)||null,[r,o]),V=!!(o&&o.startsWith("custom:")),B=R?.source==="clawdhub:registry"||R?.sourceType==="clawdhub",ee=!!(o&&(h[o]??!0)),Y=async()=>{if(!(!o||!V)){T(!0);try{const w=await Ph(),Q=(Array.isArray(w?.skillCatalogs)?w?.skillCatalogs:[]).filter(z=>z.id!==o);await Ct({skillCatalogs:Q}),await c({refresh:!0}),j(!1)}finally{T(!1)}}};return t.jsx(qt,{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(jn,{items:[{id:"manual",label:a("settings.skills.catalog.page.mode.manual")},{id:"external",label:a("settings.skills.catalog.page.mode.external")}],activeId:s,onSelect:w=>e(w),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(Tt,{value:o||"",onValueChange:w=>d(w),children:[t.jsx(Ft,{className:"w-fit",children:t.jsx(zt,{placeholder:a("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:R?.label})}),t.jsx(Lt,{align:"start",children:r.map(w=>t.jsx(ht,{value:w.id,children:w.label},w.id))})]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{o?f(o,{refresh:!0}):c({refresh:!0})},disabled:p||m,title:a("settings.skills.catalog.page.actions.refreshTitle"),children:t.jsx(A,{name:"refresh",className:le("h-3.5 w-3.5",(p||m)&&"animate-spin")})}),V&&t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>j(!0),disabled:U,title:a("settings.skills.catalog.page.actions.removeCatalogTitle"),children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})}),t.jsxs(J,{"data-settings-item":"skills.catalog.add-catalog",size:"xs",className:"!font-normal gap-1",onClick:()=>M(!0),children:[t.jsx(A,{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(A,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),t.jsx(tt,{value:E,onChange:w=>S(w.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:O.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:O.length===0&&!m?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")})]}):m?t.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[t.jsx(A,{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:O.map(w=>{const H=w.installed?.isInstalled,Q=w.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:w.skillName}),H&&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:Q||a("settings.skills.catalog.page.badge.unknown")})}),!w.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")})]}),w.description?t.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:w.description}):t.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:a("settings.skills.catalog.shared.noDescription")}),w.clawdhub&&t.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[w.clawdhub.owner&&t.jsxs("span",{children:[a("settings.skills.catalog.page.byOwnerPrefix")," ",t.jsx("span",{className:"font-medium text-foreground/80",children:w.clawdhub.owner})]}),t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(A,{name:"download",className:"h-3 w-3"}),w.clawdhub.downloads?.toLocaleString()??0]}),(w.clawdhub.stars??0)>0&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(A,{name:"star",className:"h-3 w-3"}),w.clawdhub.stars]}),t.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",w.clawdhub.version]})]}),w.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:w.warnings.join(" · ")}):null]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!w.installable,onClick:()=>{D(w),v(!0)},children:a("settings.skills.catalog.shared.actions.install")})]})},`${w.sourceId}:${w.skillDir}`)})})}),B&&ee&&!m&&O.length>0&&t.jsx("div",{className:"flex justify-center mt-2 px-2",children:t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{u()},disabled:I,children:a(I?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),t.jsx(mh,{open:C,onOpenChange:M}),t.jsx(jh,{open:k,onOpenChange:v,item:b}),t.jsx(Kt,{open:F,onOpenChange:w=>{U||j(w)},children:t.jsxs(Ut,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:a("settings.skills.catalog.page.removeDialog.title")}),t.jsx(Ht,{children:a("settings.skills.catalog.page.removeDialog.description")})]}),t.jsxs(Zt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>j(!1),disabled:U,children:a("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",variant:"destructive",onClick:()=>{Y()},disabled:U,children:a("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})};function Po(s,e){const n=s.metadata.variant==="dark",a=s.config?.fonts?.mono||"monospace",r=s.colors.syntax.highlights||{},i=s.colors.syntax.tokens||{},o=Fs.theme({"&":{backgroundColor:"var(--background)",color:s.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:a,backgroundColor:"var(--background)"},".cm-comment":{color:s.colors.syntax.base.comment},".cm-keyword":{color:s.colors.syntax.base.keyword},".cm-string":{color:s.colors.syntax.base.string},".cm-string-2":{color:i.stringEscape||s.colors.syntax.base.string},".cm-number":{color:s.colors.syntax.base.number},".cm-operator":{color:s.colors.syntax.base.operator},".cm-punctuation":{color:i.punctuation||s.colors.syntax.base.comment},".cm-atom":{color:i.boolean||s.colors.syntax.base.number},".cm-builtin":{color:i.functionCall||s.colors.syntax.base.function},".cm-def":{color:i.variableGlobal||s.colors.syntax.base.variable},".cm-attribute":{color:i.variableOther||i.variableProperty||s.colors.syntax.base.operator},".cm-meta":{color:s.colors.syntax.base.comment},".cm-property":{color:i.variableProperty||s.colors.syntax.base.keyword},".cm-variable":{color:s.colors.syntax.base.variable},".cm-variable-2":{color:i.variableOther||s.colors.syntax.base.function},".cm-variable-3":{color:i.variableGlobal||s.colors.syntax.base.type},".cm-tag":{color:i.tag||s.colors.syntax.base.keyword},".cm-link":{color:i.url||s.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:s.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:s.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:s.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||s.colors.syntax.base.comment,borderRight:`1px solid ${s.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||s.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:s.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:s.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${s.colors.interactive.border}`,backgroundColor:s.colors.surface.elevated,color:s.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${s.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${s.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${s.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:s.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${s.colors.interactive.border}`,backgroundColor:s.colors.surface.background,color:s.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:s.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:s.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:s.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:s.colors.interactive.hover,borderColor:s.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:s.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:s.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:s.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:s.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:s.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:s.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:s.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:s.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${s.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:s.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:s.colors.interactive.hover,color:s.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:s.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${s.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:s.colors.interactive.selection,color:s.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${s.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:n}),d=di.define([{tag:[Te.comment,Te.docComment,Te.meta,Te.documentMeta],class:"cm-comment"},{tag:[Te.keyword,Te.controlKeyword,Te.moduleKeyword,Te.definitionKeyword,Te.modifier],class:"cm-keyword"},{tag:[Te.operatorKeyword,Te.operator,Te.derefOperator,Te.updateOperator,Te.definitionOperator,Te.typeOperator,Te.controlOperator,Te.logicOperator,Te.bitwiseOperator,Te.arithmeticOperator,Te.compareOperator],class:"cm-operator"},{tag:[Te.punctuation,Te.separator,Te.bracket,Te.paren,Te.brace,Te.squareBracket,Te.angleBracket],class:"cm-punctuation"},{tag:[Te.string,Te.regexp,Te.attributeValue,Te.special(Te.string),Te.monospace],class:"cm-string"},{tag:Te.escape,class:"cm-string-2"},{tag:[Te.number,Te.bool,Te.atom,Te.null,Te.self],class:"cm-number"},{tag:[Te.function(Te.variableName),Te.function(Te.definition(Te.variableName)),Te.function(Te.propertyName),Te.standard(Te.variableName),Te.special(Te.variableName)],class:"cm-builtin"},{tag:Te.definition(Te.variableName),class:"cm-def"},{tag:[Te.variableName,Te.local(Te.variableName),Te.constant(Te.variableName),Te.literal],class:"cm-variable"},{tag:Te.propertyName,class:"cm-property"},{tag:Te.attributeName,class:"cm-attribute"},{tag:[Te.className,Te.typeName,Te.namespace],class:"cm-variable-3"},{tag:[Te.tagName,Te.labelName,Te.annotation,Te.macroName],class:"cm-tag"},{tag:Te.link,class:"cm-link"},{tag:[Te.heading,Te.heading1,Te.heading2,Te.heading3,Te.heading4,Te.heading5,Te.heading6],class:"cm-keyword"}]),c=di.define([{tag:[Te.comment,Te.docComment,Te.meta,Te.documentMeta],color:s.colors.syntax.base.comment},{tag:[Te.keyword,Te.controlKeyword,Te.moduleKeyword,Te.definitionKeyword,Te.modifier],color:s.colors.syntax.base.keyword},{tag:[Te.operatorKeyword,Te.operator,Te.derefOperator,Te.updateOperator,Te.definitionOperator,Te.typeOperator,Te.controlOperator,Te.logicOperator,Te.bitwiseOperator,Te.arithmeticOperator,Te.compareOperator],color:s.colors.syntax.base.operator},{tag:[Te.string,Te.regexp,Te.attributeValue,Te.special(Te.string),Te.monospace],color:s.colors.syntax.base.string},{tag:Te.escape,color:i.stringEscape||s.colors.syntax.base.string},{tag:[Te.number,Te.bool,Te.atom,Te.null,Te.self],color:s.colors.syntax.base.number},{tag:[Te.function(Te.variableName),Te.function(Te.definition(Te.variableName)),Te.function(Te.propertyName),Te.standard(Te.variableName),Te.special(Te.variableName)],color:s.colors.syntax.base.function},{tag:Te.definition(Te.variableName),color:i.variableGlobal||s.colors.syntax.base.variable},{tag:[Te.variableName,Te.local(Te.variableName),Te.constant(Te.variableName),Te.literal],color:s.colors.syntax.base.variable},{tag:Te.propertyName,color:i.variableProperty||s.colors.syntax.base.variable},{tag:Te.attributeName,color:i.variableOther||s.colors.syntax.base.variable},{tag:[Te.className,Te.typeName,Te.namespace],color:s.colors.syntax.base.type},{tag:[Te.tagName,Te.labelName,Te.annotation,Te.macroName],color:i.tag||s.colors.syntax.base.keyword},{tag:Te.link,color:i.url||s.colors.syntax.base.function,textDecoration:"underline"},{tag:[Te.punctuation,Te.separator,Te.bracket,Te.paren,Te.brace,Te.squareBracket,Te.angleBracket],color:i.punctuation||s.colors.syntax.base.comment}]);return e?.syntaxColors===!1?[o]:[o,ra(ld,{fallback:!0}),ra(cd),ra(d),ra(c)]}const Dh=180,Gl=dd.define(),Ah=1,Eh=2,Mh=4,Io=new Map,Rh=(s,e)=>{const n=`${s}|${e}`,a=Io.get(n);if(a)return a;let r="";s&&(r+=`color:${s};`),e&Ah&&(r+="font-style:italic;"),e&Eh&&(r+="font-weight:bold;"),e&Mh&&(r+="text-decoration:underline;");const i=Ka.mark({attributes:{style:r}});return Io.set(n,i),i},Th=(s,e)=>{const n=new Qr,a=s.state.doc,r=Math.min(e.length,a.lines);for(let i=0;i<r;i+=1){const o=e[i];if(!o||o.length===0)continue;const d=a.line(i+1);let c=d.from;for(const[f,u,p]of o){if(f<=0)continue;const m=c,I=Math.min(c+f,d.to);c+=f,!(I<=m)&&(!u&&!p||n.add(m,I,Rh(u,p)))}}return n.finish()},Fh=wl.define({create(){return Ka.none},update(s,e){let n=s.map(e.changes);for(const a of e.effects)a.is(Gl)&&(n=a.value);return n},provide:s=>Fs.decorations.from(s)}),Lh=s=>jl.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)},Dh)}async tokenize(e){const n=++this.generation,a=e.state.doc.toString(),r=await $d(a,s.language,s.themeName,s.theme);r&&n===this.generation&&e.state.doc.length===a.length&&e.dispatch({effects:Gl.of(Th(e,r))})}destroy(){this.timer&&clearTimeout(this.timer)}}),Oh=s=>[Fh,Lh(s)],zh=()=>{const s=st.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Ih,{mode:"external",onModeChange:_h,showModeTabs:!1}),s[0]=e):e=s[0],e},Kh="SKILL.md",Uh="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",Aa=(s,e)=>{const n=md({description:s}).trimEnd(),a=e.trimStart();return`---
|
|
23
|
-
${n}
|
|
24
|
-
---${a?`
|
|
25
|
-
|
|
26
|
-
${a}`:`
|
|
27
|
-
`}`},$h=s=>typeof s=="object"&&s!==null&&!Array.isArray(s),Jl=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=ud(e[1]);if($h(a)){const r=a.description;typeof r=="string"&&(n=r)}}catch{n=null}return{description:n,instructions:e[2].replace(/^\r?\n/,"")}},Bh=(s,e)=>{const n=Jl(s);return Aa(e,n.instructions)},Vh=()=>{const{t:s}=ot(),{currentTheme:e}=Va(),{selectedSkillName:n,getSkillByName:a,getSkillDetail:r,createSkill:i,updateSkill:o,skills:d,skillDraft:c,setSkillDraft:f,setSelectedSkill:u}=Hs(Ps(ce=>({selectedSkillName:ce.selectedSkillName,getSkillByName:ce.getSkillByName,getSkillDetail:ce.getSkillDetail,createSkill:ce.createSkill,updateSkill:ce.updateSkill,skills:ce.skills,skillDraft:ce.skillDraft,setSkillDraft:ce.setSkillDraft,setSelectedSkill:ce.setSelectedSkill}))),p=n?a(n):null,m=!!(c&&c.name===n&&!p),I=!!(n&&!p&&!c),g=p?.path==="<built-in>";l.useEffect(()=>{I&&u(null)},[I,u]);const[h,x]=l.useState(""),[E,S]=l.useState("user"),[C,M]=l.useState("opencode"),[k,v]=l.useState(""),[b,D]=l.useState(""),[U,T]=l.useState(()=>Aa("","")),[F,j]=l.useState("edit"),[P,O]=l.useState([]),[R,V]=l.useState([]),[B,ee]=l.useState(!1),[Y,w]=l.useState(!1),[H,Q]=l.useState(""),[z,L]=l.useState(""),[X,$]=l.useState(!1),[ne,re]=l.useState(""),[_,oe]=l.useState(""),[fe,xe]=l.useState(null),[Ce,ve]=l.useState(!1),[we,ye]=l.useState(""),[se,de]=l.useState(null),[be,W]=l.useState(!1),te=m?h.trim()!==""||k.trim()!==""||b.trim()!==""||R.length>0:k!==H||b!==z,ae=fe?_!==we:ne.trim()!=="",me=l.useCallback(ce=>{switch(ce){case"project-opencode":return s("settings.skills.location.option.projectOpencode.label");case"user-claude":return s("settings.skills.location.option.userClaude.label");case"project-claude":return s("settings.skills.location.option.projectClaude.label");case"user-agents":return s("settings.skills.location.option.userAgents.label");case"project-agents":return s("settings.skills.location.option.projectAgents.label");default:return s("settings.skills.location.option.userOpencode.label")}},[s]),Me=l.useCallback(ce=>{switch(ce){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]);l.useEffect(()=>{(async()=>{if(m&&c){const G=c.description||"",pe=c.instructions||"";x(c.name||""),S(c.scope||"user"),M(c.source==="agents"?"agents":"opencode"),v(G),D(pe),T(Aa(G,pe)),Q(""),L(""),O([]),V(c.pendingFiles||[])}else if(n&&p){w(!0);try{const G=await r(n);if(G){const pe=G.sources.md,je=pe.description||"",Ee=pe.instructions||"";v(je),D(Ee),T(Aa(je,Ee)),Q(je),L(Ee),O(pe.supportingFiles||[])}}catch(G){console.error("Failed to load skill details:",G)}finally{w(!1)}}})()},[p,m,n,d,c,r]);const Ne=l.useMemo(()=>{const ce=[Po(e)],G=ui(Kh);return G&&ce.push(G),ce.push(Fs.lineWrapping),ce},[e]),De=l.useMemo(()=>{const ce=ne.trim()||"supporting-file.md",G=Bd(ce),pe=!!G&&G!=="markdown",je=[Po(e,pe?{syntaxColors:!1}:void 0)],Ee=ui(ce);return Ee&&je.push(Ee),pe&&G&&je.push(Oh({language:G,themeName:e.metadata.id,theme:Ir(e)})),je.push(Fs.lineWrapping),je},[e,ne]),Ae=l.useCallback(ce=>{v(ce),T(G=>Bh(G,ce))},[]),Pe=l.useCallback(ce=>{T(ce);const G=Jl(ce);v(G.description??""),D(G.instructions)},[]),Re=async()=>{const ce=m?h.trim().replace(/\s+/g,"-").toLowerCase():n?.trim();if(!ce){q.error(s("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ce)||ce.length>64){q.error(s("settings.skills.page.toast.invalidSkillName"));return}if(!k.trim()){q.error(s("settings.skills.page.toast.descriptionRequired"));return}if(m&&d.some(G=>G.name===ce)){q.error(s("settings.skills.page.toast.skillExists"));return}ee(!0);try{const G={name:ce,description:k.trim(),instructions:b.trim()||void 0,scope:m?E:void 0,source:m?C:void 0,targetPath:m?void 0:p?.path,supportingFiles:m&&R.length>0?R:void 0};let pe;m?(pe=await i(G),pe&&(f(null),V([]),u(ce))):(pe=await o(ce,G),pe&&(Q(k.trim()),L(b.trim()))),pe?q.success(s(m?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):q.error(s(m?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(G){console.error("Error saving skill:",G),q.error(s("settings.skills.page.toast.saveUnexpectedError"))}finally{ee(!1)}},Fe=()=>{xe(null),re(""),oe(""),ye(""),$(!0)},Ue=async ce=>{if(xe(ce),re(ce),m){const pe=R.find(je=>je.path===ce)?.content||"";oe(pe),ye(pe),$(!0);return}if(n){ve(!0),$(!0);try{const{readSupportingFile:G}=Hs.getState(),pe=await G(n,ce);oe(pe||""),ye(pe||"")}catch{q.error(s("settings.skills.page.toast.loadFileContentFailed")),oe(""),ye("")}finally{ve(!1)}}},_e=async()=>{if(!ne.trim()){q.error(s("settings.skills.page.toast.fileNameRequired"));return}const ce=ne.trim(),G=fe!==null;if(m){if(G)V(Ee=>Ee.map(Se=>Se.path===fe?{path:ce,content:_}:Se)),q.success(s("settings.skills.page.toast.fileUpdated",{path:ce}));else{if(R.some(Ee=>Ee.path===ce)){q.error(s("settings.skills.page.toast.fileExists"));return}V(Ee=>[...Ee,{path:ce,content:_}]),q.success(s("settings.skills.page.toast.fileAdded",{path:ce}))}$(!1),xe(null);return}if(!n){q.error(s("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:pe}=Hs.getState();if(await pe(n,ce,_)){q.success(G?s("settings.skills.page.toast.fileUpdated",{path:ce}):s("settings.skills.page.toast.fileCreated",{path:ce})),$(!1),xe(null);const Ee=await r(n);Ee&&O(Ee.sources.md.supportingFiles||[])}else q.error(s(G?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ke=ce=>{if(m){V(G=>G.filter(pe=>pe.path!==ce)),q.success(s("settings.skills.page.toast.fileRemoved",{path:ce}));return}n&&de(ce)},qe=async()=>{if(!se||!n)return;W(!0);const{deleteSupportingFile:ce}=Hs.getState();if(await ce(n,se)){q.success(s("settings.skills.page.toast.fileDeleted",{path:se}));const pe=await r(n);pe&&O(pe.sources.md.supportingFiles||[]),de(null)}else q.error(s("settings.skills.page.toast.deleteFileFailed"));W(!1)};return!n&&!c||I?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(A,{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(qt,{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:m?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:me(ea(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:[m&&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(tt,{value:h,onChange:ce=>x(ce.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:s("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),t.jsxs(Tt,{value:ea(E,C),onValueChange:ce=>{const G=ql(ce);S(G.scope),M(G.source==="agents"?"agents":"opencode")},children:[t.jsxs(Ft,{className:"w-fit gap-1.5",children:[E==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),C==="agents"?t.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:me(ea(E,C))})]}),t.jsx(Lt,{align:"start",children:ei.map(ce=>t.jsx(ht,{value:ce.value,children:t.jsxs("div",{className:"flex flex-col gap-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[ce.scope==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),ce.source==="agents"?t.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:me(ce.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Me(ce.value)})]})},ce.value))})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsxs("span",{className:"typography-ui-label text-foreground",children:[s("settings.common.field.description")," ",t.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:s("settings.skills.page.field.descriptionHint")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(hs,{value:k,onChange:ce=>Ae(ce.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(oh,{currentMode:F==="preview"?"preview":"edit",onToggle:()=>j(ce=>ce==="preview"?"edit":"preview")})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx("div",{className:le("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Uh),children:F==="preview"?t.jsx(qt,{outerClassName:"h-full",className:"h-full",children:t.jsx("div",{className:"min-h-full px-4 py-3",children:t.jsx(Pr,{content:U,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):t.jsx(Co,{value:U,onChange:Pe,readOnly:g,extensions:Ne,className:"h-full",enableSearch:!0})})})]}),t.jsxs("div",{"data-settings-item":"skills.supporting-files",className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.skills.page.section.supportingFiles")}),t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Fe,disabled:g,children:[t.jsx(A,{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 ce=m?R:P;return ce.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:ce.map(G=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Ue(G.path),children:[t.jsx(A,{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:G.path}),m&&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(J,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:pe=>{pe.stopPropagation(),Ke(G.path)},children:t.jsx(A,{name:"delete-bin",className:"h-3 w-3"})})]},G.path))})})()})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:Re,disabled:g||B||!te,size:"xs",className:"!font-normal",children:s(B?"settings.common.actions.saving":m?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),t.jsx(Kt,{open:se!==null,onOpenChange:ce=>{!ce&&!be&&de(null)},children:t.jsxs(Ut,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("settings.skills.page.deleteFileDialog.title")}),t.jsx(Ht,{children:s("settings.skills.page.deleteFileDialog.description",{path:se??""})})]}),t.jsxs(Zt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>de(null),disabled:be,children:s("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",variant:"destructive",onClick:qe,disabled:be,children:s("settings.common.actions.delete")})]})]})}),t.jsx(Kt,{open:X,onOpenChange:ce=>{$(ce),ce||xe(null)},children:t.jsxs(Ut,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[t.jsxs(Bt,{className:"flex-shrink-0",children:[t.jsx($t,{children:s(fe?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),t.jsx(Ht,{children:s(fe?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),Ce?t.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.skills.page.loading.fileContent")})}):t.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[t.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:s("settings.skills.page.fileDialog.field.filePath")}),t.jsx(tt,{value:ne,onChange:ce=>re(ce.target.value),placeholder:s("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:fe!==null}),!fe&&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(Co,{value:_,onChange:oe,extensions:De,className:"h-full",enableSearch:!0})})]})]}),t.jsxs(Zt,{className:"mt-4",children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>{$(!1),xe(null)},children:s("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:_e,disabled:Ce||!ae,children:s(fe?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},Do=s=>{const e=st.c(2),{view:n}=s,a=n===void 0?"installed":n;let r;return e[0]!==a?(r=a==="catalog"?t.jsx(zh,{}):t.jsx(Vh,{}),e[0]=a,e[1]=r):r=e[1],r};function _h(){}const Hh=s=>{const e=st.c(38),{onItemSelect:n}=s,{t:a}=ot(),r=os(Wh),i=Le(qh),o=Le(Gh),{currentTheme:d}=Va();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=fs(),e[0]=c):c=e[0];const f=c,u=Jh;let p,m;e[1]!==r||e[2]!==i||e[3]!==o?(p=()=>{if(r.length===0){i!==null&&o(null);return}i&&r.some(b=>b.id===i)||o(r[0].id)},m=[r,i,o],e[1]=r,e[2]=i,e[3]=o,e[4]=p,e[5]=m):(p=e[4],m=e[5]),l.useEffect(p,m);let I;e[6]===Symbol.for("react.memo_cache_sentinel")?(I=le("border-b px-3","pt-4 pb-3"),e[6]=I):I=e[6];let g;e[7]!==a?(g=a("settings.page.projects.title"),e[7]=a,e[8]=g):g=e[8];let h;e[9]!==g?(h=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[9]=g,e[10]=h):h=e[10];let x;e[11]!==r.length||e[12]!==a?(x=a("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=a,e[13]=x):x=e[13];let E;e[14]!==x?(E=t.jsx("span",{className:"typography-meta text-muted-foreground",children:x}),e[14]=x,e[15]=E):E=e[15];let S;e[16]!==a?(S=!f&&t.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:u,"aria-label":a("settings.projects.sidebar.actions.addProject"),children:t.jsx(A,{name:"add",className:"size-4"})}),e[16]=a,e[17]=S):S=e[17];let C;e[18]!==E||e[19]!==S?(C=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[E,S]}),e[18]=E,e[19]=S,e[20]=C):C=e[20];let M;e[21]!==C||e[22]!==h?(M=t.jsxs("div",{className:I,children:[h,C]}),e[21]=C,e[22]=h,e[23]=M):M=e[23];let k;if(e[24]!==d||e[25]!==n||e[26]!==r||e[27]!==i||e[28]!==o){let b;e[30]!==d||e[31]!==n||e[32]!==i||e[33]!==o?(b=D=>{const U=D.id===i,T=D.icon?Vd[D.icon]:null,F=D.color?Il[D.color]??null:null,j=T?t.jsx(A,{name:T,className:le("h-4 w-4",U?"text-foreground":"text-muted-foreground/70"),style:F?{color:F}:void 0}):t.jsx(A,{name:"folder",className:le("h-4 w-4",U?"text-foreground":"text-muted-foreground/70"),style:F?{color:F}:void 0}),P=D.iconImage?t.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:D.iconBackground?{backgroundColor:D.iconBackground}:void 0,children:t.jsx(Dl,{project:D,options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:j})}):j;return t.jsx(Ur,{title:D.label||D.path,icon:P,selected:U,onSelect:()=>{o(D.id),n?.()}},D.id)},e[30]=d,e[31]=n,e[32]=i,e[33]=o,e[34]=b):b=e[34],k=r.map(b),e[24]=d,e[25]=n,e[26]=r,e[27]=i,e[28]=o,e[29]=k}else k=e[29];let v;return e[35]!==M||e[36]!==k?(v=t.jsx(Hl,{variant:"background",header:M,children:k}),e[35]=M,e[36]=k,e[37]=v):v=e[37],v};function Wh(s){return s.projects}function qh(s){return s.settingsProjectsSelectedId}function Gh(s){return s.setSettingsProjectsSelectedId}function Jh(){Pl.requestDirectoryDialog()}const Qh=({projectRef:s=null})=>{const{t:e}=ot(),{isMobile:n,isTablet:a}=Is(),r=n||a,i=os(V=>V.getActiveProject()),o=s?.path??i?.path??null,d=ks(V=>V.getWorktreeMetadata),c=_d(),f=ys(V=>V.homeDirectory),[u,p]=l.useState([]),[m,I]=l.useState(!1),[g,h]=l.useState(!1),[x,E]=l.useState(null),[S,C]=l.useState([]),[M,k]=l.useState(!1),v=l.useMemo(()=>s?.id&&s?.path?{id:s.id,path:s.path}:!i?.id||!o?null:{id:i.id,path:o},[i?.id,o,s?.id,s?.path]),b=l.useCallback(async()=>{if(!(!v||x===!1))try{const V=await pi(v);C(V)}catch{}},[v,x]);l.useEffect(()=>{if(!o)return;let V=!1;return E(null),(async()=>{try{const B=await Hd(o);if(V)return;E(B)}catch{}})(),()=>{V=!0}},[o]),l.useEffect(()=>{if(!v){C([]),k(!1);return}if(x===!1){C([]),k(!1);return}let V=!1;return k(!0),C([]),(async()=>{try{const B=await pi(v);if(V)return;C(B)}catch{}finally{V||k(!1)}})(),()=>{V=!0}},[v,x]),l.useEffect(()=>{if(!v)return;let V=!1;return h(!0),(async()=>{try{const[B,ee]=await Promise.all([Al(v),El(v)]);V||(p(B.length>0?B:[""]),I(ee))}catch{V||(p([""]),I(!1))}finally{V||h(!1)}})(),()=>{V=!0}},[v]);const D=l.useCallback((V,B)=>{p(ee=>{const Y=[...ee];return Y[V]=B,Y})},[]),U=l.useCallback(()=>{p(V=>[...V,""])},[]),T=l.useCallback(async V=>{if(!v)return;const B=V.filter(ee=>ee.trim().length>0);await Wd(v,B)},[v]),F=l.useCallback(V=>{p(B=>{const ee=B.filter((Y,w)=>w!==V);return T(ee),ee.length>0?ee:[""]})},[T]),j=l.useCallback(()=>{T(u)},[T,u]),P=l.useCallback(V=>{I(V),v&&qd(v,V)},[v]),O=l.useCallback(V=>{const B=$=>$.replace(/\\/g,"/").replace(/\/+$/,""),ee=B(V.path),Y=c.filter($=>{const ne=d($.id);if(ne?.path&&B(ne.path)===ee)return!0;const re=$.directory;return!!(re&&B(re)===ee)}),w=new Set(Y.map($=>$.id)),H=[...Dr.getState().activeSessions,...Dr.getState().archivedSessions],Q=$=>{const ne=H.filter(_=>{const oe=_.parentID;return oe&&$.has(oe)});if(ne.length===0)return[];const re=new Set(ne.map(_=>_.id));return[...ne,...Q(re)]},z=Q(w),L=new Set,X=[...Y,...z].filter($=>L.has($.id)?!1:(L.add($.id),!0));Pl.requestDelete({sessions:X,mode:"worktree",worktree:V})},[c,d]),R=l.useMemo(()=>c.map(V=>V.id).join(","),[c]);return l.useEffect(()=>{x&&o&&b()},[R,x,o,b]),o?x===!1?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")}):t.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[t.jsxs("div",{className:"space-y-2",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-normal text-foreground",children:e("settings.openchamber.worktrees.setup.title")}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(At,{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")]})]})]})}),g?t.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.setup.loading")}):t.jsxs("div",{className:"space-y-2 px-1",children:[u.map((V,B)=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(tt,{value:V,onChange:ee=>D(B,ee.target.value),onBlur:j,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 w-[30rem] max-w-full font-mono text-xs"}),t.jsx("button",{type:"button",onClick:()=>{F(B)},className:"flex-shrink-0 flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:t.jsx(A,{name:"close",className:"h-4 w-4"})})]},B)),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:U,children:[t.jsx(A,{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.5",children:[t.jsx(St,{checked:m,onChange:P,ariaLabel:e("settings.openchamber.worktrees.setup.waitForCommandsAria")}),t.jsx("span",{className:le("typography-ui-label font-normal",m?"text-foreground":"text-foreground/60"),children:e("settings.openchamber.worktrees.setup.waitForCommands")})]})]})]}),t.jsxs("div",{className:"space-y-2 border-t border-border/40 pt-4",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-normal text-foreground",children:e("settings.openchamber.worktrees.list.title")}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]})]})}),M?t.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.list.loading")}):S.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.openchamber.worktrees.list.empty")}):t.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:S.map(V=>t.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx("p",{className:"typography-meta text-foreground truncate min-w-0",children:V.label||V.branch||e("settings.openchamber.worktrees.list.detachedHead")}),t.jsx("span",{className:"typography-micro text-muted-foreground/60 px-1.5 py-[1px] rounded bg-sidebar-accent/40 flex-shrink-0 self-center leading-none",children:"OpenCode"})]}),t.jsx("p",{className:"typography-micro text-muted-foreground/60 truncate",children:Gd(V.path,f)})]}),t.jsx("button",{type:"button",onClick:()=>O(V),className:le("flex-shrink-0 flex h-7 w-7 items-center justify-center rounded text-muted-foreground/50 hover:text-destructive hover:bg-destructive/10 transition-opacity 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:V.branch||V.label||V.path}),children:t.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})]},V.path))})]})]}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},Ao=(s,e)=>e.updatedAtMs-s.updatedAtMs,ms=ln((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([Xd(),hi()]),r={};for(const i of a.sort(Ao))r[i.id]=i;e().listenerReady||await Zd(i=>{s(o=>({statusesById:{...o.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 Yd();s({importCandidates:n,isImportsLoading:!1})}catch(n){s({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await hi(),a={};for(const r of n.sort(Ao))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 Qd({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=em(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 Jd(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})})),Ql=[{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"}],Yh=Object.fromEntries(Ql.map(s=>[s.key,s.Icon])),Xh="openchamber:project-actions-updated",Zh=s=>{const e=(s||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},qv=(s,e)=>`${Zh(s)}::${e}`,ef=s=>{const e=s.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Eo=s=>{if(typeof s!="number"||!Number.isFinite(s))return null;const e=Math.round(s);return e<1||e>65535?null:e},tf=(s,e)=>{if(!e.enabled||e.type!=="local")return null;const n=Eo(e.localPort),a=Eo(e.remotePort);if(!n||!a)return null;const r=ef(e.localHost||s.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),o=(s.nickname||s.id||"instance").trim();return{id:`${s.id}::${e.id}`,label:`${o} - ${r}:${n} -> ${i}:${a}`,url:`http://${r}:${n}`}},Yl=s=>{const e=[];for(const n of s)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const a of n.portForwards){const r=tf(n,a);r&&e.push(r)}return e},Gv=(s,e)=>{const n=(s||"").trim();return n&&Yl(e).find(i=>i.id===n)?.url||null},sf=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,nf=()=>({id:sf(),name:"",command:"",icon:"play"}),af=({projectRef:s})=>{const{t:e}=ot(),n=l.useMemo(()=>ls(),[]),a=ms(b=>b.instances),r=ms(b=>b.load),[i,o]=l.useState([]),[d,c]=l.useState(!1),[f,u]=l.useState(!1),[p,m]=l.useState(null),[I,g]=l.useState({});l.useEffect(()=>{n&&r().catch(()=>{})},[n,r]),l.useEffect(()=>{let b=!1;return c(!0),(async()=>{try{const D=await tm(s);if(b)return;o(D.actions),m(JSON.stringify({actions:D.actions}))}catch{if(b)return;o([]),m(JSON.stringify({actions:[]}))}finally{b||c(!1)}})(),()=>{b=!0}},[s]);const h=l.useMemo(()=>n?Yl(a):[],[a,n]),x=l.useMemo(()=>i.some(D=>D.name.trim().length===0||D.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),E=l.useMemo(()=>p===null?!1:p!==JSON.stringify({actions:i}),[i,p]),S=l.useCallback(()=>{const b=nf();o(D=>[...D,b]),g(D=>({...D,[b.id]:!0}))},[]),C=l.useCallback(b=>{o(D=>D.filter(U=>U.id!==b)),g(D=>{const U={...D};return delete U[b],U})},[]),M=l.useCallback((b,D)=>{o(U=>U.map(T=>T.id===b?D(T):T))},[]),k=l.useCallback(async()=>{if(x){q.error(x);return}u(!0);try{if(!await sm(s,{actions:i,primaryActionId:null})){q.error(e("settings.projects.actions.toast.saveFailed"));return}m(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Xh,{detail:{projectId:s.id}})),q.success(e("settings.projects.actions.toast.saved"))}catch{q.error(e("settings.projects.actions.toast.saveFailed"))}finally{u(!1)}},[i,s,e,x]),v=!f&&!d&&E&&!x;return t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:S,children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]})]}),t.jsxs("section",{className:"pb-2 pt-0 space-y-2",children:[d?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):i.length===0?t.jsx("div",{className:"py-2",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")})}):t.jsx("div",{className:"space-y-0 max-w-[30rem]",children:i.map(b=>{const D=b.icon||"play",U=Yh[D]||"play",T=I[b.id]??!1,F=b.name.trim()||e("settings.projects.actions.state.untitled");return t.jsxs(bn,{open:T,onOpenChange:j=>{g(P=>({...P,[b.id]:j}))},className:le("py-1.5"),children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs(yn,{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:[T?t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):t.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),t.jsx(A,{name:U,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("div",{className:"flex items-center gap-2",children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:F})})})]}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>C(b.id),children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(vn,{className:"pt-1.5",children:t.jsxs("div",{className:"space-y-2 pb-6 pl-3 pr-3",children:[t.jsxs("div",{className:"flex items-center gap-2 py-1",children:[t.jsxs(gs,{children:[t.jsx(us,{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(A,{name:U,className:"h-4 w-4"})})}),t.jsx(ps,{align:"start",className:"w-56 p-2",children:t.jsx("div",{className:"grid grid-cols-6 gap-1",children:Ql.map(j=>{const P=j.Icon,O=(b.icon||"play")===j.key;return t.jsx("button",{type:"button",onClick:()=>M(b.id,R=>({...R,icon:j.key})),className:le("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",O&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:j.label}),children:t.jsx(A,{name:P,className:"h-4 w-4"})},j.key)})})})]}),t.jsx(tt,{value:b.name,onChange:j=>M(b.id,P=>({...P,name:j.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),t.jsxs("div",{className:"py-1",children:[t.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),t.jsx(hs,{value:b.command,onChange:j=>M(b.id,P=>({...P,command:j.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] 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:()=>M(b.id,j=>({...j,...j.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:j=>{(j.key===" "||j.key==="Enter")&&(j.preventDefault(),M(b.id,P=>({...P,...P.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[t.jsx(St,{checked:b.autoOpenUrl===!0,onChange:j=>M(b.id,P=>({...P,...j?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:F})}),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(tt,{value:b.openUrl||"",onChange:j=>M(b.id,P=>({...P,openUrl:j.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]})]}),n?t.jsxs("div",{className:"mt-2",children:[t.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),h.length>0?t.jsxs(Tt,{value:b.desktopOpenSshForward&&h.some(j=>j.id===b.desktopOpenSshForward)?b.desktopOpenSshForward:"__none__",onValueChange:j=>{M(b.id,P=>({...P,...j==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:j}}))},children:[t.jsx(Ft,{className:"h-7 w-full max-w-[30rem]",children:t.jsx(zt,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),h.map(j=>t.jsx(ht,{value:j.id,children:j.label},j.id))]})]}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},b.id)})}),t.jsxs("div",{className:"pt-3",children:[x?t.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:x}):null,t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:k,disabled:!v,children:e(f?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},rf=()=>{const s=st.c(197),{t:e}=ot(),n=os(of),a=os(lf),r=os(cf),i=os(df),o=os(mf),d=Le(uf),c=Le(pf),{currentTheme:f}=Va();let u;e:{if(!d){u=null;break e}let Ze;s[0]!==n||s[1]!==d?(Ze=n.find(kt=>kt.id===d)??null,s[0]=n,s[1]=d,s[2]=Ze):Ze=s[2],u=Ze}const p=u;let m,I;s[3]!==n||s[4]!==d||s[5]!==c?(m=()=>{if(n.length===0){c(null);return}d&&n.some(Ze=>Ze.id===d)||c(n[0].id)},I=[n,d,c],s[3]=n,s[4]=d,s[5]=c,s[6]=m,s[7]=I):(m=s[6],I=s[7]),l.useEffect(m,I);const[g,h]=l.useState(""),[x,E]=l.useState(null),[S,C]=l.useState(null),[M,k]=l.useState(null),[v,b]=l.useState(!1),[D,U]=l.useState(!1),[T,F]=l.useState(!1),[j,P]=l.useState(!1),[O,R]=l.useState(null),[V,B]=l.useState(null),[ee,Y]=l.useState(!1),w=l.useRef(null);let H;s[8]===Symbol.for("react.memo_cache_sentinel")?(H=()=>{R(null),B(gf)},s[8]=H):H=s[8];const Q=H;let z;e:{if(!p){z=null;break e}let Ze;s[9]!==p.id||s[10]!==p.path?(Ze={id:p.id,path:p.path},s[9]=p.id,s[10]=p.path,s[11]=Ze):Ze=s[11],z=Ze}const L=z;let X,$;s[12]!==p?(X=()=>{if(!p){h(""),E(null),C(null),k(null);return}h(p.label??""),E(p.icon??null),C(p.color??null),k(p.iconBackground??null),P(!1),Q(),Y(!1)},$=[p,Q],s[12]=p,s[13]=X,s[14]=$):(X=s[13],$=s[14]),l.useEffect(X,$);let ne,re;s[15]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>()=>{Q()},re=[Q],s[15]=ne,s[16]=re):(ne=s[15],re=s[16]),l.useEffect(ne,re);let _;s[17]!==S||s[18]!==x||s[19]!==M||s[20]!==g||s[21]!==j||s[22]!==O||s[23]!==p?(_=!!p&&(g.trim()!==(p?.label??"").trim()||x!==(p?.icon??null)||S!==(p?.color??null)||M!==(p?.iconBackground??null)||j||!!O),s[17]=S,s[18]=x,s[19]=M,s[20]=g,s[21]=j,s[22]=O,s[23]=p,s[24]=_):_=s[24];const oe=_;let fe;s[25]!==S||s[26]!==x||s[27]!==M||s[28]!==g||s[29]!==j||s[30]!==O||s[31]!==i||s[32]!==p||s[33]!==e||s[34]!==a||s[35]!==r?(fe=async()=>{if(!p)return;if(O){b(!0);const kt=await r(p.id,O);if(b(!1),!kt.ok){q.error(kt.error||e("settings.projects.page.toast.uploadIconFailed"));return}q.success(e("settings.projects.page.toast.iconUpdated")),Q(),P(!1)}const Ze=j&&!!p.iconImage;if(Ze){U(!0);const kt=await i(p.id);if(U(!1),!kt.ok){q.error(kt.error||e("settings.projects.page.toast.removeIconFailed"));return}q.success(e("settings.projects.page.toast.iconRemoved")),P(!1),k(null)}a(p.id,{label:g.trim(),icon:x,color:S,iconBackground:Ze?null:M})},s[25]=S,s[26]=x,s[27]=M,s[28]=g,s[29]=j,s[30]=O,s[31]=i,s[32]=p,s[33]=e,s[34]=a,s[35]=r,s[36]=fe):fe=s[36];const xe=fe,Ce=S?Il[S]??null:null,ve=!!p?.iconImage,we=!!(O&&V),ye=p?.iconImage?.source==="custom",se=ve&&!j||we,de=se,W=!ee&&(we||!!(p&&ve&&!j));let te;s[37]!==v||s[38]!==p?(te=Ze=>{!p||!Ze||v||(P(!1),Y(!1),R(Ze),B(kt=>(kt&&URL.revokeObjectURL(kt),URL.createObjectURL(Ze))))},s[37]=v,s[38]=p,s[39]=te):te=s[39];const ae=te;let me;s[40]!==we||s[41]!==de||s[42]!==ve||s[43]!==D||s[44]!==p?(me=()=>{!p||!de||D||(we&&Q(),P(!!ve),Y(!1))},s[40]=we,s[41]=de,s[42]=ve,s[43]=D,s[44]=p,s[45]=me):me=s[45];const Me=me;let Ne;s[46]!==o||s[47]!==T||s[48]!==p||s[49]!==e?(Ne=async()=>{!p||T||(Q(),P(!1),Y(!1),F(!0),o(p.id).then(Ze=>{if(!Ze.ok){q.error(Ze.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(Ze.skipped){q.success(e("settings.projects.page.toast.customIconAlreadySet"));return}q.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{F(!1)}))},s[46]=o,s[47]=T,s[48]=p,s[49]=e,s[50]=Ne):Ne=s[50];const De=Ne;if(!p){let Ze;s[51]!==e?(Ze=e("settings.projects.page.empty.noProjects"),s[51]=e,s[52]=Ze):Ze=s[52];let kt;return s[53]!==Ze?(kt=t.jsx(qt,{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:Ze})})}),s[53]=Ze,s[54]=kt):kt=s[54],kt}let Ae;s[55]!==p.label||s[56]!==e?(Ae=p.label??e("settings.projects.page.title.default"),s[55]=p.label,s[56]=e,s[57]=Ae):Ae=s[57];let Pe;s[58]!==Ae?(Pe=t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:Ae}),s[58]=Ae,s[59]=Pe):Pe=s[59];let Re;s[60]!==p.path?(Re=t.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:p.path,children:p.path}),s[60]=p.path,s[61]=Re):Re=s[61];let Fe;s[62]!==Pe||s[63]!==Re?(Fe=t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[Pe,Re]})}),s[62]=Pe,s[63]=Re,s[64]=Fe):Fe=s[64];let Ue;s[65]!==e?(Ue=e("settings.projects.page.field.projectName"),s[65]=e,s[66]=Ue):Ue=s[66];let _e;s[67]!==Ue?(_e=t.jsx("div",{className:"flex min-w-0 flex-col",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:Ue})}),s[67]=Ue,s[68]=_e):_e=s[68];let Ke;s[69]===Symbol.for("react.memo_cache_sentinel")?(Ke=Ze=>h(Ze.target.value),s[69]=Ke):Ke=s[69];let qe;s[70]!==e?(qe=e("settings.projects.page.field.projectNamePlaceholder"),s[70]=e,s[71]=qe):qe=s[71];let ce;s[72]!==g||s[73]!==qe?(ce=t.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:t.jsx(tt,{value:g,onChange:Ke,placeholder:qe,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),s[72]=g,s[73]=qe,s[74]=ce):ce=s[74];let G;s[75]!==_e||s[76]!==ce?(G=t.jsxs("div",{"data-settings-item":"projects.name",className:"py-1.5",children:[_e,ce]}),s[75]=_e,s[76]=ce,s[77]=G):G=s[77];let pe;s[78]!==e?(pe=e("settings.projects.page.field.accentColor"),s[78]=e,s[79]=pe):pe=s[79];let je;s[80]!==pe?(je=t.jsx("div",{className:"flex min-w-0 flex-col",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:pe})}),s[80]=pe,s[81]=je):je=s[81];let Ee;s[82]===Symbol.for("react.memo_cache_sentinel")?(Ee=()=>C(null),s[82]=Ee):Ee=s[82];const Se=S===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let Ve;s[83]!==Se?(Ve=le("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Se),s[83]=Se,s[84]=Ve):Ve=s[84];let Z;s[85]!==e?(Z=e("settings.projects.page.field.none"),s[85]=e,s[86]=Z):Z=s[86];let y;s[87]===Symbol.for("react.memo_cache_sentinel")?(y=t.jsx(A,{name:"close",className:"h-4 w-4 text-muted-foreground"}),s[87]=y):y=s[87];let ue;s[88]!==Ve||s[89]!==Z?(ue=t.jsx("button",{type:"button",onClick:Ee,className:Ve,title:Z,children:y}),s[88]=Ve,s[89]=Z,s[90]=ue):ue=s[90];let Ie;s[91]!==S?(Ie=nm.map(Ze=>t.jsx("button",{type:"button",onClick:()=>C(Ze.key),className:le("h-7 w-7 rounded-md border transition-colors",S===Ze.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:Ze.cssVar},title:Ze.label},Ze.key)),s[91]=S,s[92]=Ie):Ie=s[92];let Oe;s[93]!==ue||s[94]!==Ie?(Oe=t.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[ue,Ie]}),s[93]=ue,s[94]=Ie,s[95]=Oe):Oe=s[95];let We;s[96]!==je||s[97]!==Oe?(We=t.jsxs("div",{"data-settings-item":"projects.accent-color",className:"py-1.5",children:[je,Oe]}),s[96]=je,s[97]=Oe,s[98]=We):We=s[98];let rt;s[99]!==e?(rt=e("settings.projects.page.field.projectIcon"),s[99]=e,s[100]=rt):rt=s[100];let it;s[101]!==rt?(it=t.jsx("div",{className:"flex min-w-0 flex-col",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:rt})}),s[101]=rt,s[102]=it):it=s[102];let nt;s[103]!==ae?(nt=t.jsx("input",{ref:w,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:Ze=>{const kt=Ze.target.files?.[0]??null;ae(kt),Ze.currentTarget.value=""}}),s[103]=ae,s[104]=nt):nt=s[104];let dt;s[105]===Symbol.for("react.memo_cache_sentinel")?(dt=()=>E(null),s[105]=dt):dt=s[105];const Ye=x===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let $e;s[106]!==Ye?($e=le("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Ye),s[106]=Ye,s[107]=$e):$e=s[107];let mt;s[108]!==e?(mt=e("settings.projects.page.field.none"),s[108]=e,s[109]=mt):mt=s[109];let he;s[110]===Symbol.for("react.memo_cache_sentinel")?(he=t.jsx(A,{name:"close",className:"h-4 w-4 text-muted-foreground"}),s[110]=he):he=s[110];let et;s[111]!==$e||s[112]!==mt?(et=t.jsx("button",{type:"button",onClick:dt,className:$e,title:mt,children:he}),s[111]=$e,s[112]=mt,s[113]=et):et=s[113];let Xe;s[114]!==Ce||s[115]!==x?(Xe=am.map(Ze=>{const kt=Ze.Icon;return t.jsx("button",{type:"button",onClick:()=>E(Ze.key),className:le("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",x===Ze.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:Ze.label,children:t.jsx(A,{name:kt,className:"w-4 h-4",style:Ce&&x===Ze.key?{color:Ce}:void 0})},Ze.key)}),s[114]=Ce,s[115]=x,s[116]=Xe):Xe=s[116];let He;s[117]!==et||s[118]!==Xe?(He=t.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[et,Xe]}),s[117]=et,s[118]=Xe,s[119]=He):He=s[119];let bt;s[120]!==f||s[121]!==se||s[122]!==we||s[123]!==M||s[124]!==V||s[125]!==p||s[126]!==W||s[127]!==e?(bt=se&&W&&t.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("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:M?{backgroundColor:M}:void 0,children:we&&V?t.jsx("img",{src:V,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>Y(!0)}):p?t.jsx(Dl,{project:p,options:{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground},className:"h-full w-full object-contain",onError:()=>Y(!0)}):null})})]}),s[120]=f,s[121]=se,s[122]=we,s[123]=M,s[124]=V,s[125]=p,s[126]=W,s[127]=e,s[128]=bt):bt=s[128];let wt;s[129]!==se||s[130]!==M||s[131]!==e?(wt=se&&t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[t.jsx("input",{type:"color",value:M??"#000000",onChange:Ze=>k(Ze.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":e("settings.projects.page.field.projectIconBackgroundAria")}),t.jsx(tt,{value:M??"",onChange:Ze=>k(Ze.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),t.jsx(J,{type:"button",size:"xs",variant:"outline",onClick:()=>k(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!M,children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),s[129]=se,s[130]=M,s[131]=e,s[132]=wt):wt=s[132];let Pt;s[133]!==De||s[134]!==ye||s[135]!==T||s[136]!==v||s[137]!==e?(Pt=!ye&&t.jsxs(t.Fragment,{children:[t.jsx(J,{size:"xs",className:"h-6 !font-normal",onClick:()=>w.current?.click(),disabled:v,children:e(v?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),t.jsx(J,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{De()},disabled:T,children:e(T?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),s[133]=De,s[134]=ye,s[135]=T,s[136]=v,s[137]=e,s[138]=Pt):Pt=s[138];let ie;s[139]!==Me||s[140]!==de||s[141]!==D||s[142]!==e?(ie=de&&t.jsx(J,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Me()},disabled:D,children:e(D?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),s[139]=Me,s[140]=de,s[141]=D,s[142]=e,s[143]=ie):ie=s[143];let Be;s[144]!==D||s[145]!==j||s[146]!==e?(Be=j&&t.jsx(J,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>P(!1),disabled:D,children:e("settings.projects.page.actions.undoRemove")}),s[144]=D,s[145]=j,s[146]=e,s[147]=Be):Be=s[147];let Je;s[148]!==Pt||s[149]!==ie||s[150]!==Be?(Je=t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Pt,ie,Be]}),s[148]=Pt,s[149]=ie,s[150]=Be,s[151]=Je):Je=s[151];let Ge;s[152]!==it||s[153]!==nt||s[154]!==He||s[155]!==bt||s[156]!==wt||s[157]!==Je?(Ge=t.jsxs("div",{"data-settings-item":"projects.icon",className:"py-1.5",children:[it,nt,He,bt,wt,Je]}),s[152]=it,s[153]=nt,s[154]=He,s[155]=bt,s[156]=wt,s[157]=Je,s[158]=Ge):Ge=s[158];let ut;s[159]!==G||s[160]!==We||s[161]!==Ge?(ut=t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[G,We,Ge]}),s[159]=G,s[160]=We,s[161]=Ge,s[162]=ut):ut=s[162];let yt;s[163]!==oe||s[164]!==D||s[165]!==v||s[166]!==g?(yt=!oe||g.trim().length===0||v||D,s[163]=oe,s[164]=D,s[165]=v,s[166]=g,s[167]=yt):yt=s[167];let gt;s[168]!==e?(gt=e("settings.common.actions.saveChanges"),s[168]=e,s[169]=gt):gt=s[169];let Et;s[170]!==xe||s[171]!==yt||s[172]!==gt?(Et=t.jsx("div",{className:"mt-0.5 px-2 py-1",children:t.jsx(J,{onClick:xe,disabled:yt,size:"xs",className:"!font-normal",children:gt})}),s[170]=xe,s[171]=yt,s[172]=gt,s[173]=Et):Et=s[173];let Qt;s[174]!==ut||s[175]!==Et?(Qt=t.jsxs("div",{className:"mb-8",children:[ut,Et]}),s[174]=ut,s[175]=Et,s[176]=Qt):Qt=s[176];let es;s[177]!==L?(es=L&&t.jsx(af,{projectRef:L}),s[177]=L,s[178]=es):es=s[178];let ts;s[179]!==es?(ts=t.jsx("div",{"data-settings-item":"projects.worktree",className:"mb-8",children:t.jsx("section",{className:"px-2 pb-2 pt-0",children:es})}),s[179]=es,s[180]=ts):ts=s[180];let ss;s[181]!==e?(ss=e("settings.projects.page.section.worktree"),s[181]=e,s[182]=ss):ss=s[182];let _t;s[183]!==ss?(_t=t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:ss})}),s[183]=ss,s[184]=_t):_t=s[184];let ns;s[185]!==L?(ns=L&&t.jsx(Qh,{projectRef:L}),s[185]=L,s[186]=ns):ns=s[186];let ke;s[187]!==ns?(ke=t.jsx("section",{className:"px-2 pb-2 pt-0",children:ns}),s[187]=ns,s[188]=ke):ke=s[188];let vt;s[189]!==_t||s[190]!==ke?(vt=t.jsxs("div",{className:"mb-8",children:[_t,ke]}),s[189]=_t,s[190]=ke,s[191]=vt):vt=s[191];let Nt;return s[192]!==Fe||s[193]!==Qt||s[194]!==ts||s[195]!==vt?(Nt=t.jsx(qt,{outerClassName:"h-full",className:"w-full bg-background",children:t.jsxs("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:[Fe,Qt,ts,vt]})}),s[192]=Fe,s[193]=Qt,s[194]=ts,s[195]=vt,s[196]=Nt):Nt=s[196],Nt};function of(s){return s.projects}function lf(s){return s.updateProjectMeta}function cf(s){return s.uploadProjectIcon}function df(s){return s.removeProjectIcon}function mf(s){return s.discoverProjectIcon}function uf(s){return s.settingsProjectsSelectedId}function pf(s){return s.setSettingsProjectsSelectedId}function gf(s){return s&&URL.revokeObjectURL(s),null}const Xl=s=>({v:1,serverUrl:s.serverUrl.trim().replace(/\/+$/,""),token:s.token.trim(),...s.label?.trim()?{label:s.label.trim()}:{}}),hf=s=>{const e=new URLSearchParams;return e.set("v",String(s.v)),e.set("server",s.serverUrl),e.set("token",s.token),s.label&&e.set("label",s.label),`openchamber://connect?${e.toString()}`},ff=s=>{const e=s.trim();if(!e)return null;try{const n=new URL(e);if(n.protocol!=="openchamber:"||n.hostname!=="connect")return null;const a=n.searchParams.get("v"),r=n.searchParams.get("server")?.trim()||"",i=n.searchParams.get("token")?.trim()||"",o=n.searchParams.get("label")?.trim()||"";if(a!=="1"||!r||!i)return null;try{const d=new URL(r);if(d.protocol!=="http:"&&d.protocol!=="https:")return null}catch{return null}return Xl({serverUrl:r,token:i,label:o})}catch{return null}},Br=()=>Math.floor(2e4+Math.random()*3e4),xf=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")},Mo=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"}},bf=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Zl=s=>!!(s&&bf.has(s)),Ro=s=>s==="ready"?"bg-[var(--status-success)] animate-pulse":s==="error"?"bg-[var(--status-error)] animate-pulse":s==="degraded"||Zl(s)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",yf=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}`,vf=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Br(),remoteHost:"127.0.0.1",remotePort:80}),jf=s=>s.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Us=s=>{const e=st.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(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let o;e[3]!==a?(o=t.jsxs(It,{children:[i,t.jsx(At,{sideOffset:8,className:"max-w-xs",children:t.jsx("div",{className:"typography-meta text-foreground",children:a})})]}),e[3]=a,e[4]=o):o=e[4];let d;return e[5]!==r||e[6]!==o?(d=t.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[r,o]}),e[5]=r,e[6]=o,e[7]=d):d=e[7],d},wf=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"}},To=(s,e)=>{const n=(s||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},Nf=s=>{const e=(s||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},kf=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}`},Vr=(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}),Sf=s=>s.trim().toLowerCase()==="authorization",mr=s=>{const e={};for(const n of s){const a=n.name.trim(),r=n.value.trim();a&&r&&!Sf(a)&&(e[a]=r)}return Object.keys(e).length>0?e:void 0},Cf=s=>Object.entries(s||{}).map(([e,n])=>Vr(e,n)),Pf=()=>{if(typeof window>"u")return null;const e=Kn()||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}},If=async()=>{const s=Ar(Kn())||window.location.origin;if(!ls()||!zn())return s;let e;try{e=await pt("/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 Fl(),r=Pf();return!a||!r?s:`http://${a}:${r}`},ur=s=>{const e=s.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Df=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}},Af=()=>{const{t:s}=ot(),{clientAuth:e}=Xr(),n=ls(),a=ms(K=>K.instances),r=ms(K=>K.statusesById),i=ms(K=>K.importCandidates),o=ms(K=>K.isLoading),d=ms(K=>K.isImportsLoading),c=ms(K=>K.isSaving),f=ms(K=>K.error),u=ms(K=>K.load),p=ms(K=>K.loadImports),m=ms(K=>K.refreshStatuses),I=ms(K=>K.upsertInstance),g=ms(K=>K.createFromCommand),h=ms(K=>K.removeInstance),x=ms(K=>K.connect),E=ms(K=>K.disconnect),S=ms(K=>K.retry),C=Le(K=>K.settingsRemoteInstancesSelectedId),M=Le(K=>K.setSettingsRemoteInstancesSelectedId),k=l.useMemo(()=>C&&a.find(K=>K.id===C)||null,[a,C]),[v,b]=l.useState(null),[D,U]=l.useState(!1),[T,F]=l.useState(!1),[j,P]=l.useState(null),[O,R]=l.useState([]),[V,B]=l.useState(null),[ee,Y]=l.useState(""),[w,H]=l.useState(!1),[Q,z]=l.useState({}),[L,X]=l.useState(!1),[$,ne]=l.useState(!1),[re,_]=l.useState(()=>Date.now()),[oe,fe]=l.useState([]),[xe,Ce]=l.useState("local"),[ve,we]=l.useState(!1),[ye,se]=l.useState(!1),[de,be]=l.useState(""),[W,te]=l.useState(""),[ae,me]=l.useState(""),[Me,Ne]=l.useState([]),[De,Ae]=l.useState(""),[Pe,Re]=l.useState(null),[Fe,Ue]=l.useState(!1),[_e,Ke]=l.useState(!1),[qe,ce]=l.useState(null),[G,pe]=l.useState(""),[je,Ee]=l.useState(""),[Se,Ve]=l.useState(""),[Z,y]=l.useState([]),[ue,Ie]=l.useState([]),[Oe,We]=l.useState(!1),[rt,it]=l.useState(""),[nt,dt]=l.useState(null),[Ye,$e]=l.useState(null),[mt,he]=l.useState(null),[et,Xe]=l.useState(null),He=l.useMemo(()=>ue.filter(K=>!!K.revokedAt).length,[ue]),[bt,wt]=l.useState(!1),[Pt,ie]=l.useState("ssh user@example.com"),[Be,Je]=l.useState("");l.useEffect(()=>{u(),p()},[u,p]);const Ge=l.useCallback(async()=>{we(!0),Re(null);try{const K=await fi();fe(K.hosts||[]),Ce(K.defaultHostId||"local")}catch(K){Re(K instanceof Error?K.message:String(K))}finally{we(!1)}},[]);l.useEffect(()=>{Ge()},[Ge]);const ut=l.useCallback(async(K,ze=xe)=>{se(!0),Re(null);try{await xi({hosts:K,defaultHostId:ze,initialHostChoiceCompleted:!0}),fe(K),Ce(ze)}catch(xt){Re(xt instanceof Error?xt.message:String(xt))}finally{se(!1)}},[xe]),yt=l.useCallback(async()=>{const K=bi(W);if(!K){Re(s("desktopHostSwitcher.error.invalidUrl"));return}const ze=K.persistedUrl,jt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:de.trim()||_n(ze),url:ze,apiUrl:ze,...ae.trim()?{clientToken:ae.trim()}:{},...mr(Me)?{requestHeaders:mr(Me)}:{}};await ut([jt,...oe],xe),be(""),te(""),me(""),Ne([]),Ue(!1),K.redeemUrl&&ur(K.redeemUrl)},[xe,Me,oe,de,ae,W,ut,s]),gt=l.useCallback(async()=>{const K=ff(De);if(!K){Re(s("settings.remoteInstances.direct.error.invalidConnectLink"));return}const ze=Ar(K.serverUrl);if(!ze){Re(s("desktopHostSwitcher.error.invalidUrl"));return}const xt=oe.find(jt=>Ar(jt.apiUrl||jt.url)===ze);if(xt){const jt=oe.map(rs=>rs.id===xt.id?{...rs,label:K.label||rs.label,url:ze,apiUrl:ze,clientToken:K.token}:rs);await ut(jt,xe)}else{const jt=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`;await ut([{id:jt,label:K.label||_n(ze),url:ze,apiUrl:ze,clientToken:K.token},...oe],xe)}Ae(""),Re(null),Ke(!1)},[De,xe,oe,ut,s]),Et=l.useCallback(async K=>{const ze=oe.filter(jt=>jt.id!==K);await ut(ze,xe===K?"local":xe),qe===K&&ce(null)},[xe,qe,oe,ut]),Qt=l.useCallback(K=>{ce(K.id),pe(K.label),Ee(K.apiUrl||K.url),Ve(K.clientToken||""),y(Cf(K.requestHeaders)),Re(null)},[]),es=l.useCallback(async()=>{if(!qe)return;const K=bi(je);if(!K){Re(s("desktopHostSwitcher.error.invalidUrl"));return}const ze=K.persistedUrl,xt=oe.map(jt=>jt.id===qe?{...jt,label:G.trim()||_n(ze),url:ze,apiUrl:ze,clientToken:Se.trim()||void 0,requestHeaders:mr(Z)}:jt);await ut(xt,xe),ce(null),K.redeemUrl&&ur(K.redeemUrl)},[xe,Z,G,Se,je,qe,oe,ut,s]),ts=l.useCallback(async()=>{const K=Pt.trim();if(!K){q.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}const ze=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await g(ze,K,Be.trim()||s("settings.remoteInstances.sidebar.newSshInstanceName")),M(ze),wt(!1),ie("ssh user@example.com"),Je(""),q.success(s("settings.remoteInstances.page.toast.instanceCreated"))}catch(xt){q.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:xt instanceof Error?xt.message:String(xt)})}},[g,M,Pt,Be,s]),ss=l.useCallback(async K=>{await ut(oe,K)},[oe,ut]),_t=l.useCallback(async()=>{if(e){We(!0),$e(null);try{Ie(await e.listClients())}catch(K){$e(K instanceof Error?K.message:String(K))}finally{We(!1)}}},[e]);l.useEffect(()=>{_t()},[_t]);const ns=l.useCallback(async()=>{if(e){$e(null);try{const K=await e.createClient({label:rt.trim()||void 0});dt(K.token),it(""),await _t()}catch(K){$e(K instanceof Error?K.message:String(K))}}},[e,_t,rt]),ke=l.useCallback(async()=>{if(e){$e(null);try{const K=await If(),ze=await e.createClient({label:rt.trim()||"Paired client"}),xt=Xl({serverUrl:K,token:ze.token,label:rt||"OpenChamber"}),jt=hf(xt);dt(ze.token),he(jt),Xe(await Nl.toDataURL(jt,{width:192,margin:1})),it(""),await _t()}catch(K){$e(K instanceof Error?K.message:String(K))}}},[e,_t,rt]),vt=l.useCallback(async K=>{if(!e)return;const ze=K.clientKind==="desktop-local";$e(null);try{if(await e.revokeClient(K.id),ze&&ls()){const xt=await fi();await xi({hosts:xt.hosts,defaultHostId:xt.defaultHostId,initialHostChoiceCompleted:xt.initialHostChoiceCompleted,localClientToken:null}),Ie(jt=>jt.map(rs=>rs.id===K.id?{...rs,revokedAt:new Date().toISOString()}:rs)),Xm({apiBaseUrl:Kn(),clientToken:null,runtimeKey:"local"});return}await _t()}catch(xt){$e(xt instanceof Error?xt.message:String(xt))}},[e,_t]),Nt=l.useCallback(async()=>{if(e){$e(null);try{await e.purgeRevokedClients(),await _t()}catch(K){$e(K instanceof Error?K.message:String(K))}}},[e,_t]);l.useEffect(()=>{b(k)},[k]),l.useEffect(()=>{if(!C)return;const K=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||m()},2e3);return()=>{window.clearInterval(K)}},[m,C]),l.useEffect(()=>{let K=null,ze=Date.now();const xt=()=>{const rs=Date.now();rs-ze>=1e3&&(_(rs),ze=rs),K=requestAnimationFrame(xt)};(typeof document>"u"||document.visibilityState==="visible")&&(K=requestAnimationFrame(xt));const jt=()=>{document.visibilityState==="visible"&&K===null?K=requestAnimationFrame(xt):document.visibilityState!=="visible"&&K!==null&&(cancelAnimationFrame(K),K=null)};return document.addEventListener("visibilitychange",jt),()=>{document.removeEventListener("visibilitychange",jt),K!==null&&cancelAnimationFrame(K)}},[]);const Ze=C?r[C]:null,kt=Ze?.phase,Wt=kt==="ready",Jt=kt==="degraded",as=Zl(kt),xs=Wt||(as||Jt),Rs=Ze?Math.max(0,re-Ze.updatedAtMs):0,As=Jt&&Rs>12e3,ct=l.useMemo(()=>!v||!k?!1:JSON.stringify(v)!==JSON.stringify(k),[v,k]),at=l.useCallback(K=>{b(ze=>ze&&K(ze))},[]),Rt=l.useCallback(async()=>{if(!v)return;const K=Df(v);if(!K.sshCommand.trim()){q.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(K.localForward.bindHost==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(K.auth.sshPassword?.enabled&&K.auth.sshPassword.value?.trim()&&K.auth.sshPassword.store!=="settings"){const ze=window.confirm(s("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));K.auth.sshPassword.store=ze?"settings":"never",ze||(K.auth.sshPassword.value=void 0)}if(K.auth.openchamberPassword?.enabled&&K.auth.openchamberPassword.value?.trim()&&K.auth.openchamberPassword.store!=="settings"){const ze=window.confirm(s("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));K.auth.openchamberPassword.store=ze?"settings":"never",ze||(K.auth.openchamberPassword.value=void 0)}try{await I(K),q.success(s("settings.remoteInstances.page.toast.instanceSaved"))}catch(ze){q.error(s("settings.remoteInstances.page.toast.saveFailed"),{description:ze instanceof Error?ze.message:String(ze)})}}},[v,s,I]),Yt=l.useCallback(async(K,ze)=>{const xt=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await g(xt,`ssh ${ze}`,K),M(xt),q.success(s("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(jt){return q.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:jt instanceof Error?jt.message:String(jt)}),!1}},[g,M,s]),Gt=l.useCallback(()=>{w||(B(null),Y(""))},[w]),Qe=l.useCallback((K,ze)=>{if(ze){B(K),Y(jf(K));return}Yt(K,K)},[Yt]),Ss=l.useCallback(async()=>{const K=V,ze=ee.trim();if(K){if(!ze){q.error(s("settings.remoteInstances.page.toast.destinationRequired"));return}H(!0);try{await Yt(K,ze)&&(B(null),Y(""))}finally{H(!1)}}},[Yt,ee,V,s]),Gs=l.useCallback(async()=>{if(k)try{await x(k.id);return}catch(K){if(!xf(K)||!window.confirm(s("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw K;const xt={...k,localForward:{...k.localForward,preferredLocalPort:Br()}};await I(xt),await x(xt.id),q.success(s("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[x,k,s,I]),cn=l.useCallback(async K=>(await rm(K,600)).map(xt=>kf(xt)),[]),aa=l.useCallback(async()=>{if(v){U(!0),F(!0),P(null);try{const K=await cn(v.id);R(K)}catch(K){R([]),P(K instanceof Error?K.message:String(K))}finally{F(!1)}}},[v,cn]);l.useEffect(()=>{if(!D||!v)return;let K=!1;const ze=async()=>{try{const jt=await cn(v.id);K||(R(jt),P(null))}catch(jt){K||P(jt instanceof Error?jt.message:String(jt))}};ze();const xt=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ze()},1e3);return()=>{K=!0,window.clearInterval(xt)}},[v,D,cn]);const Nn=l.useMemo(()=>O.join(`
|
|
28
|
-
`),[O]),Ha=l.useCallback(()=>{if(!Nn.trim()){q.error(s("settings.remoteInstances.page.toast.noLogsToCopy"));return}fn(Nn).then(K=>{K.ok&&q.success(s("settings.remoteInstances.page.toast.logsCopied"))})},[Nn,s]),Wa=l.useCallback(async()=>{if(v)try{await im(v.id),R([]),q.success(s("settings.remoteInstances.page.toast.logsCleared"))}catch(K){q.error(s("settings.remoteInstances.page.toast.clearLogsFailed"),{description:K instanceof Error?K.message:String(K)})}},[v,s]),qa=l.useCallback(async()=>{if(!Ze?.localUrl){q.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const K=Ze.localUrl.trim();if(!K){q.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ur(K)},[Ze?.localUrl,s]),Js=l.useCallback(()=>{if(!v)return;X(!0),(xs?E(v.id):Gs()).catch(ze=>{const xt=xs?Wt?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";q.error(s(xt),{description:ze instanceof Error?ze.message:String(ze)})}).finally(()=>{X(!1)})},[xs,Gs,E,v,Wt,s]),Qs=l.useCallback(()=>{if(!v||as)return;ne(!0),(Jt?E(v.id).then(()=>Gs()):S(v.id)).catch(ze=>{q.error(s("settings.remoteInstances.page.toast.retryFailed"),{description:ze instanceof Error?ze.message:String(ze)})}).finally(()=>{ne(!1)})},[Gs,E,v,as,Jt,S,s]),Ys=s(as?"settings.remoteInstances.page.actions.connecting":Jt?As?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Un=!L&&!$&&(kt==="error"||kt==="idle"||!kt||Jt&&As)&&!as,Ga=s(Wt?"settings.remoteInstances.sidebar.actions.disconnect":xs?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!v)return t.jsxs($r,{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.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[t.jsx(tt,{className:"h-8",value:rt,onChange:K=>it(K.target.value),placeholder:s("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ns()},children:s("settings.remoteInstances.clientAuth.actions.create")}),t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{ke()},children:s("settings.remoteInstances.clientAuth.actions.pair")})]}),mt?t.jsxs("div",{className:"flex flex-col gap-3 rounded-md border border-[var(--interactive-border)] p-2 sm:flex-row",children:[et?t.jsx("img",{src:et,alt:s("settings.remoteInstances.clientAuth.qrAlt"),className:"size-48 self-start"}):null,t.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.pairingUrl")}),t.jsx("code",{className:"block select-all break-all typography-code text-foreground",children:mt}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{fn(mt)},children:[t.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),s("settings.common.actions.copyAll")]})]})]}):null,nt?t.jsxs("div",{className:"space-y-1 rounded-md border border-[var(--interactive-border)] p-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.createdToken")}),t.jsx("code",{className:"block select-all break-all typography-code text-foreground",children:nt})]}):null,t.jsxs("div",{className:"space-y-1",children:[He>0?t.jsx("div",{className:"flex justify-end",children:t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Nt()},children:s("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,Oe?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.state.loading")}):ue.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.state.empty")}):ue.map(K=>{const ze=K.clientKind==="desktop-local";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("p",{className:"typography-ui-label text-foreground truncate",children:K.label}),ze?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:"typography-micro text-muted-foreground truncate",children:K.revokedAt?s("settings.remoteInstances.clientAuth.state.revoked"):K.lastUsedAt?s("settings.remoteInstances.clientAuth.lastUsed",{date:K.lastUsedAt}):s("settings.remoteInstances.clientAuth.neverUsed")})]}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{vt(K)},disabled:!!K.revokedAt,children:s("settings.remoteInstances.clientAuth.actions.revoke")})]},K.id)})]}),Ye?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ye}):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 px-1 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("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.remoteInstances.direct.note")}),t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ke(!0),disabled:ye,children:s("settings.remoteInstances.direct.import.action")}),t.jsxs(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Ue(!0),disabled:ye,children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.actions.add")]})]})]}),t.jsx("div",{className:"space-y-1",children:ve?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.state.loading")}):oe.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.state.empty")}):oe.map(K=>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("p",{className:"typography-ui-label text-foreground truncate",children:_n(K.label)}),xe===K.id?t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("desktopHostSwitcher.header.default")}):null]}),t.jsx("p",{className:"typography-micro text-muted-foreground font-mono truncate",children:_n(K.apiUrl||K.url)})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ss(K.id)},disabled:ye||xe===K.id,"aria-label":s("desktopHostSwitcher.actions.setAsDefaultAria"),children:xe===K.id?t.jsx(A,{name:"star-fill",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"star",className:"h-3.5 w-3.5"})}),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Qt(K),disabled:ye,children:[t.jsx(A,{name:"pencil",className:"h-3.5 w-3.5"}),s("desktopHostSwitcher.actions.edit")]}),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Et(K.id)},disabled:ye,children:[t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]})},K.id))}),Pe?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Pe}):null]})]}):null,n?t.jsx(Kt,{open:Fe,onOpenChange:Ue,children:t.jsxs(Ut,{className:"sm:max-w-lg",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("settings.remoteInstances.direct.actions.add")}),t.jsx(Ht,{children:s("settings.remoteInstances.direct.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),yt()},children:[t.jsx(tt,{className:"h-8",value:de,onChange:K=>be(K.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ye}),t.jsx(tt,{className:"h-8",value:W,onChange:K=>te(K.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ye,autoFocus:!0}),t.jsx(tt,{className:"h-8",value:ae,onChange:K=>me(K.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ye}),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")})]}),Me.map(K=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(tt,{className:"h-8 font-mono text-xs",value:K.name,onChange:ze=>Ne(xt=>xt.map(jt=>jt.id===K.id?{...jt,name:ze.target.value}:jt)),placeholder:s("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ye}),t.jsx(tt,{className:"h-8 font-mono text-xs",value:K.value,onChange:ze=>Ne(xt=>xt.map(jt=>jt.id===K.id?{...jt,value:ze.target.value}:jt)),placeholder:s("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ye}),t.jsx("button",{type:"button",onClick:()=>Ne(ze=>ze.filter(xt=>xt.id!==K.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:ye,children:t.jsx(A,{name:"close",className:"h-4 w-4"})})]},K.id)),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ne(K=>[...K,Vr()]),disabled:ye,children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.headers.actions.add")]})]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ue(!1),disabled:ye,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:ye||!W.trim(),children:s("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?t.jsx(Kt,{open:!!qe,onOpenChange:K=>{K||ce(null)},children:t.jsxs(Ut,{className:"sm:max-w-lg",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("desktopHostSwitcher.actions.edit")}),t.jsx(Ht,{children:s("settings.remoteInstances.direct.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),es()},children:[t.jsx(tt,{className:"h-8",value:G,onChange:K=>pe(K.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ye}),t.jsx(tt,{className:"h-8",value:je,onChange:K=>Ee(K.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ye,autoFocus:!0}),t.jsx(tt,{className:"h-8",value:Se,onChange:K=>Ve(K.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ye}),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")})]}),Z.map(K=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(tt,{className:"h-8 font-mono text-xs",value:K.name,onChange:ze=>y(xt=>xt.map(jt=>jt.id===K.id?{...jt,name:ze.target.value}:jt)),placeholder:s("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ye}),t.jsx(tt,{className:"h-8 font-mono text-xs",value:K.value,onChange:ze=>y(xt=>xt.map(jt=>jt.id===K.id?{...jt,value:ze.target.value}:jt)),placeholder:s("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ye}),t.jsx("button",{type:"button",onClick:()=>y(ze=>ze.filter(xt=>xt.id!==K.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:ye,children:t.jsx(A,{name:"close",className:"h-4 w-4"})})]},K.id)),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>y(K=>[...K,Vr()]),disabled:ye,children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.headers.actions.add")]})]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ce(null),disabled:ye,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:ye,children:s("settings.common.actions.saveChanges")})]})]})]})}):null,n?t.jsx(Kt,{open:_e,onOpenChange:Ke,children:t.jsxs(Ut,{className:"sm:max-w-lg",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("settings.remoteInstances.direct.import.action")}),t.jsx(Ht,{children:s("settings.remoteInstances.direct.import.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),gt()},children:[t.jsx(tt,{className:"h-8",value:De,onChange:K=>Ae(K.target.value),placeholder:s("settings.remoteInstances.direct.import.placeholder"),disabled:ye,autoFocus:!0}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ke(!1),disabled:ye,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:ye||!De.trim(),children:s("settings.remoteInstances.direct.import.action")})]})]})]})}):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.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.sidebar.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.sidebar.total",{count:a.length})})]}),t.jsxs(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>wt(!0),children:[t.jsx(A,{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:o?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(K=>{const ze=r[K.id],xt=K.nickname?.trim()||K.sshParsed?.destination||K.id,jt=ze?.phase,rs=jt==="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 ${Ro(jt)}`}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:xt})]}),t.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[s(Mo(jt)),ze?.localUrl?` · ${ze.localUrl}`:""]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(rs?E(K.id):x(K.id)).catch(Es=>q.error(s(rs?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:Es instanceof Error?Es.message:String(Es)}))},children:[rs?t.jsx(A,{name:"stop",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"plug-2",className:"h-3.5 w-3.5"}),s(rs?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>M(K.id),children:[t.jsx(A,{name:"pencil",className:"h-3.5 w-3.5"}),s("desktopHostSwitcher.actions.edit")]}),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(s("settings.remoteInstances.page.confirm.removeInstance"))&&h(K.id).catch(Es=>q.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Es instanceof Error?Es.message:String(Es)}))},children:[t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]},K.id)})})]}):null,n?t.jsx(Kt,{open:bt,onOpenChange:wt,children:t.jsxs(Ut,{className:"sm:max-w-lg",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("settings.remoteInstances.sidebar.actions.addSshInstance")}),t.jsx(Ht,{children:s("settings.remoteInstances.page.section.instanceDescription")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),ts()},children:[t.jsx(tt,{className:"h-8",value:Be,onChange:K=>Je(K.target.value),placeholder:s("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:c}),t.jsx(tt,{className:"h-8",value:Pt,onChange:K=>ie(K.target.value),placeholder:s("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:c,autoFocus:!0}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>wt(!1),disabled:c,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:c||!Pt.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(K=>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:[K.host,K.pattern?` ${s("settings.remoteInstances.page.import.patternSuffix")}`:""]}),t.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:K.sshCommand})]}),t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Qe(K.host,K.pattern)},children:s("settings.common.actions.import")})]},`${K.source}:${K.host}`))})})]}):null,t.jsx(Kt,{open:!!V,onOpenChange:K=>{K||Gt()},children:t.jsxs(Ut,{className:"sm:max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx(Ht,{children:V?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:V}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),Ss()},children:[t.jsx(tt,{value:ee,onChange:K=>Y(K.target.value),placeholder:s("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Gt,disabled:w,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:w,children:s("settings.remoteInstances.page.actions.create")})]})]})]})})]});const kn=v.remoteOpenchamber.mode==="managed",Ks=v.nickname?.trim()||v.sshParsed?.destination||v.id;return t.jsx(Kt,{open:!!v,onOpenChange:K=>{K||M(null)},children:t.jsxs(Ut,{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:Ks}),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 ${Ro(kt)}`}),t.jsx("span",{children:s(Mo(kt))}),Ze?.localUrl?t.jsx("span",{className:"font-mono text-foreground/80",children:Ze.localUrl}):null,As?t.jsx("span",{children:s("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.actions")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.actionsDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(J,{type:"button",variant:xs?"outline":"default",size:"xs",className:"!font-normal",onClick:Js,disabled:L||$,children:[xs?t.jsx(A,{name:"stop",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"plug-2",className:"h-3.5 w-3.5"}),Ga]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Qs,disabled:!Un,children:[t.jsx(A,{name:"refresh",className:`h-3.5 w-3.5 ${as||Jt&&!As?"animate-spin":""}`}),Ys]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{aa()},children:[t.jsx(A,{name:"terminal-window",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.logs")]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(s("settings.remoteInstances.page.confirm.removeInstance"))&&h(v.id).then(()=>{M(null),q.success(s("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(ze=>{q.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ze instanceof Error?ze.message:String(ze)})})},children:[t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.sidebar.actions.remove")]})]}),Ze?.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:Ze.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(tt,{className:"h-7 md:max-w-xl",value:v.sshCommand,onChange:K=>at(ze=>({...ze,sshCommand:K.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(tt,{className:"h-7 md:max-w-sm",value:v.nickname||"",onChange:K=>at(ze=>({...ze,nickname:K.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(js,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:v.connectionTimeoutSec,onValueChange:K=>{at(ze=>({...ze,connectionTimeoutSec:Number.isFinite(K)?K:ze.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(Us,{label:s("settings.remoteInstances.page.field.mode"),hint:s("settings.remoteInstances.page.field.modeHint")})}),t.jsxs(Tt,{value:v.remoteOpenchamber.mode,onValueChange:K=>at(ze=>({...ze,remoteOpenchamber:{...ze.remoteOpenchamber,mode:K==="external"?"external":"managed"}})),children:[t.jsx(Ft,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(zt,{placeholder:s("settings.remoteInstances.page.field.modePlaceholder")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"managed",children:s("settings.remoteInstances.page.field.modeManaged")}),t.jsx(ht,{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(Us,{label:s("settings.remoteInstances.page.field.preferredRemotePort"),hint:s("settings.remoteInstances.page.field.preferredRemotePortHint")})}),t.jsx(js,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.remoteOpenchamber.preferredPort,onValueChange:K=>{at(ze=>({...ze,remoteOpenchamber:{...ze.remoteOpenchamber,preferredPort:Number.isFinite(K)&&K>0?K:void 0}}))},onClear:()=>{at(K=>({...K,remoteOpenchamber:{...K.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]}),kn?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(Us,{label:s("settings.remoteInstances.page.field.installMethod"),hint:s("settings.remoteInstances.page.field.installMethodHint")})}),t.jsxs(Tt,{value:v.remoteOpenchamber.installMethod,onValueChange:K=>at(ze=>({...ze,remoteOpenchamber:{...ze.remoteOpenchamber,installMethod:K==="npm"||K==="download_release"||K==="upload_bundle"?K:"bun"}})),children:[t.jsx(Ft,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(zt,{placeholder:s("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"bun",children:"bun"}),t.jsx(ht,{value:"npm",children:"npm"}),t.jsx(ht,{value:"download_release",children:s("settings.remoteInstances.page.field.installMethodDownloadRelease")}),t.jsx(ht,{value:"upload_bundle",children:s("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,kn?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(Us,{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(Oa,{checked:v.remoteOpenchamber.keepRunning,onCheckedChange:K=>at(ze=>({...ze,remoteOpenchamber:{...ze.remoteOpenchamber,keepRunning:K}}))})})]}):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(Us,{label:s("settings.remoteInstances.page.field.bindHost"),hint:s("settings.remoteInstances.page.field.bindHostHint")})}),t.jsxs(Tt,{value:v.localForward.bindHost,onValueChange:K=>{K==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces"))||at(ze=>({...ze,localForward:{...ze.localForward,bindHost:K==="localhost"||K==="0.0.0.0"?K:"127.0.0.1"}}))},children:[t.jsx(Ft,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(zt,{placeholder:s("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"127.0.0.1",children:"127.0.0.1"}),t.jsx(ht,{value:"localhost",children:"localhost"}),t.jsx(ht,{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(Us,{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(js,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.localForward.preferredLocalPort,onValueChange:K=>{at(ze=>({...ze,localForward:{...ze.localForward,preferredLocalPort:Number.isFinite(K)&&K>0?K:void 0}}))},onClear:()=>{at(K=>({...K,localForward:{...K.localForward,preferredLocalPort:void 0}}))},emptyLabel:s("settings.remoteInstances.page.field.auto")}),t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:s("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>at(K=>({...K,localForward:{...K.localForward,preferredLocalPort:Br()}})),children:t.jsx(A,{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(tt,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.sshPassword?.value||"",onChange:K=>at(ze=>({...ze,auth:{...ze.auth,sshPassword:{enabled:K.target.value.trim().length>0,value:K.target.value,store:ze.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(tt,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.openchamberPassword?.value||"",onChange:K=>at(ze=>({...ze,auth:{...ze.auth,openchamberPassword:{enabled:K.target.value.trim().length>0,value:K.target.value,store:ze.auth.openchamberPassword?.store||"never"}}})),placeholder:s("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.portForwards")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.portForwardsDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[v.portForwards.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:s("settings.remoteInstances.page.empty.noExtraForwards")}):null,v.portForwards.map((K,ze)=>{const xt=Ot=>{at(Xt=>({...Xt,portForwards:Xt.portForwards.map((mn,Vn)=>Vn===ze?Ot(mn):mn)}))},jt=K.type==="remote"?"Local target":"Local listen",rs=K.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.",$n=K.type==="remote"?"Remote listen":"Remote target",Es=K.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",dn=To(K.localHost||"localhost",K.localPort),Bn=To(K.remoteHost||"localhost",K.remotePort),N=K.type==="local"&&typeof K.localPort=="number"&&K.localPort>0,ft=N?`http://${Nf(K.localHost)}:${K.localPort}`:"",Mt=!!Q[K.id],is=K.type==="local"?s("settings.remoteInstances.page.forwardType.local"):K.type==="remote"?s("settings.remoteInstances.page.forwardType.remote"):s("settings.remoteInstances.page.forwardType.dynamic");return t.jsxs(bn,{open:Mt,onOpenChange:Ot=>{z(Xt=>({...Xt,[K.id]:Ot}))},className:`${ze>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(yn,{className:"flex items-center gap-2 group",children:[t.jsx(A,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Mt?"rotate-180":""}`}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:yf(K)}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:is})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Oa,{checked:K.enabled,onCheckedChange:Ot=>xt(Xt=>({...Xt,enabled:Ot})),"aria-label":s("settings.remoteInstances.page.actions.enableForwardAria")}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>at(Ot=>({...Ot,portForwards:Ot.portForwards.filter(Xt=>Xt.id!==K.id)})),children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),t.jsx(vn,{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(wf(K.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(Us,{label:s("settings.remoteInstances.page.field.forwardType"),hint:s("settings.remoteInstances.page.field.forwardTypeHint")})}),t.jsxs(Tt,{value:K.type,onValueChange:Ot=>xt(Xt=>({...Xt,type:Ot==="dynamic"||Ot==="remote"?Ot:"local"})),children:[t.jsx(Ft,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(zt,{placeholder:s("settings.remoteInstances.page.field.typePlaceholder")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"local",children:s("settings.remoteInstances.page.forwardType.local")}),t.jsx(ht,{value:"remote",children:s("settings.remoteInstances.page.forwardType.remote")}),t.jsx(ht,{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(Us,{label:jt,hint:rs})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(tt,{className:"h-7 w-32",value:K.localHost||"127.0.0.1",onChange:Ot=>xt(Xt=>({...Xt,localHost:Ot.target.value})),placeholder:s("settings.remoteInstances.page.field.localHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(js,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:K.localPort,onValueChange:Ot=>{xt(Xt=>({...Xt,localPort:Number.isFinite(Ot)&&Ot>0?Ot:void 0}))},onClear:()=>{xt(Ot=>({...Ot,localPort:void 0}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]})]}),K.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(Us,{label:$n,hint:Es})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(tt,{className:"h-7 w-32",value:K.remoteHost||"",onChange:Ot=>xt(Xt=>({...Xt,remoteHost:Ot.target.value})),placeholder:s("settings.remoteInstances.page.field.remoteHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(js,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:K.remotePort,onValueChange:Ot=>{xt(Xt=>({...Xt,remotePort:Number.isFinite(Ot)&&Ot>0?Ot:void 0}))},onClear:()=>{xt(Ot=>({...Ot,remotePort:void 0}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]})]}):null,t.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[t.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:K.type==="dynamic"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:dn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.localSocks5")})]}):K.type==="remote"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"server",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:Bn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.remote")}),t.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"}),t.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:dn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.local")})]}):t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:dn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.local")}),t.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"}),t.jsx(A,{name:"server",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:Bn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.remote")})]})}),N?t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ws(ft).then(Ot=>{Ot||q.error(s("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[t.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},K.id)}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const K=vf();at(ze=>({...ze,portForwards:[...ze.portForwards,K]})),z(ze=>({...ze,[K.id]:!0}))},children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.addForward")]})]})]}),t.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Rt()},disabled:!ct||c,children:s("settings.common.actions.saveChanges")}),Ze?.localUrl?t.jsxs(t.Fragment,{children:[t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{fn(Ze.localUrl||"").then(K=>{K.ok&&q.success(s("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[t.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.copyLocalUrl")]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{qa()},children:[t.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.open")]})]}):null,f?t.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:f}):null]})}),t.jsx(Kt,{open:D,onOpenChange:U,children:t.jsxs(Ut,{className:"sm:max-w-2xl",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("settings.remoteInstances.page.logsDialog.title")}),t.jsx(Ht,{children:v?.nickname?.trim()||v?.sshParsed?.destination||v?.id||s("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ha,disabled:T||!Nn.trim(),children:[t.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),s("settings.common.actions.copyAll")]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Wa()},disabled:T,children:[t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.clear")]})]}),T?t.jsx("div",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.logsDialog.loading")}):j?t.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:j}):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:O.length>0?O.join(`
|
|
29
|
-
`):s("settings.remoteInstances.page.logsDialog.empty")})]})}),t.jsx(Kt,{open:!!V,onOpenChange:K=>{K||Gt()},children:t.jsxs(Ut,{className:"sm:max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx(Ht,{children:V?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:V}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),Ss()},children:[t.jsx(tt,{value:ee,onChange:K=>Y(K.target.value),placeholder:s("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Gt,disabled:w,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:w,children:s("settings.common.actions.create")})]})]})]})})]})})},Ef="__add_provider__",Mf=()=>{const s=vs.getDirectory();return typeof s=="string"&&s.trim().length>0?s.trim():null},Rf=({onItemSelect:s})=>{const{t:e}=ot(),n=lt(m=>m.providers),a=lt(m=>m.selectedProviderId),r=lt(m=>m.setSelectedProvider),i=os(m=>m.activeProjectId),[o,d]=l.useState({}),c=l.useMemo(()=>Mf(),[i]);l.useEffect(()=>{if(n.length===0){d({});return}let m=!1;return(async()=>{const g=n.map(async h=>{try{const x=c?`?directory=${encodeURIComponent(c)}`:"",E=await pt(`/api/provider/${encodeURIComponent(h.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!E.ok)return;const S=await E.json().catch(()=>null),C=S?.sources??S?.data?.sources;if(!C||m)return;d(M=>({...M,[h.id]:C}))}catch{}});await Promise.all(g)})(),()=>{m=!0}},[c,n]);const f="bg-background",u=l.useMemo(()=>n.filter(m=>!!o[m.id]?.project?.exists),[n,o]),p=l.useMemo(()=>n.filter(m=>!o[m.id]?.project?.exists),[n,o]);return t.jsxs("div",{className:le("flex h-full flex-col",f),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.providers.sidebar.title")}),t.jsx(na,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),t.jsx(J,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(Ef),s?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:t.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(qt,{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(A,{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(m=>t.jsx(Fo,{provider:m,selectedProviderId:a,onSelect:()=>{r(m.id),s?.()}},m.id))]}),u.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:le("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")}),u.map(m=>t.jsx(Fo,{provider:m,selectedProviderId:a,onSelect:()=>{r(m.id),s?.()}},m.id))]})]})})]})},Fo=s=>{const e=st.c(17),{provider:n,selectedProviderId:a,onSelect:r}=s,i=Array.isArray(n.models)?n.models.length:0,o=n.id===a,d=n.id,c=o?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==c?(f=le("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=f):f=e[1];let u;e[2]!==n.id?(u=t.jsx(Tn,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=u):u=e[3];const p=n.name||n.id;let m;e[4]!==p?(m=t.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:p}),e[4]=p,e[5]=m):m=e[5];let I;e[6]!==i?(I=t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=I):I=e[7];let g;e[8]!==r||e[9]!==u||e[10]!==m||e[11]!==I?(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:[u,m,I]}),e[8]=r,e[9]=u,e[10]=m,e[11]=I,e[12]=g):g=e[12];let h;return e[13]!==n.id||e[14]!==f||e[15]!==g?(h=t.jsx("div",{className:f,children:g},d),e[13]=n.id,e[14]=f,e[15]=g,e[16]=h):h=e[16],h},Tf=s=>s,Ff=s=>new Intl.NumberFormat(Yr(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(s),Lo=s=>{if(typeof s!="number"||Number.isNaN(s))return null;if(s===0)return"0";const e=Ff(s);return e.endsWith(".0")?e.slice(0,-2):e},xa="__add_provider__",On=s=>typeof s=="object"&&s!==null,Oo=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()},Lf=s=>{if(!On(s))return{};const e={};for(const[n,a]of Object.entries(s))Array.isArray(a)&&(e[n]=a.filter(r=>On(r)));return e},Of=s=>{if(typeof s=="string")return{id:s};if(!On(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}},zf=s=>{let e=[];Array.isArray(s)?e=s:On(s)&&(Array.isArray(s.all)?e=s.all:Array.isArray(s.providers)&&(e=s.providers));const n=e.map(r=>Of(r)).filter(r=>!!r),a=new Set;return n.filter(r=>a.has(r.id)?!1:(a.add(r.id),!0))},Kf=()=>{const{t:s}=ot(),e=lt(W=>W.providers),n=lt(W=>W.selectedProviderId),a=lt(W=>W.setSelectedProvider),r=lt(W=>W.getModelMetadata),i=Le(W=>W.hiddenModels),o=Le(W=>W.toggleHiddenModel),d=Le(W=>W.hideAllModels),c=Le(W=>W.showAllModels),[f,u]=l.useState({}),[p,m]=l.useState(!1),[I,g]=l.useState({}),[h,x]=l.useState(null),[E,S]=l.useState(""),[C,M]=l.useState(null),[k,v]=l.useState({}),[b,D]=l.useState({}),[U,T]=l.useState([]),[F,j]=l.useState(!1),[P,O]=l.useState(null),[R,V]=l.useState(""),[B,ee]=l.useState(""),[Y,w]=l.useState(!1),[H,Q]=l.useState({}),[z,L]=l.useState(!1),X=n===xa;l.useEffect(()=>{!n&&e.length>0&&a(e[0].id)},[e,n,a]),l.useEffect(()=>{if(!X)return;let W=!0;return(async()=>{m(!0);try{const ae=await vs.getSdkClient().provider.auth();if(ae.error)throw new Error(`provider.auth failed: ${String(ae.error)}`);if(!W)return;u(Lf(ae.data))}catch(ae){if(!W)return;console.error("Failed to load provider auth methods:",ae),q.error(s("settings.providers.page.toast.authMethodsLoadFailed"))}finally{W&&m(!1)}})(),()=>{W=!1}},[X,s]),l.useEffect(()=>{if(!Tf(X))return;let W=!0;return(async()=>{j(!0),O(null);try{const ae=await vs.getSdkClient().provider.list();if(ae.error)throw new Error(`provider.list failed: ${String(ae.error)}`);if(!W)return;T(zf(ae.data))}catch(ae){if(!W)return;console.error("Failed to load available providers:",ae),O(s("settings.providers.page.state.unableToLoadProviderList"))}finally{W&&j(!1)}})(),()=>{W=!1}},[X,s]);const $=l.useMemo(()=>new Set(e.map(W=>W.id)),[e]),ne=l.useMemo(()=>U.filter(W=>!$.has(W.id)).sort((W,te)=>{const ae=(W.name||W.id).toLowerCase(),me=(te.name||te.id).toLowerCase();return ae.localeCompare(me)}),[U,$]);l.useEffect(()=>{n===xa&&R&&!ne.some(W=>W.id===R)&&V("")},[n,R,ne]),l.useEffect(()=>{if(n===xa){L(!0);return}L(!1)},[n,s]),l.useEffect(()=>{if(!n||n===xa)return;let W=!1;return(async()=>{try{const ae=await pt(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),me=await ae.json().catch(()=>null);if(!ae.ok)throw new Error(me?.error||s("settings.providers.page.toast.providerSourcesLoadFailed"));const Me=me?.sources??me?.data?.sources;!W&&Me&&Q(Ne=>({...Ne,[n]:Me}))}catch(ae){W||console.error("Failed to load provider sources:",ae)}})(),()=>{W=!0}},[n,s]);const re=e.find(W=>W.id===n),_=n?H[n]:void 0,oe=async W=>{const te=I[W]?.trim()??"";if(!te){q.error(s("settings.providers.page.toast.apiKeyRequired"));return}const ae=`api:${W}`;x(ae);try{if((await vs.getSdkClient().auth.set({providerID:W,auth:{type:"api",key:te}})).error)throw new Error(s("settings.providers.page.toast.apiKeySaveFailed"));q.success(s("settings.providers.page.toast.apiKeySaved")),g(Me=>({...Me,[W]:""})),await Mn({scopes:["providers"],mode:"active"}),a(W)}catch(me){console.error("Failed to save API key:",me),q.error(s("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},fe=async(W,te)=>{const ae=`oauth:${W}:${te}`;x(ae);try{const me=await vs.getSdkClient().provider.oauth.authorize({providerID:W,method:te});if(me.error)throw new Error(s("settings.providers.page.toast.oauthStartFailed"));const Me=On(me.data)?me.data:{},Ne=Me.data,De=On(Ne)?Ne:Me,Ae=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,Pe=typeof De.instructions=="string"&&De.instructions||typeof De.message=="string"&&De.message||void 0,Re=typeof De.user_code=="string"&&De.user_code||typeof De.code=="string"&&De.code||typeof De.userCode=="string"&&De.userCode||void 0;if(!Ae&&!Pe&&!Re)throw new Error(s("settings.providers.page.toast.oauthDetailsMissing"));const Fe=`${W}:${te}`;D(Ue=>({...Ue,[Fe]:{url:Ae,instructions:Pe,userCode:Re}})),Ae&&Ws(Ae),M({providerId:W,methodIndex:te}),q.message(s("settings.providers.page.toast.completeOAuthInBrowser"))}catch(me){console.error("Failed to start OAuth flow:",me),q.error(s("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},xe=async(W,te)=>{const ae=`${W}:${te}`,me=k[ae]?.trim(),Me=`oauth-complete:${W}:${te}`;x(Me);try{const Ne={method:te};if(me&&(Ne.code=me),(await vs.getSdkClient().provider.oauth.callback({providerID:W,method:Ne.method,code:Ne.code})).error)throw new Error(s("settings.providers.page.toast.oauthCompleteFailed"));q.success(s("settings.providers.page.toast.oauthCompleted")),v(Ae=>({...Ae,[ae]:""})),M(null),await Mn({scopes:["providers"],mode:"active"}),a(W)}catch(Ne){console.error("Failed to complete OAuth flow:",Ne),q.error(s("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},Ce=async W=>{const te=await fn(W);if(te.ok){q.success(s("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",te.error),q.error(s("settings.providers.page.toast.oauthLinkCopyFailed"))},ve=async W=>{const te=await fn(W);if(te.ok){q.success(s("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",te.error),q.error(s("settings.providers.page.toast.deviceCodeCopyFailed"))},we=async W=>{const te=`disconnect:${W}`;x(te);try{const ae=await pt(`/api/provider/${encodeURIComponent(W)}/auth?scope=all`,{method:"DELETE",headers:{Accept:"application/json"}}),me=await ae.json().catch(()=>null);if(!ae.ok)throw new Error(me?.error||s("settings.providers.page.toast.providerDisconnectFailed"));q.success(s("settings.providers.page.toast.providerDisconnected")),await Mn({scopes:["providers"],mode:"active"})}catch(ae){console.error("Failed to disconnect provider:",ae),q.error(s("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}};if(!X&&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(A,{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(X)return t.jsx(qt,{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")}),F?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.state.loading")}):P?t.jsx("p",{className:"typography-meta text-muted-foreground",children:P}):ne.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.connect.allProvidersConnected")}):t.jsxs(gs,{open:Y,onOpenChange:W=>{w(W),W||ee("")},children:[t.jsx(us,{asChild:!0,children:t.jsxs("button",{type:"button",className:le("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(Tn,{providerId:R,className:"h-3.5 w-3.5 flex-shrink-0"}):null,t.jsx("span",{className:le("truncate typography-ui-label font-normal",R?"text-foreground":"text-muted-foreground"),children:R?ne.find(W=>W.id===R)?.name||R:s("settings.providers.page.connect.selectProviderPlaceholder")})]}),t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),t.jsxs(ps,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:W=>W.preventDefault(),children:[t.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:W=>W.stopPropagation(),children:[t.jsx(A,{name:"search",className:"h-4 w-4 text-muted-foreground"}),t.jsx("input",{type:"text",value:B,onChange:W=>ee(W.target.value),onKeyDown:W=>W.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(qt,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const W=ne.filter(te=>{const ae=B.toLowerCase();return(te.name||te.id).toLowerCase().includes(ae)||te.id.toLowerCase().includes(ae)});return W.length===0?t.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:s("settings.providers.page.connect.noProvidersFound")}):W.map(te=>t.jsxs(ws,{onSelect:()=>{V(te.id),w(!1),ee("")},className:"flex items-center justify-between",children:[t.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(Tn,{providerId:te.id,className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:te.name||te.id})]}),R===te.id&&t.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},te.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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{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(tt,{type:"password",value:I[R]??"",onChange:W=>g(te=>({...te,[R]:W.target.value})),placeholder:s("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal shrink-0",onClick:()=>oe(R),disabled:h===`api:${R}`,children:h===`api:${R}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),(()=>{const te=(f[R]??[]).filter(ae=>Oo(ae)==="oauth");return te.length===0?null:t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:te.map((ae,me)=>{const Me=ae.label||ae.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String(me+1)}),Ne=`${R}:${me}`,De=C?.providerId===R&&C?.methodIndex===me;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:Me}),(ae.description||ae.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(ae.description||ae.help)})]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>fe(R,me),disabled:h===`oauth:${R}:${me}`,children:s("settings.providers.page.actions.connect")})]}),b[Ne]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:b[Ne]?.instructions}),b[Ne]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(tt,{value:b[Ne]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ve(b[Ne]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),b[Ne]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(tt,{value:b[Ne]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ws(b[Ne]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ce(b[Ne]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),De&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(tt,{value:k[Ne]??"",onChange:Ae=>v(Pe=>({...Pe,[Ne]:Ae.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal",onClick:()=>xe(R,me),disabled:h===`oauth-complete:${R}:${me}`,children:h===`oauth-complete:${R}:${me}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${R}-${Me}`)})})})()]})]})]})});if(!re)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(A,{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 ye=Array.isArray(re.models)?re.models:[],de=(f[re.id]??[]).filter(W=>Oo(W)==="oauth"),be=ye.filter(W=>{const te=typeof W?.name=="string"?W.name:"",ae=typeof W?.id=="string"?W.id:"",me=E.trim().toLowerCase();return me?te.toLowerCase().includes(me)||ae.toLowerCase().includes(me):!0});return t.jsx(qt,{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(Tn,{providerId:re.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:re.name||re.id}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t.jsx("span",{className:"font-mono",children:re.id})})]})]}),t.jsxs("div",{"data-settings-item":"providers.auth",className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.auth.title")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>L(W=>!W),children:s(z?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:z?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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{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(tt,{type:"password",value:I[re.id]??"",onChange:W=>g(te=>({...te,[re.id]:W.target.value})),placeholder:s("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal shrink-0",onClick:()=>oe(re.id),disabled:h===`api:${re.id}`,children:h===`api:${re.id}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),de.length>0&&t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:de.map((W,te)=>{const ae=W.label||W.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String(te+1)}),me=`${re.id}:${te}`,Me=C?.providerId===re.id&&C?.methodIndex===te;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:ae}),(W.description||W.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(W.description||W.help)})]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>fe(re.id,te),disabled:h===`oauth:${re.id}:${te}`,children:s("settings.providers.page.actions.connect")})]}),b[me]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:b[me]?.instructions}),b[me]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(tt,{value:b[me]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ve(b[me]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),b[me]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(tt,{value:b[me]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ws(b[me]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ce(b[me]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),Me&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(tt,{value:k[me]??"",onChange:Ne=>v(De=>({...De,[me]:Ne.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal",onClick:()=>xe(re.id,te),disabled:h===`oauth-complete:${re.id}:${te}`,children:h===`oauth-complete:${re.id}:${te}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${re.id}-${ae}`)})})]}):t.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[t.jsx(A,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.providers.page.auth.connected")}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-1",children:s("settings.providers.page.auth.useReconnectHint")})]})})]}),t.jsxs("div",{"data-settings-item":"providers.connection-details",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.connectionDetails.title")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col",children:_&&(_.auth.exists||_.user.exists||_.project.exists||_.custom?.exists)?t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[s("settings.providers.page.connectionDetails.configuredIn")," ",[_.auth.exists?s("settings.providers.page.connectionDetails.source.authCredentials"):null,_.user.exists?s("settings.providers.page.connectionDetails.source.userConfig"):null,_.project.exists?s("settings.providers.page.connectionDetails.source.projectConfig"):null,_.custom?.exists?s("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.connectionDetails.noActiveSource")})}),t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>we(re.id),disabled:h===`disconnect:${re.id}`,children:h===`disconnect:${re.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"),ye.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ye.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const W=ye.map(te=>typeof te?.id=="string"?te.id:"").filter(te=>te.length>0);d(re.id,W)},children:s("settings.providers.page.actions.hideAll")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>c(re.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(A,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),t.jsx(tt,{value:E,onChange:W=>S(W.target.value),placeholder:s("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),be.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:be.map(W=>{const te=typeof W?.id=="string"?W.id:"",ae=typeof W?.name=="string"?W.name:te,me=te?r(re.id,te):void 0,Me=i.some(Pe=>Pe.providerID===re.id&&Pe.modelID===te),Ne=Lo(me?.limit?.context),De=Lo(me?.limit?.output),Ae=[];return me?.tool_call&&Ae.push({key:"tools",icon:"tools",label:s("settings.providers.page.models.capability.toolCalling")}),me?.reasoning&&Ae.push({key:"reasoning",icon:"brain-ai-3",label:s("settings.providers.page.models.capability.reasoning")}),me?.attachment&&Ae.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:le("flex items-center gap-3",Me&&"opacity-50"),children:[t.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:ae}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Ne||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:[Ne?`${Ne} ${s("settings.providers.page.models.tokenBadge.context")}`:"",Ne&&De?" · ":"",De?`${De} ${s("settings.providers.page.models.tokenBadge.output")}`:""]}),Ae.length>0&&t.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Ae.map(({key:Pe,icon:Re,label:Fe})=>t.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Fe,"aria-label":Fe,children:t.jsx(A,{name:Re,className:"h-3 w-3"})},Pe))}),t.jsx("button",{type:"button",onClick:()=>o(re.id,te),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:s(Me?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":s(Me?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Me?t.jsx(A,{name:"eye-off",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},te)})})]})]})]})})},on=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"cursor",name:"Cursor"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"wafer",name:"Wafer.ai"}];function zo(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 Uf=[{id:"gemini-auth",label:"Gemini",matcher:s=>s.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:s=>s.startsWith("antigravity/"),order:2}],ec={google:Uf};function tc(s,e){const n=ec[e]??[];for(const a of n)if(a.matcher(s))return a;return null}function $f(s){return ec[s]??[]}function Bf(s){return[...s].sort((e,n)=>e.order-n.order)}function Jv(s,e){const n=new Map;for(const a of Object.keys(s)){const i=tc(a,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(a)}return n}function Vf(s,e,n){const a=new Map;for(const r of s){const i=e(r),d=tc(i,n)?.id??null;a.has(d)||a.set(d,[]),a.get(d).push(r)}return a}function _f(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,Ko=s=>{const e=on.map(m=>m.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,o=Array.isArray(s?.usageDropdownProviders)?s?.usageDropdownProviders:null,d=o?o.filter(m=>typeof m=="string"&&e.includes(m)):e,c={},f=s?.usageSelectedModels;if(f&&typeof f=="object")for(const[m,I]of Object.entries(f))Array.isArray(I)&&(c[m]=I.filter(g=>typeof g=="string"));const u={},p=s?.usageExpandedFamilies;if(p&&typeof p=="object")for(const[m,I]of Object.entries(p))Array.isArray(I)&&(u[m]=I.filter(g=>typeof g=="string"));return{autoRefresh:n,refreshIntervalMs:a,displayMode:r,showPredValues:i,dropdownProviderIds:d,selectedModels:c,expandedFamilies:u}},Hf=async()=>{const s=Os()?.settings;if(s)try{const n=(await s.load())?.settings;return Ko(n??null)}catch{}if(!fs()){const e=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Ko(n)}}return{autoRefresh:!1,refreshIntervalMs:ti,displayMode:"usage",showPredValues:!1,dropdownProviderIds:on.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Vt=ln()(sa((s,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:ti,displayMode:"usage",showPredValues:!1,dropdownProviderIds:on.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Hf();s(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{s({isLoading:!0,error:null});const n=on.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 pt(`/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(o=>{const d=o.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(o=>{const d=o.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}})),Ct({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}}}),Ct({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,a)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=_f(n,a);i.length!==0&&(s(o=>({selectedModels:{...o.selectedModels,[n]:i}})),Ct({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Wf=()=>{const s=st.c(5),e=Vt(qf),n=Vt(Gf),a=Vt(Jf);let r,i;s[0]!==e||s[1]!==a||s[2]!==n?(r=()=>{if(!e)return;const o=window.setInterval(()=>{a()},n);return()=>window.clearInterval(o)},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]),l.useEffect(r,i)};function qf(s){return s.autoRefresh}function Gf(s){return s.refreshIntervalMs}function Jf(s){return s.fetchAllQuotas}const Qf=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)},Yf=s=>{const e=st.c(122),{onItemSelect:n}=s,{t:a}=ot(),r=Vt(Xf),i=Vt(Zf),o=Vt(ex),d=Vt(tx),c=Vt(sx),f=Vt(nx),u=Vt(ax),p=Vt(rx),m=Vt(ix),I=Vt(ox),g=Vt(lx),h=Vt(cx),x=Vt(dx),E=Vt(mx);let S,C;e[0]!==E?(S=()=>{E()},C=[E],e[0]=E,e[1]=S,e[2]=C):(S=e[1],C=e[2]),l.useEffect(S,C);const M=ux;let k;e[3]!==m?(k=je=>{m(je),M({usageAutoRefresh:je})},e[3]=m,e[4]=k):k=e[4];const v=k;let b;e[5]!==I?(b=je=>{const Ee=Number(je);Number.isFinite(Ee)&&(I(Ee),M({usageRefreshIntervalMs:Ee}))},e[5]=I,e[6]=b):b=e[6];const D=b;let U;e[7]!==g?(U=je=>{je!=="usage"&&je!=="remaining"||(g(je),M({usageDisplayMode:je}))},e[7]=g,e[8]=U):U=e[8];const T=U;let F;e[9]!==x?(F=je=>{x(je),M({usageShowPredValues:je})},e[9]=x,e[10]=F):F=e[10];const j=F;let P;e[11]===Symbol.for("react.memo_cache_sentinel")?(P=le("flex h-full flex-col","bg-background"),e[11]=P):P=e[11];let O;e[12]!==a?(O=a("settings.usage.sidebar.title"),e[12]=a,e[13]=O):O=e[13];let R;e[14]!==O?(R=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:O}),e[14]=O,e[15]=R):R=e[15];let V;e[16]!==a?(V=a("settings.usage.sidebar.total",{count:on.length}),e[16]=a,e[17]=V):V=e[17];let B;e[18]!==V?(B=t.jsx("span",{className:"typography-meta text-muted-foreground",children:V}),e[18]=V,e[19]=B):B=e[19];let ee;e[20]!==a?(ee=a("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[20]=a,e[21]=ee):ee=e[21];let Y;e[22]!==v||e[23]!==ee||e[24]!==f?(Y=t.jsx(Dt,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:t.jsx(St,{checked:f,onChange:v,ariaLabel:ee})})}),e[22]=v,e[23]=ee,e[24]=f,e[25]=Y):Y=e[25];let w;e[26]!==a?(w=a("settings.usage.sidebar.tooltip.autoRefresh"),e[26]=a,e[27]=w):w=e[27];let H;e[28]!==w?(H=t.jsx(At,{side:"bottom",children:w}),e[28]=w,e[29]=H):H=e[29];let Q;e[30]!==Y||e[31]!==H?(Q=t.jsxs(It,{children:[Y,H]}),e[30]=Y,e[31]=H,e[32]=Q):Q=e[32];const z=String(u),L=!f;let X;e[33]!==a?(X=a("settings.usage.sidebar.field.intervalPlaceholder"),e[33]=a,e[34]=X):X=e[34];let $;e[35]!==X?($=t.jsx(Ft,{className:"w-fit",children:t.jsx(zt,{placeholder:X})}),e[35]=X,e[36]=$):$=e[36];let ne;e[37]===Symbol.for("react.memo_cache_sentinel")?(ne=t.jsxs(Lt,{children:[t.jsx(ht,{value:"30000",children:"30s"}),t.jsx(ht,{value:"60000",children:"1m"}),t.jsx(ht,{value:"300000",children:"5m"})]}),e[37]=ne):ne=e[37];let re;e[38]!==D||e[39]!==z||e[40]!==L||e[41]!==$?(re=t.jsxs(Tt,{value:z,onValueChange:D,disabled:L,children:[$,ne]}),e[38]=D,e[39]=z,e[40]=L,e[41]=$,e[42]=re):re=e[42];let _;e[43]!==d?(_=()=>d(),e[43]=d,e[44]=_):_=e[44];let oe;e[45]!==a?(oe=a("settings.usage.sidebar.actions.refreshAria"),e[45]=a,e[46]=oe):oe=e[46];let fe;e[47]!==a?(fe=a("settings.usage.sidebar.actions.refreshTitle"),e[47]=a,e[48]=fe):fe=e[48];const xe=c&&"animate-spin";let Ce;e[49]!==xe?(Ce=le("h-3.5 w-3.5",xe),e[49]=xe,e[50]=Ce):Ce=e[50];let ve;e[51]!==Ce?(ve=t.jsx(A,{name:"refresh",className:Ce}),e[51]=Ce,e[52]=ve):ve=e[52];let we;e[53]!==c||e[54]!==_||e[55]!==oe||e[56]!==fe||e[57]!==ve?(we=t.jsx(J,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:_,"aria-label":oe,title:fe,disabled:c,children:ve}),e[53]=c,e[54]=_,e[55]=oe,e[56]=fe,e[57]=ve,e[58]=we):we=e[58];let ye;e[59]!==Q||e[60]!==re||e[61]!==we?(ye=t.jsxs("div",{className:"flex items-center gap-2",children:[Q,re,we]}),e[59]=Q,e[60]=re,e[61]=we,e[62]=ye):ye=e[62];let se;e[63]!==B||e[64]!==ye?(se=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[B,ye]}),e[63]=B,e[64]=ye,e[65]=se):se=e[65];let de;e[66]!==a?(de=a("settings.usage.sidebar.field.display"),e[66]=a,e[67]=de):de=e[67];let be;e[68]!==de?(be=t.jsx("span",{className:"typography-micro text-muted-foreground",children:de}),e[68]=de,e[69]=be):be=e[69];let W;e[70]!==a?(W=a("settings.usage.sidebar.field.displayModePlaceholder"),e[70]=a,e[71]=W):W=e[71];let te;e[72]!==W?(te=t.jsx(Ft,{className:"w-fit",children:t.jsx(zt,{placeholder:W})}),e[72]=W,e[73]=te):te=e[73];let ae;e[74]!==a?(ae=a("settings.usage.sidebar.field.displayModeUsage"),e[74]=a,e[75]=ae):ae=e[75];let me;e[76]!==ae?(me=t.jsx(ht,{value:"usage",children:ae}),e[76]=ae,e[77]=me):me=e[77];let Me;e[78]!==a?(Me=a("settings.usage.sidebar.field.displayModeRemaining"),e[78]=a,e[79]=Me):Me=e[79];let Ne;e[80]!==Me?(Ne=t.jsx(ht,{value:"remaining",children:Me}),e[80]=Me,e[81]=Ne):Ne=e[81];let De;e[82]!==me||e[83]!==Ne?(De=t.jsxs(Lt,{children:[me,Ne]}),e[82]=me,e[83]=Ne,e[84]=De):De=e[84];let Ae;e[85]!==T||e[86]!==te||e[87]!==De||e[88]!==p?(Ae=t.jsxs(Tt,{value:p,onValueChange:T,children:[te,De]}),e[85]=T,e[86]=te,e[87]=De,e[88]=p,e[89]=Ae):Ae=e[89];let Pe;e[90]!==be||e[91]!==Ae?(Pe=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[be,Ae]}),e[90]=be,e[91]=Ae,e[92]=Pe):Pe=e[92];let Re;e[93]!==a?(Re=a("settings.usage.sidebar.field.showPredictions"),e[93]=a,e[94]=Re):Re=e[94];let Fe;e[95]!==Re?(Fe=t.jsx("span",{className:"typography-micro text-muted-foreground",children:Re}),e[95]=Re,e[96]=Fe):Fe=e[96];let Ue;e[97]!==a?(Ue=a("settings.usage.sidebar.field.showPredictions"),e[97]=a,e[98]=Ue):Ue=e[98];let _e;e[99]!==j||e[100]!==h||e[101]!==Ue?(_e=t.jsx(St,{checked:h,onChange:j,ariaLabel:Ue}),e[99]=j,e[100]=h,e[101]=Ue,e[102]=_e):_e=e[102];let Ke;e[103]!==Fe||e[104]!==_e?(Ke=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[Fe,_e]}),e[103]=Fe,e[104]=_e,e[105]=Ke):Ke=e[105];let qe;e[106]!==se||e[107]!==Pe||e[108]!==Ke||e[109]!==R?(qe=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[R,se,Pe,Ke]}),e[106]=se,e[107]=Pe,e[108]=Ke,e[109]=R,e[110]=qe):qe=e[110];let ce;e[111]!==n||e[112]!==r||e[113]!==i||e[114]!==o||e[115]!==a?(ce=on.map(je=>{const Ee=r.find(Ie=>Ie.providerId===je.id),Se=Qf(Ee?.usage),Ve=Ml(Se),Z=je.id===i,y=Ee?.configured??!1,ue=y?Ve==="critical"?{backgroundColor:"var(--status-error)"}:Ve==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return t.jsx("div",{className:le("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",Z?"bg-interactive-selection":"hover:bg-interactive-hover"),children:t.jsxs("button",{type:"button",onClick:()=>{o(je.id),n?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:ue}),t.jsx(Tn,{providerId:je.id,className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:je.name}),!y&&t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:a("settings.usage.sidebar.status.notSet")})]})},je.id)}),e[111]=n,e[112]=r,e[113]=i,e[114]=o,e[115]=a,e[116]=ce):ce=e[116];let G;e[117]!==ce?(G=t.jsx(qt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:ce}),e[117]=ce,e[118]=G):G=e[118];let pe;return e[119]!==qe||e[120]!==G?(pe=t.jsxs("div",{className:P,children:[qe,G]}),e[119]=qe,e[120]=G,e[121]=pe):pe=e[121],pe};function Xf(s){return s.results}function Zf(s){return s.selectedProviderId}function ex(s){return s.setSelectedProvider}function tx(s){return s.fetchAllQuotas}function sx(s){return s.isLoading}function nx(s){return s.autoRefresh}function ax(s){return s.refreshIntervalMs}function rx(s){return s.displayMode}function ix(s){return s.setAutoRefresh}function ox(s){return s.setRefreshInterval}function lx(s){return s.setDisplayMode}function cx(s){return s.showPredValues}function dx(s){return s.setShowPredValues}function mx(s){return s.loadSettings}async function ux(s){try{await Ct(s)}catch(e){console.warn("Failed to save usage settings:",e)}}const px=s=>{const e=st.c(20),{percent:n,tonePercent:a,className:r,expectedMarkerPercent:i}=s;let o;e[0]!==n?(o=om(n)??0,e[0]=n,e[1]=o):o=e[1];const d=o,c=a??n;let f;e[2]!==c?(f=Ml(c),e[2]=c,e[3]=f):f=e[3];const u=f,p=i!=null?Math.max(0,Math.min(100,i)):null;let m;e[4]!==u?(m=u==="critical"?{backgroundColor:"var(--status-error)"}:u==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=u,e[5]=m):m=e[5];const I=m;let g;e[6]!==r?(g=le("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=g):g=e[7];const h=`${d}%`;let x;e[8]!==I||e[9]!==h?(x={...I,width:h},e[8]=I,e[9]=h,e[10]=x):x=e[10];let E;e[11]!==d||e[12]!==x?(E=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]=E):E=e[13];let S;e[14]!==p?(S=p!=null&&p>0&&p<100&&t.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${p}%`},title:`Expected usage if spread evenly: ${Math.round(p)}% of quota`,"aria-hidden":"true"}),e[14]=p,e[15]=S):S=e[15];let C;return e[16]!==g||e[17]!==E||e[18]!==S?(C=t.jsxs("div",{className:g,children:[E,S]}),e[16]=g,e[17]=E,e[18]=S,e[19]=C):C=e[19],C},gx=s=>{const e=st.c(67),{paceInfo:n,className:a,compact:r}=s,i=r===void 0?!1:r,{t:o}=ot();let d;e[0]!==n.status?(d=lm(n.status),e[0]=n.status,e[1]=d):d=e[1];const c=d;let f;e:{switch(n.status){case"on-track":{let b;e[2]!==o?(b=o("settings.usage.pace.status.onTrack"),e[2]=o,e[3]=b):b=e[3],f=b;break e}case"slightly-fast":{let b;e[4]!==o?(b=o("settings.usage.pace.status.slightlyFast"),e[4]=o,e[5]=b):b=e[5],f=b;break e}case"too-fast":{let b;e[6]!==o?(b=o("settings.usage.pace.status.tooFast"),e[6]=o,e[7]=b):b=e[7],f=b;break e}case"exhausted":{let b;e[8]!==o?(b=o("settings.usage.pace.status.usedUp"),e[8]=o,e[9]=b):b=e[9],f=b;break e}}f=void 0}const u=f;let p;e[10]!==n.predictText||e[11]!==o?(p=o("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=o,e[12]=p):p=e[12];const m=p;if(i){let b;e[13]!==a?(b=le("flex items-center gap-1.5",a),e[13]=a,e[14]=b):b=e[14];let D;e[15]!==c?(D={backgroundColor:c},e[15]=c,e[16]=D):D=e[16];let U;e[17]!==u||e[18]!==D?(U=t.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:D,title:u}),e[17]=u,e[18]=D,e[19]=U):U=e[19];let T;e[20]!==c?(T={color:c},e[20]=c,e[21]=T):T=e[21];const F=n.isExhausted?void 0:m;let j;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==o?(j=n.isExhausted?t.jsx(t.Fragment,{children:o("settings.usage.pace.wait",{duration:yi(n.remainingSeconds)})}):t.jsx(t.Fragment,{children:o("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=o,e[26]=j):j=e[26];let P;e[27]!==j||e[28]!==T||e[29]!==F?(P=t.jsx("span",{className:"typography-micro tabular-nums",style:T,title:F,children:j}),e[27]=j,e[28]=T,e[29]=F,e[30]=P):P=e[30];let O;return e[31]!==P||e[32]!==b||e[33]!==U?(O=t.jsxs("div",{className:b,children:[U,P]}),e[31]=P,e[32]=b,e[33]=U,e[34]=O):O=e[34],O}let I;e[35]!==a?(I=le("flex items-center justify-between gap-2",a),e[35]=a,e[36]=I):I=e[36];let g;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==o?(g=!n.isExhausted&&t.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=o,e[40]=g):g=e[40];let h;e[41]!==g?(h=t.jsx("div",{className:"flex items-center gap-1.5",children:g}),e[41]=g,e[42]=h):h=e[42];let x;e[43]!==c?(x={color:c},e[43]=c,e[44]=x):x=e[44];let E;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==m||e[49]!==u||e[50]!==o?(E=n.isExhausted?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"font-medium",children:u}),t.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.waitSeparator")}),t.jsx("span",{className:"font-medium",children:yi(n.remainingSeconds)})]}):t.jsxs("span",{title:m,children:[t.jsx("span",{className:"text-muted-foreground",children:o("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]=m,e[49]=u,e[50]=o,e[51]=E):E=e[51];let S;e[52]!==x||e[53]!==E?(S=t.jsx("span",{className:"typography-micro tabular-nums",style:x,children:E}),e[52]=x,e[53]=E,e[54]=S):S=e[54];let C;e[55]!==c?(C={backgroundColor:c},e[55]=c,e[56]=C):C=e[56];let M;e[57]!==u||e[58]!==C?(M=t.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:C,title:u}),e[57]=u,e[58]=C,e[59]=M):M=e[59];let k;e[60]!==S||e[61]!==M?(k=t.jsxs("div",{className:"flex items-center gap-1.5",children:[S,M]}),e[60]=S,e[61]=M,e[62]=k):k=e[62];let v;return e[63]!==k||e[64]!==I||e[65]!==h?(v=t.jsxs("div",{className:I,children:[h,k]}),e[63]=k,e[64]=I,e[65]=h,e[66]=v):v=e[66],v},pr=s=>{const e=st.c(54),{title:n,window:a,subtitle:r,showToggle:i,toggleEnabled:o,onToggle:d}=s,c=i===void 0?!1:i,f=o===void 0?!1:o,u=Vt(hx),p=Vt(fx),m=Le(xx),I=u==="remaining"?a.remainingPercent:a.usedPercent,g=u==="remaining"?"remaining":"used";let h;e[0]!==I||e[1]!==a.valueLabel?(h=cm(a.valueLabel,I),e[0]=I,e[1]=a.valueLabel,e[2]=h):h=e[2];const x=h,E=a.resetAfterFormatted??a.resetAtFormatted;let S;e[3]!==E||e[4]!==m||e[5]!==a.resetAt?(S=dm(a.resetAt,E,m),e[3]=E,e[4]=m,e[5]=a.resetAt,e[6]=S):S=e[6];const C=S;let M;e[7]!==n?(M=mm(n),e[7]=n,e[8]=M):M=e[8];const k=M;let v;e[9]!==n||e[10]!==a.resetAt||e[11]!==a.usedPercent||e[12]!==a.windowSeconds?(v=um(a.usedPercent,a.resetAt,a.windowSeconds,n),e[9]=n,e[10]=a.resetAt,e[11]=a.usedPercent,e[12]=a.windowSeconds,e[13]=v):v=e[13];const b=v;let D;e:{if(!b||b.dailyAllocationPercent===null){D=null;break e}const $=pm(b.elapsedRatio);D=u==="remaining"?100-$:$}const U=D;let T;e[14]!==d||e[15]!==c||e[16]!==f?(T=c&&t.jsx(St,{checked:f,onChange:$=>d?.($),ariaLabel:"Show in dropdown"}),e[14]=d,e[15]=c,e[16]=f,e[17]=T):T=e[17];let F;e[18]!==k?(F=t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k}),e[18]=k,e[19]=F):F=e[19];let j;e[20]!==r?(j=r&&t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[20]=r,e[21]=j):j=e[21];let P;e[22]!==F||e[23]!==j?(P=t.jsxs("div",{className:"min-w-0 flex flex-col",children:[F,j]}),e[22]=F,e[23]=j,e[24]=P):P=e[24];let O;e[25]!==P||e[26]!==T?(O=t.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[T,P]}),e[25]=P,e[26]=T,e[27]=O):O=e[27];const R=x==="-"?"":x;let V;e[28]!==R?(V=t.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:R}),e[28]=R,e[29]=V):V=e[29];let B;e[30]!==O||e[31]!==V?(B=t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[O,V]}),e[30]=O,e[31]=V,e[32]=B):B=e[32];let ee;e[33]!==I||e[34]!==U||e[35]!==a.usedPercent?(ee=t.jsx(px,{percent:I,tonePercent:a.usedPercent,expectedMarkerPercent:U,className:"h-1.5"}),e[33]=I,e[34]=U,e[35]=a.usedPercent,e[36]=ee):ee=e[36];const Y=C?`Resets ${C}`:"";let w;e[37]!==Y?(w=t.jsx("span",{className:"typography-micro text-muted-foreground",children:Y}),e[37]=Y,e[38]=w):w=e[38];let H;e[39]!==g?(H=t.jsx("span",{className:"typography-micro text-muted-foreground",children:g}),e[39]=g,e[40]=H):H=e[40];let Q;e[41]!==w||e[42]!==H?(Q=t.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[w,H]}),e[41]=w,e[42]=H,e[43]=Q):Q=e[43];let z;e[44]!==ee||e[45]!==Q?(z=t.jsxs("div",{className:"mt-2.5",children:[ee,Q]}),e[44]=ee,e[45]=Q,e[46]=z):z=e[46];let L;e[47]!==b||e[48]!==p?(L=b&&p&&t.jsx("div",{className:"mt-1.5",children:t.jsx(gx,{paceInfo:b})}),e[47]=b,e[48]=p,e[49]=L):L=e[49];let X;return e[50]!==B||e[51]!==z||e[52]!==L?(X=t.jsxs("div",{className:"py-3",children:[B,z,L]}),e[50]=B,e[51]=z,e[52]=L,e[53]=X):X=e[53],X};function hx(s){return s.displayMode}function fx(s){return s.showPredValues}function xx(s){return s.timeFormatPreference}const bx=(s,e)=>{if(!s)return"-";try{return Rl(s,e,{fallback:"-"})}catch{return"-"}},yx=()=>{const{t:s}=ot(),e=Le(P=>P.timeFormatPreference),n=Vt(P=>P.results),a=Vt(P=>P.selectedProviderId),r=Vt(P=>P.setSelectedProvider),i=Vt(P=>P.loadSettings),o=Vt(P=>P.fetchAllQuotas),d=Vt(P=>P.isLoading),c=Vt(P=>P.lastUpdated),f=Vt(P=>P.error),u=Vt(P=>P.dropdownProviderIds),p=Vt(P=>P.setDropdownProviderIds),m=Vt(P=>P.selectedModels),I=Vt(P=>P.toggleModelSelected),g=Vt(P=>P.applyDefaultSelections);Wf(),l.useEffect(()=>{i(),o()},[i,o]),l.useEffect(()=>{if(a||n.length===0)return;const P=n.find(O=>O.configured)?.providerId;r(P??on[0]?.id??null)},[n,a,r]);const h=n.find(P=>P.providerId===a)??null,E=on.find(P=>P.id===a)?.name??a??s("settings.usage.sidebar.title"),S=h?.usage,C=a?u.includes(a):!1,M=l.useCallback(P=>{if(!a)return;const O=P?Array.from(new Set([...u,a])):u.filter(R=>R!==a);p(O),Ct({usageDropdownProviders:O})},[u,a,p]),k=l.useMemo(()=>S?.models?Object.entries(S.models).map(([P,O])=>({name:P,windows:O})).filter(P=>Object.keys(P.windows.windows).length>0):[],[S?.models]);l.useEffect(()=>{a&&k.length>0&&g(a,k.map(P=>P.name))},[a,k,g]);const v=l.useMemo(()=>!a||k.length===0?new Map:Vf(k,P=>P.name,a),[k,a]),b=l.useMemo(()=>{if(!a)return[];const P=$f(a);return Bf(P)},[a]),[D,U]=l.useState(()=>({})),T=l.useCallback(P=>{U(O=>({...O,[P]:!O[P]}))},[]),F=l.useCallback(P=>{if(!a)return;I(a,P);const O=m[a]??[],V=O.includes(P)?O.filter(ee=>ee!==P):[...O,P],B={...m,[a]:V};Ct({usageSelectedModels:B})},[a,m,I]),j=a?m[a]??[]:[];return a?t.jsx(qt,{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(Tn,{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:E})}),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:bx(c,e)})})]})]}),t.jsx("div",{"data-settings-item":"usage.header-menu",className:"mb-8 px-2",children:t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":C,onClick:()=>M(!C),onKeyDown:P=>{(P.key===" "||P.key==="Enter")&&(P.preventDefault(),M(!C))},children:[t.jsx(St,{checked:C,onChange:M,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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:s("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!h&&t.jsx("div",{className:"mb-8 px-2",children:t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.usage.page.state.noData")})}),f&&t.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[t.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:s("settings.usage.page.state.refreshFailedTitle")}),t.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:f})]}),h&&!h.configured&&t.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[t.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:s("settings.usage.page.state.providerNotConfiguredTitle")}),t.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:s("settings.usage.page.state.providerNotConfiguredDescription")})]}),S?.windows&&Object.keys(S.windows).length>0&&t.jsx("div",{"data-settings-item":"usage.model-quotas",className:"mb-8",children:t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(S.windows).map(([P,O])=>t.jsx(pr,{title:P,window:O},P))})})}),k.length>0&&t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.usage.page.section.modelQuotas")})}),t.jsxs("div",{className:"space-y-3",children:[b.map(P=>{const O=v.get(P.id)??[];if(O.length===0)return null;const R=D[P.id]??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(bn,{open:!R,onOpenChange:()=>T(P.id),children:[t.jsxs(yn,{className:"flex w-full items-center justify-between py-0.5 group",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[t.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:P.label}),t.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",O.length,")"]})]}),R?t.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(vn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:O.map(V=>{const B=Object.entries(V.windows.windows);if(B.length===0)return null;const[ee,Y]=B[0],w=j.includes(V.name);return t.jsx(pr,{title:ee,subtitle:zo(V.name),window:Y,showToggle:!0,toggleEnabled:w,onToggle:()=>F(V.name)},V.name)})})})]})},P.id)}),(()=>{const P=v.get(null)??[];if(P.length===0)return null;const O=D.other??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(bn,{open:!O,onOpenChange:()=>T("other"),children:[t.jsxs(yn,{className:"flex w-full items-center justify-between py-0.5 group",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[t.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:s("settings.usage.page.section.otherModels")}),t.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",P.length,")"]})]}),O?t.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(vn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:P.map(R=>{const V=Object.entries(R.windows.windows);if(V.length===0)return null;const[B,ee]=V[0],Y=j.includes(R.name);return t.jsx(pr,{title:B,subtitle:zo(R.name),window:ee,showToggle:!0,toggleEnabled:Y,onToggle:()=>F(R.name)},R.name)})})})]})})})()]})]}),h?.configured&&S&&Object.keys(S.windows??{}).length===0&&k.length===0&&t.jsxs("div",{className:"mb-8 px-2",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.usage.page.state.noQuotaWindowsTitle")}),t.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:s("settings.usage.page.state.noQuotaWindowsDescription")})]})]})}):t.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:t.jsx("p",{className:"typography-body",children:s("settings.usage.page.empty.selectProvider")})})},vx="git.commit.generate",_r=ln(s=>({selectedPromptId:vx,setSelectedPromptId:e=>{s(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),jx=s=>{const e=st.c(23),{onItemSelect:n}=s,{t:a}=ot(),r=_r(wx),i=_r(Nx);let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={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]=o):o=e[0];let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=d):d=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=c):c=e[2];let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=[o,d,c,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=f):f=e[3];const u=f;let p;e[4]!==a?(p=a("settings.magicPrompts.sidebar.title"),e[4]=a,e[5]=p):p=e[5];let m;e[6]!==p?(m=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:p}),e[6]=p,e[7]=m):m=e[7];let I;e[8]!==a?(I=a("settings.magicPrompts.sidebar.description"),e[8]=a,e[9]=I):I=e[9];let g;e[10]!==I?(g=t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:I}),e[10]=I,e[11]=g):g=e[11];let h;e[12]!==m||e[13]!==g?(h=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[m,g]}),e[12]=m,e[13]=g,e[14]=h):h=e[14];let x;e[15]!==n||e[16]!==r||e[17]!==i||e[18]!==a?(x=t.jsx(qt,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:u.map(S=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:a(S.groupKey)}),S.items.map(C=>{const M=r===C.id;return t.jsx("button",{type:"button",onClick:()=>{i(C.id),n?.()},className:le("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",M?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-ui-label truncate font-normal",children:a(C.titleKey)})},C.id)})]},S.groupKey))}),e[15]=n,e[16]=r,e[17]=i,e[18]=a,e[19]=x):x=e[19];let E;return e[20]!==x||e[21]!==h?(E=t.jsxs("div",{className:"flex h-full flex-col bg-background",children:[h,x]}),e[20]=x,e[21]=h,e[22]=E):E=e[22],E};function wx(s){return s.selectedPromptId}function Nx(s){return s.setSelectedPromptId}const Uo={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},$o=(s,e)=>Object.prototype.hasOwnProperty.call(s,e),gr=s=>s.endsWith(".visible"),kx=()=>{const{t:s}=ot(),e=l.useCallback(v=>s(v),[s]),n=_r(v=>v.selectedPromptId),[a,r]=l.useState(!0),[i,o]=l.useState({}),[d,c]=l.useState({}),[f,u]=l.useState({}),[p,m]=l.useState({}),[I,g]=l.useState(!1);l.useEffect(()=>{let v=!0;return(async()=>{r(!0);try{const D=await xm();if(!v)return;o(D)}catch(D){console.warn("Failed to load magic prompts:",D),q.error(s("settings.magicPrompts.page.toast.loadFailed"))}finally{v&&r(!1)}})(),()=>{v=!1}},[s]);const h=Uo[n]??Uo["git.commit.generate"],x=l.useCallback(v=>$o(i,v)?i[v]:Qa(v),[i]),E=l.useCallback(v=>d[v]??x(v),[d,x]),S=l.useCallback((v,b)=>{c(D=>D[v]===b?D:{...D,[v]:b})},[]),C=l.useCallback(async v=>{const b=E(v);if(gr(v)&&b.trim().length===0){q.error(s("settings.magicPrompts.page.toast.visiblePromptRequired"));return}u(D=>({...D,[v]:!0}));try{const D=b===Qa(v)?await vi(v):await gm(v,b);o(D.overrides),q.success(s("settings.magicPrompts.page.toast.saved"))}catch(D){const U=D instanceof Error?D.message:String(D);q.error(s("settings.magicPrompts.page.toast.saveFailed"),{description:U})}finally{u(D=>({...D,[v]:!1}))}},[E,s]),M=l.useCallback(async v=>{m(b=>({...b,[v]:!0}));try{const b=await vi(v);o(b.overrides),c(D=>({...D,[v]:Qa(v)})),q.success(s("settings.magicPrompts.page.toast.resetSuccess"))}catch(b){const D=b instanceof Error?b.message:String(b);q.error(s("settings.magicPrompts.page.toast.resetFailed"),{description:D})}finally{m(b=>({...b,[v]:!1}))}},[s]),k=l.useCallback(async()=>{g(!0);try{const v=await hm();o(v.overrides),c({}),q.success(s("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(v){const b=v instanceof Error?v.message:String(v);q.error(s("settings.magicPrompts.page.toast.resetAllFailed"),{description:b})}finally{g(!1)}},[s]);return a?t.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[t.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":s("settings.magicPrompts.page.loading.aria")}),t.jsx("span",{className:"typography-ui",children:s("settings.magicPrompts.page.loading.text")})]}):t.jsx("div",{className:"h-full overflow-auto",children:t.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[t.jsx("div",{className:"space-y-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(h.titleKey)}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:e(h.descriptionKey)})]})]})}),t.jsx(J,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{k()},disabled:I||Object.keys(i).length===0,children:s(I?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),h.blocks.map((v,b)=>{const D=fm(v.id),U=x(v.id),T=E(v.id),F=$o(i,v.id),j=T!==U,P=gr(v.id)&&T.trim().length===0,O=f[v.id]===!0,R=p[v.id]===!0;return t.jsxs("section",{"data-settings-item":gr(v.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",className:b>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:e(v.titleKey)}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:D.description})]})]}),D.placeholders&&D.placeholders.length>0&&t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[s("settings.magicPrompts.page.placeholdersLabel")," ",D.placeholders.map(V=>`{{${V.key}}}`).join(", ")]})]}),t.jsx(hs,{value:T,onChange:V=>S(v.id,V.target.value),className:"min-h-[220px] font-mono text-sm"}),P&&t.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:s("settings.magicPrompts.page.validation.visiblePromptRequired")}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s(j?"settings.magicPrompts.page.status.unsavedChanges":F?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>{M(v.id)},disabled:!F||O||R,children:s(R?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),t.jsx(J,{size:"sm",onClick:()=>{C(v.id)},disabled:!j||O||R||P,children:s(O?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},v.id)})]})})},Sx=s=>{const e=st.c(89),{onItemSelect:n}=s,{t:a}=ot(),[r,i]=l.useState(null),[o,d]=l.useState(null),[c,f]=l.useState(null),{selectedSnippetName:u,snippets:p,setSelectedSnippet:m,setSnippetDraft:I,deleteSnippet:g,loadSnippets:h}=_a(Ps(Cx));let x,E;e[0]!==h?(x=()=>{h()},E=[h],e[0]=h,e[1]=x,e[2]=E):(x=e[1],E=e[2]),l.useEffect(x,E);let S;e[3]!==n||e[4]!==m||e[5]!==I||e[6]!==p?(S=async()=>{const se=new Set(p.map(Px));let de="new-snippet",be=1;for(;se.has(de);)de=`new-snippet-${be++}`;I({name:de,scope:"global"}),m(de),n?.()},e[3]=n,e[4]=m,e[5]=I,e[6]=p,e[7]=S):S=e[7];const C=S;let M;e[8]!==r||e[9]!==g||e[10]!==a?(M=async()=>{if(!r)return;await g(r.name)?(q.success(a("settings.snippets.sidebar.toast.deleted")),i(null)):q.error(a("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=g,e[10]=a,e[11]=M):M=e[11];const k=M;let v;e[12]!==p?(v=[...p].sort(Ix),e[12]=p,e[13]=v):v=e[13];const b=v;let D;e[14]===Symbol.for("react.memo_cache_sentinel")?(D=le("flex h-full flex-col","bg-background"),e[14]=D):D=e[14];let U;e[15]!==a?(U=a("settings.snippets.sidebar.title"),e[15]=a,e[16]=U):U=e[16];let T;e[17]!==U?(T=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:U}),e[17]=U,e[18]=T):T=e[18];let F;e[19]!==p.length||e[20]!==a?(F=a("settings.snippets.sidebar.total",{count:p.length}),e[19]=p.length,e[20]=a,e[21]=F):F=e[21];let j;e[22]!==F?(j=t.jsx("span",{className:"typography-meta text-muted-foreground",children:F}),e[22]=F,e[23]=j):j=e[23];let P;e[24]!==a?(P=a("settings.snippets.sidebar.actions.create"),e[24]=a,e[25]=P):P=e[25];let O;e[26]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[26]=O):O=e[26];let R;e[27]!==C||e[28]!==P?(R=t.jsx(J,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:C,"aria-label":P,children:O}),e[27]=C,e[28]=P,e[29]=R):R=e[29];let V;e[30]!==j||e[31]!==R?(V=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,R]}),e[30]=j,e[31]=R,e[32]=V):V=e[32];let B;e[33]!==V||e[34]!==T?(B=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,V]}),e[33]=V,e[34]=T,e[35]=B):B=e[35];let ee;if(e[36]!==n||e[37]!==o||e[38]!==c||e[39]!==u||e[40]!==m||e[41]!==b||e[42]!==a){let se;e[44]!==n||e[45]!==o||e[46]!==c||e[47]!==u||e[48]!==m||e[49]!==a?(se=de=>t.jsxs(sn,{open:c===de.name,onOpenChange:be=>f(be?de.name:null),children:[t.jsxs(nn,{render:t.jsx("div",{className:le("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",u===de.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:be=>{be.preventDefault(),f(de.name)}}),children:[t.jsxs("button",{onClick:()=>{m(de.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:["#",de.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.${de.source}`)})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:de.description||de.content.replace(/\s+/g," ").substring(0,80)})]}),t.jsxs(gs,{open:o===de.name,onOpenChange:be=>{be&&f(null),d(be?de.name:null)},children:[t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100","aria-label":a("settings.snippets.sidebar.actions.more",{name:de.name}),children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:t.jsxs(ws,{onClick:be=>{be.stopPropagation(),i(de)},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]})]}),t.jsx(an,{className:"w-fit min-w-20",children:t.jsxs(qs,{onClick:be=>{be.stopPropagation(),i(de)},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]},`${de.source}:${de.filePath}`),e[44]=n,e[45]=o,e[46]=c,e[47]=u,e[48]=m,e[49]=a,e[50]=se):se=e[50],ee=b.map(se),e[36]=n,e[37]=o,e[38]=c,e[39]=u,e[40]=m,e[41]=b,e[42]=a,e[43]=ee}else ee=e[43];let Y;e[51]!==ee?(Y=t.jsx(qt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:ee}),e[51]=ee,e[52]=Y):Y=e[52];const w=r!==null;let H;e[53]===Symbol.for("react.memo_cache_sentinel")?(H=se=>{se||i(null)},e[53]=H):H=e[53];let Q;e[54]!==a?(Q=a("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=a,e[55]=Q):Q=e[55];let z;e[56]!==Q?(z=t.jsx($t,{children:Q}),e[56]=Q,e[57]=z):z=e[57];const L=r?.name??"";let X;e[58]!==a||e[59]!==L?(X=a("settings.snippets.sidebar.dialog.deleteDescription",{name:L}),e[58]=a,e[59]=L,e[60]=X):X=e[60];let $;e[61]!==X?($=t.jsx(Ht,{children:X}),e[61]=X,e[62]=$):$=e[62];let ne;e[63]!==z||e[64]!==$?(ne=t.jsxs(Bt,{children:[z,$]}),e[63]=z,e[64]=$,e[65]=ne):ne=e[65];let re;e[66]===Symbol.for("react.memo_cache_sentinel")?(re=()=>i(null),e[66]=re):re=e[66];let _;e[67]!==a?(_=a("settings.common.actions.cancel"),e[67]=a,e[68]=_):_=e[68];let oe;e[69]!==_?(oe=t.jsx(J,{size:"sm",variant:"ghost",onClick:re,children:_}),e[69]=_,e[70]=oe):oe=e[70];let fe;e[71]!==a?(fe=a("settings.common.actions.delete"),e[71]=a,e[72]=fe):fe=e[72];let xe;e[73]!==k||e[74]!==fe?(xe=t.jsx(J,{size:"sm",onClick:k,children:fe}),e[73]=k,e[74]=fe,e[75]=xe):xe=e[75];let Ce;e[76]!==oe||e[77]!==xe?(Ce=t.jsxs(Zt,{children:[oe,xe]}),e[76]=oe,e[77]=xe,e[78]=Ce):Ce=e[78];let ve;e[79]!==ne||e[80]!==Ce?(ve=t.jsxs(Ut,{className:"max-w-md",children:[ne,Ce]}),e[79]=ne,e[80]=Ce,e[81]=ve):ve=e[81];let we;e[82]!==w||e[83]!==ve?(we=t.jsx(Kt,{open:w,onOpenChange:H,children:ve}),e[82]=w,e[83]=ve,e[84]=we):we=e[84];let ye;return e[85]!==B||e[86]!==Y||e[87]!==we?(ye=t.jsxs("div",{className:D,children:[B,Y,we]}),e[85]=B,e[86]=Y,e[87]=we,e[88]=ye):ye=e[88],ye};function Cx(s){return{selectedSnippetName:s.selectedSnippetName,snippets:s.snippets,setSelectedSnippet:s.setSelectedSnippet,setSnippetDraft:s.setSnippetDraft,deleteSnippet:s.deleteSnippet,loadSnippets:s.loadSnippets}}function Px(s){return s.name}function Ix(s,e){return s.name.localeCompare(e.name)}const Dx=()=>{const{t:s}=ot(),{selectedSnippetName:e,snippets:n,snippetDraft:a,setSnippetDraft:r,updateSnippet:i,createSnippet:o}=_a(Ps(D=>({selectedSnippetName:D.selectedSnippetName,snippets:D.snippets,snippetDraft:D.snippetDraft,setSnippetDraft:D.setSnippetDraft,updateSnippet:D.updateSnippet,createSnippet:D.createSnippet}))),d=l.useMemo(()=>e?n.find(D=>D.name===e||D.aliases.includes(e))??null:null,[e,n]),c=!!(a&&a.name===e&&!d),[f,u]=l.useState(""),[p,m]=l.useState("global"),[I,g]=l.useState(""),[h,x]=l.useState(""),[E,S]=l.useState(""),[C,M]=l.useState(!1),k=l.useRef(null);l.useEffect(()=>{if(c&&a){const D={draftName:a.name||"",draftScope:a.scope||"global",description:a.description||"",aliases:(a.aliases||[]).join(", "),content:a.content||""};u(D.draftName),m(D.draftScope),g(D.description),x(D.aliases),S(D.content),k.current=D}else if(d){const D={draftName:"",draftScope:"global",description:d.description??"",aliases:d.aliases.join(", "),content:d.content};g(D.description),x(D.aliases),S(D.content),k.current=D}},[d,c,e,a]);const v=l.useMemo(()=>{const D=k.current;return D?c&&f!==D.draftName||c&&p!==D.draftScope?!0:I!==D.description||h!==D.aliases||E!==D.content:!1},[h,E,I,f,p,c]),b=async()=>{const D=c?f.trim().replace(/\s+/g,"-"):e?.trim();if(!D){q.error(s("settings.snippets.page.toast.nameRequired"));return}if(!E.trim()){q.error(s("settings.snippets.page.toast.contentRequired"));return}const U=h.split(",").map(T=>T.trim()).filter(Boolean);M(!0);try{if(!(c?await o(D,E,{aliases:U,description:I,scope:p}):await i(D,{content:E,aliases:U,description:I}))){q.error(s("settings.snippets.page.toast.saveFailed"));return}q.success(s("settings.snippets.page.toast.saved")),c&&r(null)}finally{M(!1)}};return e?t.jsx(qt,{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(tt,{value:f,onChange:D=>u(D.target.value),placeholder:s("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),t.jsxs(Tt,{value:p,onValueChange:D=>m(D),children:[t.jsx(Ft,{className:"w-fit min-w-[100px]",children:t.jsx(zt,{})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"global",children:s("settings.common.scope.global")}),t.jsx(ht,{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(tt,{value:I,onChange:D=>g(D.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(tt,{value:h,onChange:D=>x(D.target.value),placeholder:s("settings.snippets.page.field.aliasesPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]})]}),t.jsxs("div",{"data-settings-item":"snippets.content",className:"mb-2 px-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.snippets.page.field.content")}),t.jsx(hs,{value:E,onChange:D=>S(D.target.value),placeholder:s("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),t.jsx("p",{className:"mt-2 typography-meta text-muted-foreground",children:s("settings.snippets.page.hint")})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:b,disabled:C||!v,size:"xs",className:"!font-normal",children:s(C?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{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")})]})})},sc=()=>{const{t:s}=ot(),e=lt(p=>p.settingsGitmojiEnabled),n=lt(p=>p.setSettingsGitmojiEnabled),a=Zm(),r=Le(p=>p.gitChangesViewMode),i=Le(p=>p.setGitChangesViewMode),[o,d]=l.useState(!0),c=l.useMemo(()=>[{id:"flat",label:s("settings.openchamber.git.option.flatList")},{id:"tree",label:s("settings.openchamber.git.option.treeView")}],[s]);l.useEffect(()=>{(async()=>{try{let m=null;if(!m){const I=Os()?.settings;if(I)try{const h=(await I.load())?.settings;h&&(m={gitmojiEnabled:typeof h.gitmojiEnabled=="boolean"?h.gitmojiEnabled:void 0,gitChangesViewMode:h.gitChangesViewMode==="flat"||h.gitChangesViewMode==="tree"?h.gitChangesViewMode:void 0})}catch{}}if(!m){const I=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});I.ok&&(m=await I.json())}m&&(typeof m.gitmojiEnabled=="boolean"&&n(m.gitmojiEnabled),(m.gitChangesViewMode==="flat"||m.gitChangesViewMode==="tree")&&i(m.gitChangesViewMode))}catch(m){console.warn("Failed to load git settings:",m)}finally{d(!1)}})()},[i,n]);const f=l.useCallback(async p=>{n(p);try{await Ct({gitmojiEnabled:p})}catch(m){console.warn("Failed to save gitmoji setting:",m)}},[n]),u=l.useCallback(p=>{p!==r&&(i(p),Ct({gitChangesViewMode:p}))},[r,i]);return o?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 m=r===p.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>{u(p.id)},onKeyDown:I=>{(I.key===" "||I.key==="Enter")&&(I.preventDefault(),u(p.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:m,onChange:()=>{u(p.id)},ariaLabel:s("settings.openchamber.git.optionAria",{option:p.label})}),t.jsx("span",{className:m?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:p.label})]},p.id)})})]}),t.jsxs("div",{"data-settings-item":"git.gitmoji",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{f(!e)},onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),f(!e))},children:[t.jsx(St,{checked:e,onChange:p=>{f(p)},ariaLabel:s("settings.openchamber.git.enableGitmojiAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.git.enableGitmoji")})]}),t.jsxs("div",{"data-settings-item":"git.gitignored-files",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":a,onClick:()=>er(!a),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),er(!a))},children:[t.jsx(St,{checked:a,onChange:er,ariaLabel:s("settings.openchamber.git.showGitignoredAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.git.showGitignored")})]})]})]})},nc=()=>{const{t:s}=ot(),{isMobile:e}=Is(),n=Os()?.github,a=_s(j=>j.status),r=_s(j=>j.isLoading),i=_s(j=>j.hasChecked),o=_s(j=>j.refreshStatus),d=_s(j=>j.setStatus),c=l.useCallback(async j=>{await Ws(j)},[]),[f,u]=l.useState(!1),[p,m]=l.useState(null),[I,g]=l.useState(null),h=l.useRef(null),x=l.useCallback(()=>{h.current!=null&&(window.clearInterval(h.current),h.current=null),g(null)},[]);l.useEffect(()=>((async()=>{try{i||await o(n)}catch(j){console.warn("Failed to load GitHub auth status:",j)}})(),()=>{x()}),[i,o,n,x]);const E=l.useCallback(async()=>{u(!0);try{const j=n?await n.authStart():await(async()=>{const O=await pt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),R=await O.json().catch(()=>null);if(!O.ok||!R||!("deviceCode"in R))throw new Error(R?.error||O.statusText);return R})();m(j),g(Math.max(1,j.interval)*1e3);const P=j.verificationUriComplete||j.verificationUri;c(P)}catch(j){console.error("Failed to start GitHub connect:",j),q.error(s("settings.github.page.toast.startConnectFailed"))}finally{u(!1)}},[c,n,s]),S=l.useCallback(async j=>{if(n)return n.authComplete(j);const P=await pt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:j})}),O=await P.json().catch(()=>null);if(!P.ok||!O)throw new Error(O?.error||P.statusText);return O},[n]);l.useEffect(()=>{if(!(!p?.deviceCode||!I)&&h.current==null)return h.current=window.setInterval(()=>{(async()=>{try{const j=await S(p.deviceCode);if(j.connected){q.success(s("settings.github.page.toast.connected")),m(null),x(),await o(n,{force:!0});return}j.status==="slow_down"&&g(P=>P?P+5e3:5e3),(j.status==="expired_token"||j.status==="access_denied")&&(q.error(j.error||s("settings.github.page.toast.authorizationFailed")),m(null),x())}catch(j){console.warn("GitHub polling failed:",j)}})()},I),()=>{h.current!=null&&(window.clearInterval(h.current),h.current=null)}},[p,I,S,o,n,x,s]);const C=l.useCallback(async j=>{u(!0);try{if(n)await n.authSetGhCliDisabled(j);else{const P=await pt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:j})}),O=await P.json().catch(()=>null);if(!P.ok)throw new Error(O?.error||P.statusText)}q.success(s(j?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await o(n,{force:!0})}catch(P){console.error("Failed to update gh CLI setting:",P),q.error(s("settings.github.page.toast.ghCliUpdateFailed"))}finally{u(!1)}},[o,n,s]),M=l.useCallback(async()=>{u(!0);try{if(x(),m(null),n)await n.authDisconnect();else{const j=await pt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!j.ok)throw new Error(j.statusText)}q.success(s("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(j){console.error("Failed to disconnect GitHub:",j),q.error(s("settings.github.page.toast.disconnectFailed"))}finally{u(!1)}},[o,n,x,s]),k=l.useCallback(async j=>{if(j){u(!0);try{const P=n?await n.authActivate(j):await(async()=>{const O=await pt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:j})}),R=await O.json().catch(()=>null);if(!O.ok||!R)throw new Error(R?.error||O.statusText);return R})();d(P),q.success(s("settings.github.page.toast.accountSwitched"))}catch(P){console.error("Failed to switch GitHub account:",P),q.error(s("settings.github.page.toast.accountSwitchFailed"))}finally{u(!1)}}},[n,d,s]);if(r)return null;const v=!!a?.connected,b=a?.user,U=(a?.accounts??[]).filter(j=>!j.current),T=a?.ghCli??null,F=T?.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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:s("settings.github.page.tooltip.connectAccount")})]})]})}),t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[v?t.jsxs("div",{className:le("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:le("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[b?.avatarUrl?t.jsx("img",{src:b.avatarUrl,alt:b.login?s("settings.github.page.avatarAlt.withLogin",{login:b.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:b?.name?.trim()||b?.login||"GitHub"}),t.jsxs("div",{className:le("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[t.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"font-mono",children:b?.login||s("settings.github.page.label.unknownUser")}),b?.email&&t.jsx("span",{className:"opacity-50",children:"•"}),b?.email&&t.jsx("span",{children:b.email}),t.jsx("span",{className:"opacity-50",children:"•"}),t.jsx("span",{children:F})]}),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})}),T?.active&&t.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:s("settings.github.page.ghCli.activeDescription")})]})]}),T?.active?t.jsx(J,{size:"sm",variant:"outline",onClick:()=>C(!0),disabled:f,className:le(e?"w-full":void 0),children:s("settings.github.page.ghCli.actions.disable")}):t.jsx(J,{size:"sm",variant:"outline",onClick:M,disabled:f,className:le("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:s("settings.github.page.actions.disconnect")})]}):t.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[t.jsx("div",{className:"flex min-w-0 flex-col",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.github.page.status.notConnected")})}),t.jsx(J,{size:"sm",variant:"default",onClick:E,disabled:f,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(j=>{const P=j.user,O=j.source==="gh-cli"?s("settings.github.page.accountSource.cli"):s("settings.github.page.accountSource.oauth");return t.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[P?.avatarUrl?t.jsx("img",{src:P.avatarUrl,alt:P.login?s("settings.github.page.avatarAlt.withLogin",{login:P.login}):s("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:t.jsx(A,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),t.jsxs("div",{className:"min-w-0 flex flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:P?.name?.trim()||P?.login||"GitHub"}),P?.login&&t.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[t.jsx("span",{className:"font-mono",children:P.login}),t.jsx("span",{className:"mx-1 opacity-50",children:"·"}),t.jsx("span",{children:O})]})]})]}),t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>k(j.id),disabled:f,children:s("settings.github.page.actions.switchTo")})]},j.id)})})]})]}),v&&t.jsx("div",{className:"mt-2 px-2 pb-2",children:t.jsx(J,{size:"sm",variant:"outline",onClick:E,disabled:f,className:le(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(J,{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(J,{size:"sm",variant:"ghost",disabled:f,onClick:()=>{x(),m(null)},children:s("settings.common.actions.cancel")})]})]}),T?.available&&!T?.active&&(!T.user||T.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:le("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:le("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[T.user?.avatarUrl?t.jsx("img",{src:T.user.avatarUrl,alt:T.user.login?s("settings.github.page.avatarAlt.withLogin",{login:T.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(A,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[!T.disabled&&T.user&&t.jsx("div",{className:"typography-ui-label text-foreground truncate",children:T.user.name?.trim()||T.user.login||"GitHub"}),!T.disabled&&T.user?.login&&t.jsxs("div",{className:le("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[t.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"font-mono",children:T.user.login}),T.user.email&&t.jsx("span",{className:"opacity-50",children:"•"}),T.user.email&&t.jsx("span",{children:T.user.email})]}),t.jsx("div",{className:le("typography-meta text-muted-foreground",T.disabled?"opacity-60":void 0),children:T.disabled?s("settings.github.page.ghCli.disabledDescription"):s("settings.github.page.ghCli.fallbackDescription")})]})]}),t.jsx(J,{size:"sm",variant:"outline",onClick:()=>C(!T.disabled),disabled:f,className:le(e?"w-full":void 0),children:T.disabled?s("settings.github.page.ghCli.actions.enable"):s("settings.github.page.ghCli.actions.disable")})]})})]})]})},Bo=[{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)"}],Ax=[{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"}],Ex=({open:s,onOpenChange:e,profileId:n,importData:a})=>{const{t:r}=ot(),i=Cs($=>$.getProfileById),o=Cs($=>$.createProfile),d=Cs($=>$.updateProfile),c=Cs($=>$.deleteProfile),f=l.useMemo(()=>n&&n!=="new"&&!a?i(n):null,[n,i,a]),u=n==="new"||a!=null,p=n==="global",[m,I]=l.useState(""),[g,h]=l.useState(""),[x,E]=l.useState(""),[S,C]=l.useState("ssh"),[M,k]=l.useState(""),[v,b]=l.useState(!1),[D,U]=l.useState(""),[T,F]=l.useState(""),[j,P]=l.useState("keyword"),[O,R]=l.useState("branch"),[V,B]=l.useState(!1),[ee,Y]=l.useState(!1),[w,H]=l.useState(!1);l.useEffect(()=>{if(s){if(a){const $=a.host.split("/"),ne=$.length>=3?$[$.length-1]:a.host;I(ne),h(a.username),E(""),C("token"),k(""),b(!1),U(""),F(a.host),P("string"),R("code")}else if(u)I(""),h(""),E(""),C("ssh"),k(""),b(!1),U(""),F(""),P("keyword"),R("branch");else if(f)I(f.name),h(f.userName),E(f.userEmail),C(f.authType||"ssh"),k(f.sshKey||""),b(f.signCommits===!0),U(f.signingKey||""),F(f.host||""),P(f.color||"keyword"),R(f.icon||"branch");else if(p){const $=i("global");$&&(I($.name),h($.userName),E($.userEmail),C($.authType||"ssh"),k($.sshKey||""),b(!1),U(""),F($.host||""),P($.color||"keyword"),R($.icon||"branch"))}}},[s,n,f,u,a,p,i]);const Q=async()=>{if(!g.trim()||!x.trim()){q.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(S==="token"&&!T.trim()){q.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(v&&!D.trim()){q.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}B(!0);try{const $={name:m.trim()||g.trim(),userName:g.trim(),userEmail:x.trim(),authType:S,sshKey:S==="ssh"&&M.trim()||null,signCommits:v,signingKey:D.trim()||null,host:S==="token"&&T.trim()||null,color:j,icon:O};let ne;if(u)ne=await o($);else if(n)ne=await d(n,$);else return;ne?(q.success(r(u?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):q.error(r(u?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch($){console.error("Error saving profile:",$),q.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{B(!1)}},z=async()=>{if(!(!n||u)){H(!0);try{await c(n)?(q.success(r("settings.gitIdentities.editor.toast.profileDeleted")),Y(!1),e(!1)):q.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch($){console.error("Error deleting profile:",$),q.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{H(!1)}}},L=l.useMemo(()=>Bo.find(ne=>ne.key===j)?.cssVar||"var(--syntax-keyword)",[j]),X=a?r("settings.gitIdentities.editor.title.importCredential"):u?r("settings.gitIdentities.editor.title.newIdentity"):p?r("settings.gitIdentities.editor.title.globalIdentity"):f?.name||r("settings.gitIdentities.editor.title.editIdentity");return t.jsxs(t.Fragment,{children:[t.jsx(Kt,{open:s,onOpenChange:e,children:t.jsxs(Ut,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:X}),t.jsx(Ht,{children:r(p?"settings.gitIdentities.editor.description.globalReadOnly":u?"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(tt,{value:m,onChange:$=>I($.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:Bo.map($=>t.jsx("button",{type:"button",onClick:()=>P($.key),className:le("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",j===$.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:$.cssVar},title:$.label},$.key))})]}),t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.icon")}),t.jsx("div",{className:"flex gap-1.5",children:Ax.map($=>{const ne=$.Icon;return t.jsx("button",{type:"button",onClick:()=>R($.key),className:le("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",O===$.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:$.label,children:t.jsx(A,{name:ne,className:"w-3.5 h-3.5",style:{color:O===$.key?L:"var(--surface-muted-foreground)"}})},$.key)})})]})]}),!p&&t.jsx("div",{className:"border-t border-border/40"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.userName")}),!p&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),t.jsx(tt,{value:g,onChange:$=>h($.target.value),placeholder:r("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!p,readOnly:p,disabled:p,className:"h-8"})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.emailAddress")}),!p&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),t.jsx(tt,{type:"email",value:x,onChange:$=>E($.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(J,{size:"sm",type:"button",variant:"chip","aria-pressed":S==="ssh",onClick:()=>C("ssh"),children:[t.jsx(A,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),t.jsxs(J,{size:"sm",type:"button",variant:"chip","aria-pressed":S==="token",onClick:()=>C("token"),children:[t.jsx(A,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.gitIdentities.editor.field.authToken")]})]})]}),S==="ssh"&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.sshKeyPath")}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),t.jsx(tt,{value:M,onChange:$=>k($.target.value),placeholder:r("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),t.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(St,{checked:v,onChange:b,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(tt,{value:D,onChange:$=>U($.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!v,className:"h-8 font-mono text-xs"})]})]}),S==="token"&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.host")}),t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]})]}),t.jsx(tt,{value:T,onChange:$=>F($.target.value),placeholder:r("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),t.jsxs(Zt,{className:"gap-2",children:[!p&&!u&&t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>Y(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[t.jsx(A,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.common.actions.delete")]}),t.jsx(J,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:r(p?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!p&&t.jsx(J,{size:"sm",onClick:Q,disabled:V,children:r(V?"settings.common.actions.saving":u?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),t.jsx(Kt,{open:ee,onOpenChange:$=>{w||Y($)},children:t.jsxs(Ut,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:r("settings.gitIdentities.page.deleteDialog.title")}),t.jsx(Ht,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:f?.name||m})})]}),t.jsxs(Zt,{children:[t.jsx(J,{variant:"ghost",onClick:()=>Y(!1),disabled:w,children:r("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",variant:"destructive",onClick:()=>{z()},disabled:w,children:r("settings.common.actions.delete")})]})]})})]})},Mx={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},Rx={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},Tx=()=>{const s=st.c(118),{t:e}=ot(),{profiles:n,globalIdentity:a,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:o,loadGlobalIdentity:d,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:f,setDefaultGitIdentityId:u,getUnimportedCredentials:p}=Cs(Ps(Lx)),[m,I]=l.useState(!1),[g,h]=l.useState(null),[x,E]=l.useState(null),[S,C]=l.useState(null),[M,k]=l.useState(!1);let v,b;s[0]!==f||s[1]!==c||s[2]!==d||s[3]!==o?(v=()=>{o(),d(),c(),f()},b=[o,d,c,f],s[0]=f,s[1]=c,s[2]=d,s[3]=o,s[4]=v,s[5]=b):(v=s[4],b=s[5]),l.useEffect(v,b);let D,U,T,F,j,P,O,R,V,B,ee,Y,w,H;if(s[6]!==r||s[7]!==S||s[8]!==i||s[9]!==p||s[10]!==a||s[11]!==n||s[12]!==u||s[13]!==e){const De=p();let Ae;s[28]===Symbol.for("react.memo_cache_sentinel")?(Ae=(je,Ee)=>{h(je),E(Ee??null),I(!0)},s[28]=Ae):Ae=s[28];const Pe=Ae;let Re;s[29]!==r||s[30]!==u||s[31]!==e?(Re=async je=>{const Ee=r===je?null:je;if(!await u(Ee)){q.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}q.success(e(Ee?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},s[29]=r,s[30]=u,s[31]=e,s[32]=Re):Re=s[32];const Fe=Re;let Ue;s[33]!==S||s[34]!==i||s[35]!==e?(Ue=async()=>{if(!S)return;k(!0),await i(S.id)?(q.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:S.name})),C(null)):q.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),k(!1)},s[33]=S,s[34]=i,s[35]=e,s[36]=Ue):Ue=s[36],U=Ue,D=qt,j="h-full",P="w-full bg-background",T="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")?(F=t.jsx("div",{"data-settings-item":"git.github-account",children:t.jsx(nc,{})}),s[37]=F):F=s[37],Y="git.identities",w="border-t border-border/40 pt-6";let _e;s[38]!==e?(_e=e("settings.gitIdentities.page.section.title"),s[38]=e,s[39]=_e):_e=s[39];let Ke;s[40]!==_e?(Ke=t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:_e})}),s[40]=_e,s[41]=Ke):Ke=s[41];let qe,ce;s[42]===Symbol.for("react.memo_cache_sentinel")?(qe=()=>Pe("new"),ce=t.jsx(A,{name:"add",className:"w-3.5 h-3.5 mr-1"}),s[42]=qe,s[43]=ce):(qe=s[42],ce=s[43]);let G;s[44]!==e?(G=e("settings.common.badge.new"),s[44]=e,s[45]=G):G=s[45];let pe;s[46]!==G?(pe=t.jsxs(J,{size:"sm",variant:"outline",onClick:qe,children:[ce," ",G]}),s[46]=G,s[47]=pe):pe=s[47],s[48]!==Ke||s[49]!==pe?(H=t.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[Ke,pe]}),s[48]=Ke,s[49]=pe,s[50]=H):H=s[50],O="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",R=a&&t.jsx(Vo,{profile:a,isDefault:r==="global",onEdit:()=>Pe("global"),onToggleDefault:()=>Fe("global"),isReadOnly:!0,hasBorder:n.length>0||De.length>0}),V=n.map((je,Ee)=>t.jsx(Vo,{profile:je,isDefault:r===je.id,onEdit:()=>Pe(je.id),onToggleDefault:()=>Fe(je.id),onDelete:()=>C(je),hasBorder:Ee<n.length-1||De.length>0},je.id)),B=!a&&n.length===0&&De.length===0&&t.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),t.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),ee=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((je,Ee)=>t.jsx(Fx,{credential:je,onImport:()=>Pe("new",{host:je.host,username:je.username}),hasBorder:Ee<De.length-1},`${je.host}-${je.username}`))]}),s[6]=r,s[7]=S,s[8]=i,s[9]=p,s[10]=a,s[11]=n,s[12]=u,s[13]=e,s[14]=D,s[15]=U,s[16]=T,s[17]=F,s[18]=j,s[19]=P,s[20]=O,s[21]=R,s[22]=V,s[23]=B,s[24]=ee,s[25]=Y,s[26]=w,s[27]=H}else D=s[14],U=s[15],T=s[16],F=s[17],j=s[18],P=s[19],O=s[20],R=s[21],V=s[22],B=s[23],ee=s[24],Y=s[25],w=s[26],H=s[27];let Q;s[51]!==O||s[52]!==R||s[53]!==V||s[54]!==B||s[55]!==ee?(Q=t.jsxs("div",{className:O,children:[R,V,B,ee]}),s[51]=O,s[52]=R,s[53]=V,s[54]=B,s[55]=ee,s[56]=Q):Q=s[56];let z;s[57]!==Q||s[58]!==Y||s[59]!==w||s[60]!==H?(z=t.jsxs("div",{"data-settings-item":Y,className:w,children:[H,Q]}),s[57]=Q,s[58]=Y,s[59]=w,s[60]=H,s[61]=z):z=s[61];let L;s[62]===Symbol.for("react.memo_cache_sentinel")?(L=t.jsx(sc,{}),s[62]=L):L=s[62];let X;s[63]!==T||s[64]!==F||s[65]!==z?(X=t.jsxs("div",{className:T,children:[F,z,L]}),s[63]=T,s[64]=F,s[65]=z,s[66]=X):X=s[66];let $;s[67]!==D||s[68]!==j||s[69]!==P||s[70]!==X?($=t.jsx(D,{outerClassName:j,className:P,children:X}),s[67]=D,s[68]=j,s[69]=P,s[70]=X,s[71]=$):$=s[71];let ne;s[72]!==x||s[73]!==m||s[74]!==g?(ne=t.jsx(Ex,{open:m,onOpenChange:I,profileId:g,importData:x}),s[72]=x,s[73]=m,s[74]=g,s[75]=ne):ne=s[75];const re=S!==null;let _;s[76]!==M?(_=De=>{M||De||C(null)},s[76]=M,s[77]=_):_=s[77];let oe;s[78]!==e?(oe=e("settings.gitIdentities.page.deleteDialog.title"),s[78]=e,s[79]=oe):oe=s[79];let fe;s[80]!==oe?(fe=t.jsx($t,{children:oe}),s[80]=oe,s[81]=fe):fe=s[81];const xe=S?.name??"";let Ce;s[82]!==e||s[83]!==xe?(Ce=e("settings.gitIdentities.page.deleteDialog.description",{name:xe}),s[82]=e,s[83]=xe,s[84]=Ce):Ce=s[84];let ve;s[85]!==Ce?(ve=t.jsx(Ht,{children:Ce}),s[85]=Ce,s[86]=ve):ve=s[86];let we;s[87]!==fe||s[88]!==ve?(we=t.jsxs(Bt,{children:[fe,ve]}),s[87]=fe,s[88]=ve,s[89]=we):we=s[89];let ye;s[90]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>C(null),s[90]=ye):ye=s[90];let se;s[91]!==e?(se=e("settings.common.actions.cancel"),s[91]=e,s[92]=se):se=s[92];let de;s[93]!==M||s[94]!==se?(de=t.jsx(J,{variant:"ghost",onClick:ye,disabled:M,children:se}),s[93]=M,s[94]=se,s[95]=de):de=s[95];let be;s[96]!==U?(be=()=>{U()},s[96]=U,s[97]=be):be=s[97];let W;s[98]!==e?(W=e("settings.common.actions.delete"),s[98]=e,s[99]=W):W=s[99];let te;s[100]!==M||s[101]!==be||s[102]!==W?(te=t.jsx(J,{size:"sm",variant:"destructive",onClick:be,disabled:M,children:W}),s[100]=M,s[101]=be,s[102]=W,s[103]=te):te=s[103];let ae;s[104]!==de||s[105]!==te?(ae=t.jsxs(Zt,{children:[de,te]}),s[104]=de,s[105]=te,s[106]=ae):ae=s[106];let me;s[107]!==we||s[108]!==ae?(me=t.jsxs(Ut,{className:"max-w-md",children:[we,ae]}),s[107]=we,s[108]=ae,s[109]=me):me=s[109];let Me;s[110]!==re||s[111]!==_||s[112]!==me?(Me=t.jsx(Kt,{open:re,onOpenChange:_,children:me}),s[110]=re,s[111]=_,s[112]=me,s[113]=Me):Me=s[113];let Ne;return s[114]!==$||s[115]!==ne||s[116]!==Me?(Ne=t.jsxs(t.Fragment,{children:[$,ne,Me]}),s[114]=$,s[115]=ne,s[116]=Me,s[117]=Ne):Ne=s[117],Ne},Vo=s=>{const e=st.c(56),{profile:n,isDefault:a,onEdit:r,onToggleDefault:i,onDelete:o,isReadOnly:d,hasBorder:c}=s,{t:f}=ot(),[u,p]=l.useState(!1),m=Mx[n.icon||"branch"]||"git-branch",I=Rx[n.color||""],g=n.authType||"ssh";let h;e[0]!==r?(h=z=>{z.currentTarget===z.target&&(z.key!=="Enter"&&z.key!==" "||(z.preventDefault(),r()))},e[0]=r,e[1]=h):h=e[1];const x=h;let E;e[2]!==a||e[3]!==d||e[4]!==o||e[5]!==i||e[6]!==f?(E=z=>t.jsxs(t.Fragment,{children:[t.jsx(z,{onClick:L=>{L.stopPropagation(),i()},children:f(a?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!d&&o&&t.jsxs(z,{onClick:L=>{L.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]})]}),e[2]=a,e[3]=d,e[4]=o,e[5]=i,e[6]=f,e[7]=E):E=e[7];const S=E,C=c&&"border-b border-[var(--surface-subtle)]";let M;e[8]!==C?(M=le("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",C),e[8]=C,e[9]=M):M=e[9];let k;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=z=>{z.preventDefault(),p(!0)},e[10]=k):k=e[10];let v;e[11]!==x||e[12]!==r||e[13]!==M?(v=t.jsx("div",{className:M,onClick:r,role:"button",tabIndex:0,onKeyDown:x,onContextMenu:k}),e[11]=x,e[12]=r,e[13]=M,e[14]=v):v=e[14];let b;e[15]!==I?(b={color:I},e[15]=I,e[16]=b):b=e[16];let D;e[17]!==m||e[18]!==b?(D=t.jsx(A,{name:m,className:"w-4 h-4 shrink-0",style:b}),e[17]=m,e[18]=b,e[19]=D):D=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 T;e[22]!==g?(T=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]=T):T=e[23];let F;e[24]!==a||e[25]!==f?(F=a&&t.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:f("settings.gitIdentities.page.badge.default")}),e[24]=a,e[25]=f,e[26]=F):F=e[26];let j;e[27]!==d||e[28]!==f?(j=d&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f("settings.agents.sidebar.badge.system")}),e[27]=d,e[28]=f,e[29]=j):j=e[29];let P;e[30]!==T||e[31]!==F||e[32]!==j||e[33]!==U?(P=t.jsxs("div",{className:"flex items-center gap-1.5",children:[U,T,F,j]}),e[30]=T,e[31]=F,e[32]=j,e[33]=U,e[34]=P):P=e[34];const O=g==="token"&&n.host?n.host:n.userEmail;let R;e[35]!==O?(R=t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:O}),e[35]=O,e[36]=R):R=e[36];let V;e[37]!==P||e[38]!==R?(V=t.jsxs("div",{className:"min-w-0",children:[P,R]}),e[37]=P,e[38]=R,e[39]=V):V=e[39];let B;e[40]!==V||e[41]!==D?(B=t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[D,V]}),e[40]=V,e[41]=D,e[42]=B):B=e[42];let ee;e[43]===Symbol.for("react.memo_cache_sentinel")?(ee=t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:Ox,children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=ee):ee=e[43];let Y;e[44]!==S?(Y=t.jsxs(gs,{children:[ee,t.jsx(ps,{align:"end",className:"w-fit min-w-28",children:S(ws)})]}),e[44]=S,e[45]=Y):Y=e[45];let w;e[46]!==B||e[47]!==Y||e[48]!==v?(w=t.jsxs(nn,{render:v,children:[B,Y]}),e[46]=B,e[47]=Y,e[48]=v,e[49]=w):w=e[49];let H;e[50]!==S?(H=t.jsx(an,{className:"w-fit min-w-28",children:S(qs)}),e[50]=S,e[51]=H):H=e[51];let Q;return e[52]!==u||e[53]!==w||e[54]!==H?(Q=t.jsxs(sn,{open:u,onOpenChange:p,children:[w,H]}),e[52]=u,e[53]=w,e[54]=H,e[55]=Q):Q=e[55],Q},Fx=s=>{const e=st.c(21),{credential:n,onImport:a,hasBorder:r}=s,{t:i}=ot();let o;e[0]!==n.host?(o=n.host.split("/"),e[0]=n.host,e[1]=o):o=e[1];const d=o,c=d.length>=3?d[d.length-1]:n.host,f=n.host.includes("/"),u=r&&"border-b border-[var(--surface-subtle)]";let p;e[2]!==u?(p=le("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",u),e[2]=u,e[3]=p):p=e[3];let m;e[4]!==c?(m=t.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=m):m=e[5];const I=f?n.host:n.username;let g;e[6]!==I?(g=t.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:I}),e[6]=I,e[7]=g):g=e[7];let h;e[8]!==m||e[9]!==g?(h=t.jsxs("div",{className:"min-w-0",children:[m,g]}),e[8]=m,e[9]=g,e[10]=h):h=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx(A,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let E;e[12]!==i?(E=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=E):E=e[13];let S;e[14]!==a||e[15]!==E?(S=t.jsxs(J,{size:"sm",variant:"ghost",onClick:a,className:"gap-1 shrink-0",children:[x,E]}),e[14]=a,e[15]=E,e[16]=S):S=e[16];let C;return e[17]!==S||e[18]!==p||e[19]!==h?(C=t.jsxs("div",{className:p,children:[h,S]}),e[17]=S,e[18]=p,e[19]=h,e[20]=C):C=e[20],C};function Lx(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 Ox(s){return s.stopPropagation()}const ac=()=>{const s=bm();return{displayMode:s,installed:s!=="browser",browserTab:s==="browser"}},zx=()=>{const s=st.c(2),[e,n]=l.useState(Kx);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)")],o=()=>{n(ac())};o();for(const d of i)typeof d.addEventListener=="function"?d.addEventListener("change",o):typeof d.addListener=="function"&&d.addListener(o);return window.addEventListener("appinstalled",o),window.addEventListener("focus",o),()=>{for(const d of i)typeof d.removeEventListener=="function"?d.removeEventListener("change",o):typeof d.removeListener=="function"&&d.removeListener(o);window.removeEventListener("appinstalled",o),window.removeEventListener("focus",o)}},r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),l.useEffect(a,r),e};function Kx(){return ac()}const Ux=[{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"}],$x=[{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"}],Bx=[{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"}],Jn="OpenChamber - AI Coding Assistant",_o=[{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"}],Ho=[{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"}],Vx=[{value:"default",labelKey:"settings.openchamber.visual.option.mobileLayout.default"},{value:"new",labelKey:"settings.openchamber.visual.option.mobileLayout.new"}],hr=s=>s==="portrait"||s==="landscape"?s:"system",_x=[{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"}],Hx=[{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"}],Wo=[{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"}],Wx=[{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"}],qo=[{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"}],Go=[{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"}],qx=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Gx=s=>s==="markdown"?"markdown":"plain",si=({visibleSettings:s})=>{const{locale:e,locales:n,setLocale:a,label:r,t:i}=ot(),o=l.useCallback(N=>i(N),[i]),{isMobile:d}=Is(),{browserTab:c}=zx(),f=eu(),u=Le(N=>N.showReasoningTraces),p=Le(N=>N.sessionRecapEnabled),m=Le(N=>N.sessionSuggestionEnabled),I=Le(N=>N.setSessionRecapEnabled),g=Le(N=>N.setSessionSuggestionEnabled),h=Le(N=>N.setShowReasoningTraces),x=Le(N=>N.collapsibleThinkingBlocks),E=Le(N=>N.setCollapsibleThinkingBlocks),S=Le(N=>N.mermaidRenderingMode),C=Le(N=>N.setMermaidRenderingMode),M=Le(N=>N.userMessageRenderingMode),k=Le(N=>N.setUserMessageRenderingMode),v=Le(N=>N.collapsibleUserMessages),b=Le(N=>N.setCollapsibleUserMessages),D=Le(N=>N.stickyUserHeader),U=Le(N=>N.setStickyUserHeader),T=Le(N=>N.expandedEditorToolbar),F=Le(N=>N.setExpandedEditorToolbar),j=Le(N=>N.wideChatLayoutEnabled),P=Le(N=>N.setWideChatLayoutEnabled),O=Le(N=>N.chatRenderMode),R=Le(N=>N.setChatRenderMode),V=Le(N=>N.activityRenderMode),B=Le(N=>N.setActivityRenderMode),ee=Le(N=>N.fontSize),Y=Le(N=>N.setFontSize),w=Le(N=>N.terminalFontSize),H=Le(N=>N.setTerminalFontSize),Q=Le(N=>N.uiFont),z=Le(N=>N.setUiFont),L=Le(N=>N.monoFont),X=Le(N=>N.setMonoFont),$=Le(N=>N.padding),ne=Le(N=>N.setPadding),re=Le(N=>N.inputBarOffset),_=Le(N=>N.setInputBarOffset),oe=Le(N=>N.mobileKeyboardMode),fe=Le(N=>N.setMobileKeyboardMode),xe=Le(N=>N.diffLayoutPreference),Ce=Le(N=>N.setDiffLayoutPreference),ve=Le(N=>N.showTerminalQuickKeysOnDesktop),we=Le(N=>N.setShowTerminalQuickKeysOnDesktop),ye=Le(N=>N.fileEditorKeymap),se=Le(N=>N.setFileEditorKeymap),de=Ii(N=>N.followUpBehavior),be=Ii(N=>N.setFollowUpBehavior),W=Le(N=>N.persistChatDraft),te=Le(N=>N.setPersistChatDraft),ae=Le(N=>N.inputSpellcheckEnabled),me=Le(N=>N.setInputSpellcheckEnabled),Me=Le(N=>N.showToolFileIcons),Ne=Le(N=>N.setShowToolFileIcons),De=Le(N=>N.showTurnChangedFiles),Ae=Le(N=>N.setShowTurnChangedFiles),Pe=Le(N=>N.showExpandedBashTools),Re=Le(N=>N.setShowExpandedBashTools),Fe=Le(N=>N.showExpandedEditTools),Ue=Le(N=>N.setShowExpandedEditTools),_e=Le(N=>N.timeFormatPreference),Ke=Le(N=>N.setTimeFormatPreference),qe=Le(N=>N.weekStartPreference),ce=Le(N=>N.setWeekStartPreference),G=Le(N=>N.showSplitAssistantMessageActions),pe=Le(N=>N.setShowSplitAssistantMessageActions),je=lt(N=>N.settingsMessageStreamTransport),Ee=lt(N=>N.setSettingsMessageStreamTransport),Se=je,Ve=lt(N=>N.settingsDefaultFileViewerPreview),Z=lt(N=>N.setSettingsDefaultFileViewerPreview),y=Le(N=>N.isSettingsDialogOpen),{themeMode:ue,setThemeMode:Ie,availableThemes:Oe,customThemesLoading:We,reloadCustomThemes:rt,lightThemeId:it,darkThemeId:nt,setLightThemePreference:dt,setDarkThemePreference:Ye}=Va(),[$e,mt]=l.useState(!1),he=l.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancySupported===!0,[]),et=typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancy===!0,[Xe,He]=l.useState(et),[bt,wt]=l.useState(!1),Pt=l.useMemo(()=>ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),ie=Le(N=>N.dockBadgeEnabled),Be=Le(N=>N.setDockBadgeEnabled),[Je,Ge]=l.useState(0),ut=Le(N=>N.reportUsage),yt=Le(N=>N.setReportUsage),gt=l.useCallback(N=>{yt(N),Ct({reportUsage:N})},[yt]),Et=y&&(s?s.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!Et)return;let N=null,ft=Date.now();const Mt=()=>{const Ot=Date.now();Ot-ft>=420&&(Ge(Xt=>(Xt+1)%24),ft=Ot),N=requestAnimationFrame(Mt)};(typeof document>"u"||document.visibilityState==="visible")&&(N=requestAnimationFrame(Mt));const is=()=>{document.visibilityState==="visible"&&N===null?N=requestAnimationFrame(Mt):document.visibilityState!=="visible"&&N!==null&&(cancelAnimationFrame(N),N=null)};return document.addEventListener("visibilitychange",is),()=>{document.removeEventListener("visibilitychange",is),N!==null&&cancelAnimationFrame(N)}},[Et]);const Qt=l.useCallback(N=>{k(N),Ct({userMessageRenderingMode:N})},[k]),es=l.useCallback(N=>{U(N),Ct({stickyUserHeader:N})},[U]),ts=l.useCallback(N=>{F(N),Ct({expandedEditorToolbar:N})},[F]),ss=l.useCallback(N=>{b(N),Ct({collapsibleUserMessages:N})},[b]),_t=l.useCallback(N=>{P(N),Ct({wideChatLayoutEnabled:N})},[P]),ns=l.useCallback(N=>{pe(N),Ct({showSplitAssistantMessageActions:N})},[pe]),ke=l.useCallback(N=>{me(N),Ct({inputSpellcheckEnabled:N})},[me]),vt=l.useCallback(N=>{R(N),Ct({chatRenderMode:N})},[R]),Nt=l.useCallback(N=>{Ee(N),Ct({messageStreamTransport:N})},[Ee]),Ze=l.useCallback(N=>{B(N),Ct({activityRenderMode:N})},[B]),kt=l.useCallback(N=>{C(N),Ct({mermaidRenderingMode:N})},[C]),Wt=l.useCallback(N=>{Ne(N),Ct({showToolFileIcons:N})},[Ne]),Jt=l.useCallback(N=>{Ae(N),Ct({showTurnChangedFiles:N})},[Ae]),as=l.useCallback(N=>{Z(N),Ct({defaultFileViewerPreview:N}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:N}}))},[Z]),zs=l.useCallback(N=>{Re(N),Ct({showExpandedBashTools:N})},[Re]),xs=l.useCallback(N=>{Ue(N),Ct({showExpandedEditTools:N})},[Ue]),Rs=l.useCallback(N=>{Ke(N),Ct({timeFormatPreference:N})},[Ke]),As=l.useCallback(N=>{ce(N),Ct({weekStartPreference:N})},[ce]),ct=l.useMemo(()=>Oe.filter(N=>N.metadata.variant==="light").sort((N,ft)=>N.metadata.name.localeCompare(ft.metadata.name)),[Oe]),at=l.useMemo(()=>Oe.filter(N=>N.metadata.variant==="dark").sort((N,ft)=>N.metadata.name.localeCompare(ft.metadata.name)),[Oe]),Rt=l.useMemo(()=>ct.find(N=>N.metadata.id===it)??ct[0],[ct,it]),Yt=l.useMemo(()=>at.find(N=>N.metadata.id===nt)??at[0],[at,nt]),Gt=l.useCallback((N,ft)=>{const Mt=ft==="dark"?" Dark":" Light";return N.endsWith(Mt)?N.slice(0,-Mt.length):N},[]),Qe=N=>s?s.includes(N):!0,Ss=fs(),Gs=Qe("theme")&&!Ss,cn=Qe("theme")||Qe("timeFormat")||Qe("weekStart"),aa=d&&hn()&&!ls()&&!Ss,Nn=Ss?cn:Qe("theme")||aa||Qe("pwaInstallName")||Qe("pwaOrientation")||Qe("timeFormat")||Qe("weekStart"),Ha=Qe("fontSize")||Qe("terminalFontSize")||Qe("spacing")||Qe("inputBarOffset"),Wa=Qe("terminalQuickKeys")&&!d||Qe("fileEditorKeymap")||Qe("expandedEditorToolbar"),qa=Qe("mermaidRendering")||Qe("userMessageRendering")||Qe("chatRenderMode")||Qe("messageTransport")||Qe("activityRenderMode")&&O==="sorted"||Qe("collapsibleUserMessages")||Qe("stickyUserHeader")||Qe("wideChatLayout")||Qe("splitAssistantMessageActions")||Qe("diffLayout")||Qe("dotfiles")||Qe("fileViewerPreview")||Qe("reasoning")||Qe("followUpBehavior")||Qe("persistDraft")||Qe("showToolFileIcons")||Qe("expandedTools")||!d&&Qe("inputSpellcheck"),Js=Qe("pwaInstallName")&&hn()&&c&&!ls()&&!Ss,Qs=Qe("pwaOrientation")&&hn()&&!ls()&&!Ss,Ys=Qe("mobileKeyboardMode")&&hn()&&!ls()&&!Ss&&tu(),[Un,Ga]=l.useState(()=>pu()),[kn,Ks]=l.useState(""),[K,ze]=l.useState("system"),xt=l.useMemo(()=>{const N=qo.find(ft=>ft.id===_e);return o(N?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[_e,o]),jt=l.useMemo(()=>{const N=Go.find(ft=>ft.id===qe);return o(N?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[qe,o]),rs=l.useMemo(()=>{const N=_o.find(ft=>ft.id===K);return N?o(N.labelKey):void 0},[K,o]),$n=l.useMemo(()=>{const N=Ho.find(ft=>ft.id===oe);return N?o(N.labelKey):void 0},[oe,o]),Es=l.useCallback(N=>{N!==Un&&(Ga(N),gu(N),window.location.reload())},[Un]),dn=l.useCallback(async N=>{if(typeof window>"u")return;const ft=window,is=N.trim().replace(/\s+/g," ").slice(0,64);if(await Ct({pwaAppName:is}),typeof ft.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const Ot=ft.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(is);Ks(Ot);return}Ks(is||Jn),ft.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Bn=l.useCallback(async N=>{if(typeof window>"u")return;const ft=window,Mt=hr(N);if(await Ct({pwaOrientation:Mt}),typeof ft.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const is=ft.__OPENCHAMBER_SET_PWA_ORIENTATION__(Mt);ze(is);return}ze(Mt),ft.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!Js&&!Qs&&!Ys)return;let N=!1;return(async()=>{try{const Mt=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Mt.ok){N||Ks(Jn);return}const is=await Mt.json().catch(()=>({})),Xt=(typeof is?.pwaAppName=="string"?is.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),mn=hr(is?.pwaOrientation),Vn=Ri(is?.mobileKeyboardMode);N||(Js&&Ks(Xt||Jn),Qs&&ze(mn),Ys&&fe(Vn))}catch{N||(Js&&Ks(Jn),Qs&&ze("system"),Ys&&fe("native"))}})(),()=>{N=!0}},[fe,Ys,Js,Qs]),t.jsxs("div",{className:"space-y-8",children:[Nn&&t.jsxs("div",{className:"mb-8 space-y-6",children:[Gs&&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:Ux.map(N=>t.jsx(J,{variant:"chip",size:"xs","aria-pressed":ue===N.value,className:"!font-normal",onClick:()=>Ie(N.value),children:o(N.labelKey)},N.value))})]}),aa&&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:Vx.map(N=>t.jsx(J,{variant:"chip",size:"xs","aria-pressed":Un===N.value,className:"!font-normal",onClick:()=>Es(N.value),children:o(N.labelKey)},N.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(Tt,{value:Rt?.metadata.id??"",onValueChange:dt,children:[t.jsx(Ft,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:t.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Rt?Gt(Rt.metadata.name,"light"):void 0})}),t.jsx(Lt,{children:ct.map(N=>t.jsx(ht,{value:N.metadata.id,children:Gt(N.metadata.name,"light")},N.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(Tt,{value:Yt?.metadata.id??"",onValueChange:Ye,children:[t.jsx(Ft,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:t.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Yt?Gt(Yt.metadata.name,"dark"):void 0})}),t.jsx(Lt,{children:at.map(N=>t.jsx(ht,{value:N.metadata.id,children:Gt(N.metadata.name,"dark")},N.metadata.id))})]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[t.jsx("button",{type:"button",disabled:We||$e,onClick:()=>{const N=Date.now();mt(!0),rt().finally(()=>{const ft=Date.now()-N;if(ft<500){window.setTimeout(()=>{mt(!1)},500-ft);return}mt(!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($e?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),t.jsxs(It,{children:[t.jsx(Dt,{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(A,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(At,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]}),he&&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":Xe,onClick:()=>{bt||He(!Xe)},onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),bt||He(!Xe))},children:[t.jsx(St,{checked:Xe,onChange:He,disabled:bt,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")})]})]}),Xe!==et&&t.jsx("div",{className:"pl-6",children:t.jsx(J,{variant:"outline",size:"sm",disabled:bt,onClick:()=>{wt(!0),su("desktop_set_vibrancy",{enabled:Xe})},children:i(bt?"settings.openchamber.visual.actions.restarting":"settings.openchamber.visual.actions.saveAndRestart")})})]}),Pt&&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":ie,onClick:()=>Be(!ie),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),Be(!ie))},children:[t.jsx(St,{checked:ie,onChange:Be,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")})]})]})})]}),cn&&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(Tt,{value:e,onValueChange:N=>a(N),children:[t.jsx(Ft,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:t.jsx(zt,{children:r(e)})}),t.jsx(Lt,{children:n.map(N=>t.jsx(ht,{value:N,children:r(N)},N))})]})]}),(Qe("timeFormat")||Qe("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:[Qe("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(Tt,{value:_e,onValueChange:N=>Rs(N),children:[t.jsx(Ft,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:t.jsx(zt,{children:xt})}),t.jsx(Lt,{children:qo.map(N=>t.jsx(ht,{value:N.id,children:o(N.labelKey)},N.id))})]})]}),Qe("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(Tt,{value:qe,onValueChange:N=>As(N),children:[t.jsx(Ft,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:t.jsx(zt,{children:jt})}),t.jsx(Lt,{children:Go.map(N=>t.jsx(ht,{value:N.id,children:o(N.labelKey)},N.id))})]})]})]})]}),(Js||Qs||Ys)&&t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[Js&&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(tt,{value:kn,onChange:N=>{Ks(N.target.value)},onBlur:()=>{dn(kn)},onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),dn(kn))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ks(Jn),dn("")},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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qs&&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(Tt,{value:K,onValueChange:N=>{const ft=hr(N);ze(ft),Bn(ft)},children:[t.jsx(Ft,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:t.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:rs})}),t.jsx(Lt,{children:_o.map(N=>t.jsx(ht,{value:N.id,children:o(N.labelKey)},N.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ze("system"),Bn("system")},disabled:K==="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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Ys&&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(Tt,{value:oe,onValueChange:N=>{const ft=Ri(N);fe(ft),Ct({mobileKeyboardMode:ft})},children:[t.jsx(Ft,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:t.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:$n})}),t.jsx(Lt,{children:Ho.map(N=>t.jsx(ht,{value:N.id,children:o(N.labelKey)},N.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>{fe("native"),Ct({mobileKeyboardMode:"native"})},disabled:oe==="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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),Ha&&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:[Qe("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(Tt,{value:Q,onValueChange:N=>z(N),children:[t.jsx(Ft,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:t.jsx(zt,{children:Di.find(N=>N.id===Q)?.label})}),t.jsx(Lt,{children:Di.map(N=>t.jsx(ht,{value:N.id,children:t.jsx("span",{style:{fontFamily:N.stack},children:N.label})},N.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>z(Ai),disabled:Q===Ai,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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("terminalFontSize")&&t.jsxs("div",{className:le("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:le("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:le("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsxs(Tt,{value:L,onValueChange:N=>X(N),children:[t.jsx(Ft,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:t.jsx(zt,{children:Ei.find(N=>N.id===L)?.label})}),t.jsx(Lt,{children:Ei.map(N=>t.jsx(ht,{value:N.id,children:t.jsx("span",{style:{fontFamily:N.stack},children:N.label})},N.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>X(Mi),disabled:L===Mi,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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("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(js,{value:ee,onValueChange:Y,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>Y(100),disabled:ee===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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("terminalFontSize")&&t.jsxs("div",{"data-settings-item":"appearance.terminal-font-size",className:le("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:le("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:le("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(js,{value:w,onValueChange:H,min:9,max:52,step:1,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>H(13),disabled:w===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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("spacing")&&t.jsxs("div",{"data-settings-item":"appearance.spacing-density",className:le("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:le("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:le("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(js,{value:$,onValueChange:ne,min:50,max:200,step:5,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>ne(100),disabled:$===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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("inputBarOffset")&&t.jsxs("div",{"data-settings-item":"appearance.input-bar-offset",className:le("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:le("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),t.jsxs("div",{className:le("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(js,{value:re,onValueChange:_,min:0,max:100,step:5,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>_(0),disabled:re===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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),Wa&&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")}),Qe("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(N=>{const ft=ye===N,Mt=i(`settings.openchamber.visual.option.fileEditorKeymap.${N}`);return t.jsxs("button",{type:"button",className:"flex cursor-pointer items-center gap-2 py-0.5 text-left",role:"radio","aria-checked":ft,onClick:()=>se(N),children:[t.jsx("span",{"aria-hidden":!0,className:le("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",ft?"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:le("block h-[5px] w-[5px] rounded-full bg-white",!ft&&"opacity-0")})}),t.jsx("span",{className:le("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:Mt})]},N)})})]}),Qe("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":T,onClick:()=>ts(!T),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),ts(!T))},children:[t.jsx(St,{checked:T,onChange:ts,ariaLabel:i("settings.openchamber.visual.field.expandedEditorToolbarAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.expandedEditorToolbar")})]}),Qe("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":ve,onClick:()=>we(!ve),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),we(!ve))},children:[t.jsx(St,{checked:ve,onChange:we,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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),qa&&t.jsxs("div",{className:"space-y-3",children:[(Qe("userMessageRendering")||Qe("mermaidRendering")||Qe("chatRenderMode")||Qe("messageTransport")||Qe("activityRenderMode")&&O==="sorted"||Qe("diffLayout")&&!Ss||Qe("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:[Qe("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:Hx.map(N=>{const ft=O===N.id,Mt=Je%12;return t.jsxs("button",{type:"button",onClick:()=>vt(N.id),"aria-pressed":ft,className:le("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",ft?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsx("span",{className:le("typography-ui-label",ft?"text-foreground":"text-muted-foreground"),children:o(N.labelKey)}),t.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:N.id==="live"?t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(is=>{const Ot=is*3+1,Xt=Mt-Ot+1,mn=Xt<=0?0:Xt===1?42:Xt===2?68:92,Vn=mn>0;return t.jsxs("div",{className:le("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Vn?"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:`${mn}%`}})]},is)})}):t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(is=>{const Ot=Mt>=(is+1)*3;return t.jsxs("div",{className:le("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Ot?"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%"}})]},is)})})})]},N.id)})})]}),Qe("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:Wo.map(N=>t.jsx(J,{variant:"chip",size:"xs","aria-pressed":Se===N.id,className:"!font-normal",onClick:()=>Nt(N.id),children:o(N.labelKey)},N.id))}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const N=Wo.find(ft=>ft.id===Se);return N?.descriptionKey?o(N.descriptionKey):""})()})]})]}),Qe("activityRenderMode")&&O==="sorted"&&t.jsxs("section",{className:"p-2 md:col-span-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.activityDefault")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:Wx.map(N=>{const ft=V===N.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>Ze(N.id),onKeyDown:Mt=>{(Mt.key===" "||Mt.key==="Enter")&&(Mt.preventDefault(),Ze(N.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:ft,onChange:()=>Ze(N.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(N.labelKey)})}),t.jsx("span",{className:le("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(N.labelKey)})]},N.id)})})]}),Qe("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":Pe,onClick:()=>zs(!Pe),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),zs(!Pe))},children:[t.jsx(St,{checked:Pe,onChange:zs,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":Fe,onClick:()=>xs(!Fe),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),xs(!Fe))},children:[t.jsx(St,{checked:Fe,onChange:xs,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),Qe("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:_x.map(N=>{const ft=Gx(M)===N.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>Qt(N.id),onKeyDown:Mt=>{(Mt.key===" "||Mt.key==="Enter")&&(Mt.preventDefault(),Qt(N.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:ft,onChange:()=>Qt(N.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(N.labelKey)})}),t.jsx("span",{className:le("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(N.labelKey)})]},N.id)})})]}),Qe("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:Bx.map(N=>{const ft=S===N.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>kt(N.id),onKeyDown:Mt=>{(Mt.key===" "||Mt.key==="Enter")&&(Mt.preventDefault(),kt(N.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:ft,onChange:()=>kt(N.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(N.labelKey)})}),t.jsx("span",{className:le("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(N.labelKey)})]},N.id)})})]}),Qe("diffLayout")&&!Ss&&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:$x.map(N=>{const ft=xe===N.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>Ce(N.id),onKeyDown:Mt=>{(Mt.key===" "||Mt.key==="Enter")&&(Mt.preventDefault(),Ce(N.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:ft,onChange:()=>Ce(N.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:o(N.labelKey)})}),t.jsx("span",{className:le("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(N.labelKey)})]},N.id)})})]}),Qe("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:qx.map(N=>{const ft=de===N.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>be(N.id),onKeyDown:Mt=>{(Mt.key===" "||Mt.key==="Enter")&&(Mt.preventDefault(),be(N.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:ft,onChange:()=>be(N.id),ariaLabel:i("settings.openchamber.visual.field.followUpBehaviorAria",{option:o(N.labelKey)})}),t.jsx("span",{className:le("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(N.labelKey)})]},N.id)})})]})]}),(Qe("sessionAssist")||Qe("collapsibleUserMessages")||Qe("stickyUserHeader")||Qe("wideChatLayout")||Qe("splitAssistantMessageActions")||Qe("dotfiles")||Qe("fileViewerPreview")||Qe("persistDraft")||Qe("showToolFileIcons")||Qe("showTurnChangedFiles")||!d&&Qe("inputSpellcheck")||Qe("reasoning"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[Qe("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:()=>I(!p),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),I(!p))},children:[t.jsx(St,{checked:p,onChange:I,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":m,onClick:()=>g(!m),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),g(!m))},children:[t.jsx(St,{checked:m,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")})]})]}),Qe("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":u,onClick:()=>h(!u),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),h(!u))},children:[t.jsx(St,{checked:u,onChange:h,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),Qe("reasoning")&&u&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":x,onClick:()=>E(!x),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),E(!x))},children:[t.jsx(St,{checked:x,onChange:E,ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleThinkingBlocks")})]}),Qe("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":v,onClick:()=>ss(!v),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),ss(!v))},children:[t.jsx(St,{checked:v,onChange:ss,ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleUserMessages")})]}),Qe("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":D,onClick:()=>es(!D),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),es(!D))},children:[t.jsx(St,{checked:D,onChange:es,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),Qe("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":j,onClick:()=>_t(!j),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),_t(!j))},children:[t.jsx(St,{checked:j,onChange:_t,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),Qe("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":G,onClick:()=>ns(!G),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),ns(!G))},children:[t.jsx(St,{checked:G,onChange:ns,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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),Qe("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":Me,onClick:()=>Wt(!Me),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),Wt(!Me))},children:[t.jsx(St,{checked:Me,onChange:Wt,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),Qe("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":De,onClick:()=>Jt(!De),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),Jt(!De))},children:[t.jsx(St,{checked:De,onChange:Jt,ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showTurnChangedFiles")})]}),Qe("dotfiles")&&!fs()&&t.jsxs("div",{"data-settings-item":"chat.dotfiles",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>tr(!f),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),tr(!f))},children:[t.jsx(St,{checked:f,onChange:tr,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),Qe("fileViewerPreview")&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Ve,onClick:()=>as(!Ve),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),as(!Ve))},children:[t.jsx("span",{onClick:N=>N.stopPropagation(),children:t.jsx(St,{checked:Ve,onChange:as,ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.defaults.field.openFilesPreview")})]}),Qe("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":W,onClick:()=>te(!W),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),te(!W))},children:[t.jsx(St,{checked:W,onChange:te,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!d&&Qe("inputSpellcheck")&&t.jsxs("div",{"data-settings-item":"chat.spellcheck",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ae,onClick:()=>ke(!ae),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),ke(!ae))},children:[t.jsx(St,{checked:ae,onChange:ke,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),Qe("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(St,{checked:ut,onChange:gt,ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria")}),t.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[t.jsx("div",{className:"group flex cursor-pointer",role:"button",tabIndex:0,"aria-pressed":ut,onClick:()=>gt(!ut),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),gt(!ut))},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")})]})]})]})})]})},Jx=1,Qx=365,Jo=30,Yx=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],rc=()=>{const s=st.c(113),{t:e}=ot(),n=Le(Xx),a=Le(Zx),r=Le(eb),i=Le(tb),o=Le(sb),d=Le(nb);let c;s[0]===Symbol.for("react.memo_cache_sentinel")?(c={autoRun:!1},s[0]=c):c=s[0];const{candidates:f,isRunning:u,runCleanup:p,action:m}=ym(c),I=f.length;let g;s[1]!==p||s[2]!==e?(g=async()=>{const ae=await p({force:!0});if(ae.completedIds.length===0&&ae.failedIds.length===0){q.message(ae.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ae.completedIds.length>0&&q.success(ae.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ae.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ae.completedIds.length})),ae.failedIds.length>0&&q.error(ae.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ae.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ae.failedIds.length}))},s[1]=p,s[2]=e,s[3]=g):g=s[3];const h=g;let x;s[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),s[4]=e,s[5]=x):x=s[5];let E;s[6]!==x?(E=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),s[6]=x,s[7]=E):E=s[7];let S;s[8]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[8]=S):S=s[8];let C;s[9]!==e?(C=e("settings.openchamber.sessionRetention.tooltip"),s[9]=e,s[10]=C):C=s[10];let M;s[11]!==C?(M=t.jsxs(It,{children:[S,t.jsx(At,{sideOffset:8,className:"max-w-xs",children:C})]}),s[11]=C,s[12]=M):M=s[12];let k;s[13]!==E||s[14]!==M?(k=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[E,M]})}),s[13]=E,s[14]=M,s[15]=k):k=s[15];let v,b;s[16]!==n||s[17]!==i?(v=()=>i(!n),b=ae=>{(ae.key===" "||ae.key==="Enter")&&(ae.preventDefault(),i(!n))},s[16]=n,s[17]=i,s[18]=v,s[19]=b):(v=s[18],b=s[19]);let D;s[20]!==e?(D=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),s[20]=e,s[21]=D):D=s[21];let U;s[22]!==n||s[23]!==i||s[24]!==D?(U=t.jsx(St,{checked:n,onChange:i,ariaLabel:D}),s[22]=n,s[23]=i,s[24]=D,s[25]=U):U=s[25];let T;s[26]!==e?(T=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),s[26]=e,s[27]=T):T=s[27];let F;s[28]!==T?(F=t.jsx("span",{className:"typography-ui-label text-foreground",children:T}),s[28]=T,s[29]=F):F=s[29];let j;s[30]!==n||s[31]!==U||s[32]!==F||s[33]!==v||s[34]!==b?(j=t.jsxs("div",{"data-settings-item":"sessions.auto-cleanup",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:v,onKeyDown:b,children:[U,F]}),s[30]=n,s[31]=U,s[32]=F,s[33]=v,s[34]=b,s[35]=j):j=s[35];let P;s[36]!==e?(P=e("settings.openchamber.sessionRetention.field.retentionPeriod"),s[36]=e,s[37]=P):P=s[37];let O;s[38]!==P?(O=t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:P})}),s[38]=P,s[39]=O):O=s[39];let R;s[40]!==e?(R=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),s[40]=e,s[41]=R):R=s[41];let V;s[42]!==a||s[43]!==o||s[44]!==R?(V=t.jsx(js,{value:a,onValueChange:o,min:Jx,max:Qx,step:1,"aria-label":R,className:"w-20 tabular-nums"}),s[42]=a,s[43]=o,s[44]=R,s[45]=V):V=s[45];let B;s[46]!==e?(B=e("settings.openchamber.sessionRetention.field.days"),s[46]=e,s[47]=B):B=s[47];let ee;s[48]!==B?(ee=t.jsx("span",{className:"typography-ui-label text-muted-foreground",children:B}),s[48]=B,s[49]=ee):ee=s[49];let Y;s[50]!==o?(Y=()=>o(Jo),s[50]=o,s[51]=Y):Y=s[51];const w=a===Jo;let H;s[52]!==e?(H=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),s[52]=e,s[53]=H):H=s[53];let Q;s[54]!==e?(Q=e("settings.common.actions.reset"),s[54]=e,s[55]=Q):Q=s[55];let z;s[56]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"}),s[56]=z):z=s[56];let L;s[57]!==Y||s[58]!==w||s[59]!==H||s[60]!==Q?(L=t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:Y,disabled:w,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":H,title:Q,children:z}),s[57]=Y,s[58]=w,s[59]=H,s[60]=Q,s[61]=L):L=s[61];let X;s[62]!==V||s[63]!==ee||s[64]!==L?(X=t.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[V,ee,L]}),s[62]=V,s[63]=ee,s[64]=L,s[65]=X):X=s[65];let $;s[66]!==O||s[67]!==X?($=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:[O,X]}),s[66]=O,s[67]=X,s[68]=$):$=s[68];let ne;s[69]!==e?(ne=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),s[69]=e,s[70]=ne):ne=s[70];let re;s[71]!==ne?(re=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:ne})}),s[71]=ne,s[72]=re):re=s[72];let _;s[73]!==r||s[74]!==d||s[75]!==e?(_=Yx.map(ae=>t.jsx(J,{type:"button",variant:"chip",size:"xs","aria-pressed":r===ae.value,className:"!font-normal",onClick:()=>d(ae.value),children:e(ae.labelKey)},ae.value)),s[73]=r,s[74]=d,s[75]=e,s[76]=_):_=s[76];let oe;s[77]!==_?(oe=t.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:_}),s[77]=_,s[78]=oe):oe=s[78];let fe;s[79]!==re||s[80]!==oe?(fe=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:[re,oe]}),s[79]=re,s[80]=oe,s[81]=fe):fe=s[81];let xe;s[82]!==j||s[83]!==$||s[84]!==fe?(xe=t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[j,$,fe]}),s[82]=j,s[83]=$,s[84]=fe,s[85]=xe):xe=s[85];let Ce;s[86]!==e?(Ce=e("settings.openchamber.sessionRetention.manualCleanup.title"),s[86]=e,s[87]=Ce):Ce=s[87];let ve;s[88]!==Ce?(ve=t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("p",{className:"typography-meta text-foreground font-medium",children:Ce})}),s[88]=Ce,s[89]=ve):ve=s[89];let we;s[90]!==u||s[91]!==e?(we=e(u?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),s[90]=u,s[91]=e,s[92]=we):we=s[92];let ye;s[93]!==h||s[94]!==u||s[95]!==we?(ye=t.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:t.jsx(J,{type:"button",variant:"outline",size:"xs",onClick:h,disabled:u,className:"!font-normal",children:we})}),s[93]=h,s[94]=u,s[95]=we,s[96]=ye):ye=s[96];let se;s[97]!==ve||s[98]!==ye?(se=t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ve,ye]}),s[97]=ve,s[98]=ye,s[99]=se):se=s[99];let de;s[100]!==m||s[101]!==I||s[102]!==e?(de=m==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:I}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:I}),s[100]=m,s[101]=I,s[102]=e,s[103]=de):de=s[103];let be;s[104]!==de?(be=t.jsx("p",{className:"typography-meta text-muted-foreground",children:de}),s[104]=de,s[105]=be):be=s[105];let W;s[106]!==se||s[107]!==be?(W=t.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[se,be]}),s[106]=se,s[107]=be,s[108]=W):W=s[108];let te;return s[109]!==xe||s[110]!==W||s[111]!==k?(te=t.jsxs("div",{className:"mb-8",children:[k,xe,W]}),s[109]=xe,s[110]=W,s[111]=k,s[112]=te):te=s[112],te};function Xx(s){return s.autoDeleteEnabled}function Zx(s){return s.autoDeleteAfterDays}function eb(s){return s.sessionRetentionAction}function tb(s){return s.setAutoDeleteEnabled}function sb(s){return s.setAutoDeleteAfterDays}function nb(s){return s.setSessionRetentionAction}const Qo=(s,e,n)=>!s||!Number.isFinite(s)?e:new Intl.DateTimeFormat(Yr(),{dateStyle:"medium",timeStyle:"short",hour12:n==="auto"?void 0:n==="12h"}).format(s),ic=()=>{const{t:s}=ot(),e=Le(b=>b.timeFormatPreference),[n,a]=l.useState(!1),[r,i]=l.useState(!0),[o,d]=l.useState(!1),[c,f]=l.useState(null),[u,p]=l.useState(!1),[m,I]=l.useState([]),[g,h]=l.useState(vm),[x,E]=l.useState(""),S=l.useMemo(()=>jm(),[]),C=l.useCallback(async()=>{i(!0),E("");try{const b=await wm();I(b)}catch(b){const D=b instanceof Error?b.message:s("settings.openchamber.passkeys.toast.loadFailed");E(D)}finally{i(!1)}},[s]);l.useEffect(()=>{let b=!1;return(async()=>{try{if(!S.supported){b||(a(!1),i(!1));return}b||a(!0)}catch{b||a(!1)}if(!b){const D=await Ya();if(h(D),!D.enabled){I([]),i(!1);return}await C()}})(),()=>{b=!0,ji()}},[C,S.supported]);const M=l.useCallback(async()=>{if(!g.enabled){const b=s("settings.openchamber.passkeys.toast.enableUiPasswordFirst");E(b),q.message(b);return}if(!n){E(S.reason),q.message(S.reason);return}if(o){ji(),d(!1);return}E(""),d(!0);try{await Nm(),h(await Ya()),await C(),q.success(s("settings.openchamber.passkeys.toast.added"))}catch(b){if(km(b)){q.message(s("settings.openchamber.passkeys.toast.setupCanceled"));return}const D=b instanceof Error?b.message:s("settings.openchamber.passkeys.toast.addFailed");E(D),q.error(D)}finally{d(!1)}},[o,C,g.enabled,S.reason,n,s]),k=l.useCallback(async b=>{f(b),E("");try{await Sm(b),h(await Ya()),await C(),q.success(s("settings.openchamber.passkeys.toast.removed"))}catch(D){const U=D instanceof Error?D.message:s("settings.openchamber.passkeys.toast.removeFailed");E(U),q.error(U)}finally{f(null)}},[C,s]),v=l.useCallback(async()=>{p(!0),E("");try{await Cm(),window.location.reload()}catch(b){const D=b instanceof Error?b.message:s("settings.openchamber.passkeys.toast.clearAuthFailed");E(D),q.error(D),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(J,{type:"button",variant:o?"secondary":"outline",size:"xs",onClick:()=>{M()},disabled:r||u,className:"!font-normal",children:s(o?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",onClick:()=>{v()},disabled:r||o||u,className:"!font-normal text-muted-foreground hover:text-foreground",children:s(u?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]})]}),!g.enabled&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.uiPasswordRequired")}),g.enabled&&!n&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:S.reason}),r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.loading")}):m.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:m.map(b=>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:b.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:b.lastUsedAt?s("settings.openchamber.passkeys.item.lastUsed",{time:Qo(b.lastUsedAt,s("settings.openchamber.passkeys.time.neverUsed"),e)}):s("settings.openchamber.passkeys.item.added",{time:Qo(b.createdAt,s("settings.openchamber.passkeys.time.neverUsed"),e)})}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k(b.id)},disabled:c===b.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===b.id?s("settings.openchamber.passkeys.actions.removing"):s("settings.common.actions.delete")})]})]},b.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})})]})},Yo=s=>{const e=xn(s);return e||{providerId:"",modelId:""}},oc=()=>{const{t:s}=ot(),e=lt(w=>w.setProvider),n=lt(w=>w.setModel),a=lt(w=>w.setAgent),r=lt(w=>w.setCurrentVariant),i=lt(w=>w.setSettingsDefaultModel),o=lt(w=>w.setSettingsDefaultVariant),d=lt(w=>w.setSettingsDefaultAgent),c=Le(w=>w.showDeletionDialog),f=Le(w=>w.setShowDeletionDialog),u=lt(w=>w.providers),[p,m]=l.useState(),[I,g]=l.useState(),[h,x]=l.useState(),[E,S]=l.useState(!0),[C,M]=l.useState(),[k,v]=l.useState(),[b,D]=l.useState(!0),U=l.useMemo(()=>Yo(p),[p]);l.useEffect(()=>{(async()=>{try{let H=null;if(!H){const Q=Os()?.settings;if(Q)try{const L=(await Q.load())?.settings;if(L){const X=L;H={defaultModel:typeof L.defaultModel=="string"?L.defaultModel:void 0,defaultVariant:typeof X.defaultVariant=="string"?X.defaultVariant:void 0,defaultAgent:typeof L.defaultAgent=="string"?L.defaultAgent:void 0,smallModelUseDefault:typeof X.smallModelUseDefault=="boolean"?X.smallModelUseDefault:void 0,smallModelOverride:typeof X.smallModelOverride=="string"?X.smallModelOverride:void 0}}}catch{}}if(!H){const Q=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});Q.ok&&(H=await Q.json())}if(H){const Q=typeof H.defaultModel=="string"&&H.defaultModel.trim().length>0?H.defaultModel.trim():void 0,z=typeof H.defaultVariant=="string"&&H.defaultVariant.trim().length>0?H.defaultVariant.trim():void 0,L=typeof H.defaultAgent=="string"&&H.defaultAgent.trim().length>0?H.defaultAgent.trim():void 0;Q!==void 0&&m(Q),z!==void 0&&g(z),L!==void 0&&x(L),typeof H.smallModelUseDefault=="boolean"&&S(H.smallModelUseDefault),typeof H.smallModelOverride=="string"&&H.smallModelOverride.trim()&&M(H.smallModelOverride.trim())}}catch(H){console.warn("Failed to load defaults settings:",H)}finally{D(!1)}})()},[]);const T=l.useCallback(async(w,H)=>{const Q=w&&H?`${w}/${H}`:void 0;m(Q),g(void 0),o(void 0),r(void 0),i(Q),w&&H&&u.find(L=>L.id===w)&&(e(w),n(H));try{await Ct({defaultModel:Q??"",defaultVariant:""});const z=await pt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:Q})});z.ok||console.warn("Failed to save default model to server:",z.status,z.statusText)}catch(z){console.warn("Failed to save default model:",z)}},[u,r,n,e,i,o]),F="__default__",j=l.useCallback(w=>w===F?s("settings.openchamber.defaults.option.default"):w.charAt(0).toUpperCase()+w.slice(1),[s]),P=l.useCallback(async w=>{const H=w===F?void 0:w||void 0;g(H),o(H),r(H);try{await Ct({defaultVariant:H??""})}catch(Q){console.warn("Failed to save default variant:",Q)}},[r,o]),O=l.useCallback(async w=>{const H=w||void 0;x(H),d(H),w&&a(w);try{await Ct({defaultAgent:H??""})}catch(Q){console.warn("Failed to save default agent:",Q)}},[a,d]),R=l.useCallback(async w=>{S(w);try{await Ct({smallModelUseDefault:w})}catch(H){console.warn("Failed to save small model preference:",H)}},[]),V=l.useCallback(async(w,H)=>{const Q=w&&H?`${w}/${H}`:void 0;M(Q);try{await Ct({smallModelOverride:Q??""})}catch(z){console.warn("Failed to save small model override:",z)}},[]),B=l.useMemo(()=>Yo(C),[C]);l.useEffect(()=>{if(E||k!==void 0)return;let w=!1;return(async()=>{try{const H=await pt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!H.ok)return;const Q=await H.json().catch(()=>null);!w&&Array.isArray(Q?.authenticatedProviders)&&v(Q.authenticatedProviders.filter(z=>typeof z=="string"))}catch{}})(),()=>{w=!0}},[E,k]);const ee=l.useMemo(()=>{if(!U.providerId||!U.modelId)return[];const Q=u.find(z=>z.id===U.providerId)?.models.find(z=>z.id===U.modelId)?.variants;return Q?Object.keys(Q):[]},[U.modelId,U.providerId,u]),Y=ee.length>0;return l.useEffect(()=>{!Y&&I&&(g(void 0),o(void 0),r(void 0),Ct({defaultVariant:""}).catch(()=>{}))},[I,r,o,Y]),b?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?` (${I??s("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):t.jsx("span",{className:"text-foreground",children:s("settings.openchamber.defaults.summaryOpenCodeDefault")}),h&&t.jsxs(t.Fragment,{children:[" / ",t.jsx("span",{className:"text-foreground",children:h})]})]}),t.jsxs("div",{"data-settings-item":"sessions.default-model",className:le("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(La,{providerId:U.providerId,modelId:U.modelId,onChange:T})})]}),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(Tt,{value:I??F,onValueChange:P,disabled:!Y,children:[t.jsx(Ft,{className:"w-fit min-w-[120px]",children:t.jsx(zt,{placeholder:s("settings.openchamber.defaults.field.thinkingPlaceholder"),children:j(I??F)})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:F,children:s("settings.openchamber.defaults.option.default")}),ee.map(w=>t.jsx(ht,{value:w,children:j(w)},w))]})]})})]}),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(Cl,{agentName:h||"",onChange:O})})]}),t.jsxs("div",{"data-settings-item":"sessions.deletion-dialog",className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":c,onClick:()=>f(!c),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),f(!c))},children:[t.jsx(St,{checked:c,onChange:f,ariaLabel:s("settings.openchamber.defaults.field.showDeletionDialogAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.field.showDeletionDialog")})]})]}),t.jsx("div",{className:"mt-6 mb-0.5 px-1",children:t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.defaults.smallModel.title")})})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsx("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:s("settings.openchamber.defaults.smallModel.description")}),t.jsxs("div",{"data-settings-item":"sessions.small-model",className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":E,onClick:()=>{R(!E)},onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),R(!E))},children:[t.jsx(St,{checked:E,onChange:w=>{R(w)},ariaLabel:s("settings.openchamber.defaults.smallModel.useDefaultAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.smallModel.useDefault")})]}),E?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(La,{providerId:B.providerId,modelId:B.modelId,onChange:V,allowedProviderIds:k})})]})]})]})},Xo={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"}},ab={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"},rb=()=>{const{t:s}=ot(),e=l.useMemo(()=>ls(),[]),n=l.useMemo(()=>fs(),[]),a=l.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),r=!e&&!n&&!a,i=Le(z=>z.nativeNotificationsEnabled),o=Le(z=>z.setNativeNotificationsEnabled),d=Le(z=>z.notificationMode),c=Le(z=>z.setNotificationMode),f=Le(z=>z.notifyOnSubtasks),u=Le(z=>z.setNotifyOnSubtasks),p=Le(z=>z.notifyOnCompletion),m=Le(z=>z.setNotifyOnCompletion),I=Le(z=>z.notifyOnError),g=Le(z=>z.setNotifyOnError),h=Le(z=>z.notifyOnQuestion),x=Le(z=>z.setNotifyOnQuestion),E=Le(z=>z.notificationTemplates),S=Le(z=>z.setNotificationTemplates),[C,M]=l.useState("default"),[k,v]=l.useState(!1),[b,D]=l.useState(!1),[U,T]=l.useState(!1);l.useEffect(()=>{if(!r){v(!1),D(!1);return}typeof Notification<"u"&&M(Notification.permission);const z=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;v(z),(async()=>{if(!z){D(!1);return}try{const X=await navigator.serviceWorker.getRegistration();if(!X){D(!1);return}const $=await X.pushManager.getSubscription();D(!!$)}catch{D(!1)}})()},[r]);const F=async z=>{if(e){o(z);return}if(!r){o(z);return}if(z&&typeof Notification<"u"&&Notification.permission==="default")try{const L=await Notification.requestPermission();M(L),L==="granted"?o(!0):q.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.description")})}catch(L){console.error("Failed to request notification permission:",L),q.error(s("settings.notifications.page.toast.requestPermissionFailed"))}else o(!!(z&&C==="granted"))},j=e||n||a||r&&typeof Notification<"u"&&Notification.permission==="granted",P=(z,L,X)=>{S({...E,[z]:{...E[z],[L]:X}})},O=z=>{const L="=".repeat((4-z.length%4)%4),X=(z+L).replace(/-/g,"+").replace(/_/g,"/"),$=atob(X),ne=new Uint8Array($.length);for(let re=0;re<$.length;re+=1)ne[re]=$.charCodeAt(re);return ne},R=async(z,L,X)=>{let $=null;const ne=new Promise((re,_)=>{$=setTimeout(()=>{_(new Error(X))},L)});try{return await Promise.race([z,ne])}finally{$&&clearTimeout($)}},V=async z=>{if(z.active)return;const L=z.installing||z.waiting;L&&L.state!=="activated"&&await R(new Promise(X=>{const $=()=>{L.state==="activated"&&(L.removeEventListener("statechange",$),X())};L.addEventListener("statechange",$),$()}),15e3,"Service worker activation timed out")},B=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const z=[{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 L=null;for(const X of z)try{const $=X.opts?navigator.serviceWorker.register("/sw.js",X.opts):navigator.serviceWorker.register("/sw.js");return await R($,1e4,`Service worker registration timed out (${X.label})`)}catch($){L=$}throw L instanceof Error?L:new Error("Service worker registration failed")},ee=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const z=await navigator.serviceWorker.getRegistration();if(z)return z;const L=await B();try{await L.update()}catch{}return await V(L),L},Y=z=>{const L=z,X=[`type=${typeof z}`,`toString=${String(z)}`,`name=${String(L?.name??"")}`,`message=${String(L?.message??"")}`];let $="";try{$=JSON.stringify(z)}catch{}return{summary:X.filter(Boolean).join(" | "),json:$,stack:typeof L?.stack=="string"?L.stack:""}},w=async()=>{const z=Os();if(!z?.notifications){q.error(s("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await z.notifications.notifyAgentCompletion({title:s("settings.notifications.page.testNotification.title"),body:s("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?q.success(s("settings.notifications.page.toast.testNotificationSent")):q.error(s("settings.notifications.page.toast.testNotificationFailed"))}catch(L){console.error("Test notification failed:",L),q.error(s("settings.notifications.page.toast.testNotificationFailed"))}},H=async()=>{if(!k){q.error(s("settings.notifications.page.toast.pushUnsupported"));return}const z=Os();if(!z?.push){q.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const fe=await Notification.requestPermission();if(M(fe),fe!=="granted"){q.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){q.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const L=await z.push.getVapidPublicKey();if(!L?.publicKey){q.error(s("settings.notifications.page.toast.pushKeyLoadFailed"));return}const X=await ee();await V(X);const $=await X.pushManager.getSubscription();if(!("pushManager"in X)||!X.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const re=($??await R(X.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:O(L.publicKey)}),15e3,"Push subscription timed out")).toJSON(),_=re.keys;if(!re.endpoint||!_?.p256dh||!_.auth)throw new Error("Push subscription missing keys");if(!(await R(z.push.subscribe({endpoint:re.endpoint,keys:{p256dh:_.p256dh,auth:_.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:Pm()}),15e3,"Push subscribe request timed out"))?.ok){q.error(s("settings.notifications.page.toast.enableBackgroundFailed"));return}D(!0),q.success(s("settings.notifications.page.toast.backgroundEnabled"))}catch(L){console.error("[Push] Enable failed:",L);const X=Y(L);q.error(s("settings.notifications.page.toast.enableBackgroundFailed"),{description:X.summary})}finally{T(!1)}},Q=async()=>{if(!k){D(!1);return}const z=Os();if(!z?.push){q.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{const X=await(await ee()).pushManager.getSubscription();if(!X){D(!1);return}const $=X.endpoint;await X.unsubscribe(),await z.push.unsubscribe({endpoint:$}),D(!1),q.success(s("settings.notifications.page.toast.backgroundDisabled"))}finally{T(!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&&j,onClick:()=>{F(!(i&&j))},onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),F(!(i&&j)))},children:[t.jsx(St,{checked:i&&j,onChange:z=>{F(z)},ariaLabel:s("settings.notifications.page.delivery.enableAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.delivery.enableLabel")})]}),i&&j&&!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:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),c(d==="always"?"hidden-only":"always"))},children:[t.jsx(St,{checked:d==="always",onChange:z=>c(z?"always":"hidden-only"),ariaLabel:s("settings.notifications.page.delivery.focusedAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.delivery.focusedLabel")})]}),t.jsx("div",{className:"py-2",children:t.jsx(J,{type:"button",variant:"outline",size:"sm",onClick:()=>{w()},children:s("settings.notifications.page.delivery.testAction")})})]})]}),r&&t.jsxs("div",{className:"mt-1 px-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.notifications.page.delivery.browserPermissionHint")}),C==="denied"&&t.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:s("settings.notifications.page.delivery.permissionDenied")}),C==="granted"&&!i&&t.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:s("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),n&&t.jsx("div",{className:"mt-1 px-2",children:t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.notifications.page.delivery.vscodeHint")})})]}),i&&j&&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:()=>m(!p),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),m(!p))},children:[t.jsx(St,{checked:p,onChange:m,ariaLabel:s("settings.notifications.page.events.completionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.completionLabel")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>u(!f),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),u(!f))},children:[t.jsx(St,{checked:f,onChange:u,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":I,onClick:()=>g(!I),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),g(!I))},children:[t.jsx(St,{checked:I,onChange:g,ariaLabel:s("settings.notifications.page.events.errorAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.errorLabel")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":h,onClick:()=>x(!h),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),x(!h))},children:[t.jsx(St,{checked:h,onChange:x,ariaLabel:s("settings.notifications.page.events.questionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.questionLabel")})]})]})]}),!a&&t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.template.title")}),t.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[s("settings.notifications.page.template.variablesLabel")," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),t.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(z=>t.jsxs("section",{className:"p-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:s(ab[z])}),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(tt,{value:E[z].title,onChange:L=>P(z,"title",L.target.value),className:"h-7",placeholder:s(Xo[z].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(tt,{value:E[z].message,onChange:L=>P(z,"message",L.target.value),className:"h-7",placeholder:s(Xo[z].messageKey)})]})]})]},z))})]})]}),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(St,{checked:k?b:!1,disabled:!k||U,onChange:z=>{z?H():Q()},ariaLabel:s("settings.notifications.page.push.enableAria")}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:le("typography-ui-label",k?"text-foreground":"text-muted-foreground"),children:s("settings.notifications.page.push.enableLabel")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s(k?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),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")})})]})})]})]})},Ns=s=>{if(!s)return;s.pause();const{src:e}=s;e.startsWith("blob:")&&URL.revokeObjectURL(e),s.removeAttribute("src"),s.load()},ib=[{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"}],Zo=s=>{const e=st.c(8),{value:n,label:a}=s,r=`${a}: ${n}/5`,i=`${n/5*100}%`;let o;e[0]!==i?(o=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]=o):o=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]!==o||e[6]!==d?(c=t.jsxs("span",{className:"flex items-center gap-1.5",title:r,children:[o,d]}),e[4]=r,e[5]=o,e[6]=d,e[7]=c):c=e[7],c},ob=({selectedModelId:s,onSelect:e})=>{const{t:n}=ot(),a=ge.useCallback(m=>n(m),[n]),[r,i]=ge.useState(new Map),[o,d]=ge.useState(null),c=ge.useCallback(async()=>{try{const m=await pt("/api/dictation/status",{query:{provider:"local"}});if(!m.ok)return;const I=await m.json();Array.isArray(I?.models)&&i(new Map(I.models.map(g=>[g.id,g])))}catch{}},[]);ge.useEffect(()=>{c()},[c]);const f=Array.from(r.values()).some(m=>m.downloading);ge.useEffect(()=>{if(!f)return;const m=setInterval(()=>{c()},2e3);return()=>clearInterval(m)},[f,c]);const u=async m=>{d(m);try{await pt(`/api/dictation/models/${encodeURIComponent(m)}/download`,{method:"POST"}),await c()}catch{}finally{d(null)}},p=async m=>{d(m);try{await pt(`/api/dictation/models/${encodeURIComponent(m)}`,{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:ib.map(m=>{const I=s===m.id,g=r.get(m.id)??null;return t.jsxs("div",{className:"flex w-full items-start gap-2 py-1.5",children:[t.jsx("div",{className:"pt-0.5",children:t.jsx(tn,{checked:I,onChange:()=>e(m.id),ariaLabel:a(m.labelKey)})}),t.jsxs("div",{className:"min-w-0 flex-1 cursor-pointer",role:"button",tabIndex:0,onClick:()=>e(m.id),onKeyDown:h=>{(h.key===" "||h.key==="Enter")&&(h.preventDefault(),e(m.id))},children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5",children:[t.jsx("span",{className:le("typography-ui-label font-normal",I?"text-foreground":"text-foreground/50"),children:a(m.labelKey)}),m.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(m.badgeKey)}):null]}),t.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-4 gap-y-0.5",children:[t.jsx(Zo,{value:m.accuracy,label:n("settings.voice.page.stt.meta.accuracy")}),t.jsx(Zo,{value:m.speed,label:n("settings.voice.page.stt.meta.speed")}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:m.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(J,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:o===m.id,onClick:()=>{p(m.id)},title:n("settings.voice.page.stt.modelDelete"),"aria-label":n("settings.voice.page.stt.modelDelete"),children:t.jsx(A,{name:"delete-bin",className:"h-4 w-4"})}),t.jsx(A,{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(A,{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(J,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:o===m.id,onClick:()=>{u(m.id)},title:n("settings.voice.page.stt.modelDownload"),"aria-label":n("settings.voice.page.stt.modelDownload"),children:t.jsx(A,{name:"download",className:"h-4 w-4"})})})]},m.id)})})},fr=[{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)"}],xr="kokoro-en-v0_19",lb=()=>{const{t:s}=ot(),[e,n]=ge.useState(null),[a,r]=ge.useState(!1),i=ge.useCallback(async()=>{try{const d=await pt("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const c=await d.json(),f=Array.isArray(c?.ttsModels)?c.ttsModels.find(u=>u.id===xr):null;f&&n(f)}catch{}},[]);ge.useEffect(()=>{i()},[i]),ge.useEffect(()=>{if(!e?.downloading)return;const d=setInterval(()=>{i()},2e3);return()=>clearInterval(d)},[e?.downloading,i]);const o=async d=>{r(!0);try{const c=d==="POST"?`/api/dictation/models/${xr}/download`:`/api/dictation/models/${xr}`;await pt(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(A,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":s("settings.voice.page.stt.modelInstalled")}),t.jsx(J,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:a,onClick:()=>{o("DELETE")},title:s("settings.voice.page.stt.modelDelete"),"aria-label":s("settings.voice.page.stt.modelDelete"),children:t.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})]}):e.downloading?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof e.downloadProgress=="number"?`${e.downloadProgress}%`:""})]}):t.jsx(J,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:a,onClick:()=>{o("POST")},title:s("settings.voice.page.stt.modelDownload"),"aria-label":s("settings.voice.page.stt.modelDownload"),children:t.jsx(A,{name:"download",className:"h-4 w-4"})}),e.downloadError?t.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:e.downloadError}):null]}):null},cb=[{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"}],db=()=>{const{t:s}=ot(),{isMobile:e}=Is(),n=lt(y=>y.voiceProvider),a=lt(y=>y.setVoiceProvider),r=lt(y=>y.speechRate),i=lt(y=>y.setSpeechRate),o=lt(y=>y.speechPitch),d=lt(y=>y.setSpeechPitch),c=lt(y=>y.speechVolume),f=lt(y=>y.setSpeechVolume),u=lt(y=>y.sayVoice),p=lt(y=>y.setSayVoice),m=lt(y=>y.localTtsVoiceId),I=lt(y=>y.setLocalTtsVoiceId),{speak:g,stop:h,isPlaying:x,error:E}=Im(),S=ge.useCallback(()=>{if(x){h();return}const y=fr.find(ue=>ue.id===m)?.label??String(m);g(s("settings.voice.page.preview.voiceLine",{voiceName:y}),{speakerId:m,speed:lt.getState().speechRate})},[x,m,g,h,s]),C=lt(y=>y.browserVoice),M=lt(y=>y.setBrowserVoice),k=lt(y=>y.openaiVoice),v=lt(y=>y.setOpenaiVoice),b=lt(y=>y.openaiApiKey),D=lt(y=>y.setOpenaiApiKey),U=lt(y=>y.openaiCompatibleUrl),T=lt(y=>y.setOpenaiCompatibleUrl),F=lt(y=>y.openaiCompatibleApiKey),j=lt(y=>y.setOpenaiCompatibleApiKey),P=lt(y=>y.openaiCompatibleVoice),O=lt(y=>y.setOpenaiCompatibleVoice),R=lt(y=>y.openaiCompatibleTtsModel),V=lt(y=>y.setOpenaiCompatibleTtsModel),B=lt(y=>y.showMessageTTSButtons),ee=lt(y=>y.ttsInputMode),Y=lt(y=>y.setTtsInputMode),w=lt(y=>y.sttProvider),H=lt(y=>y.setSttProvider),Q=lt(y=>y.sttServerUrl),z=lt(y=>y.setSttServerUrl),L=lt(y=>y.sttApiKey),X=lt(y=>y.setSttApiKey),$=lt(y=>y.sttModel),ne=lt(y=>y.setSttModel),re=lt(y=>y.sttLocalModel),_=lt(y=>y.setSttLocalModel),oe=lt(y=>y.sttLanguage),fe=lt(y=>y.setSttLanguage),xe=lt(y=>y.setShowMessageTTSButtons),Ce=lt(y=>y.dictationEnabled),ve=lt(y=>y.setDictationEnabled),[we,ye]=ge.useState(!1),[se,de]=ge.useState([]),[be,W]=ge.useState(!1),[te,ae]=ge.useState(null),[me,Me]=ge.useState(!1),[Ne,De]=ge.useState(!1),[Ae,Pe]=ge.useState(null),[Re,Fe]=ge.useState(!1),[Ue,_e]=ge.useState(null),[Ke,qe]=ge.useState([]),[ce,G]=ge.useState(!1);ge.useEffect(()=>((async()=>{const ue=await Xa.waitForVoices();qe(ue)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{qe(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const pe=ge.useMemo(()=>Ke.filter(y=>y.lang).sort((y,ue)=>{const Ie=y.lang.startsWith("en"),Oe=ue.lang.startsWith("en");if(Ie&&!Oe)return-1;if(!Ie&&Oe)return 1;const We=y.lang.localeCompare(ue.lang);return We!==0?We:y.name.localeCompare(ue.name)}),[Ke]),je=ge.useCallback(()=>{if(ce){Xa.cancelSpeech(),G(!1);return}const y=Ke.find(We=>We.name===C),ue=y?.name??s("settings.voice.page.preview.browserVoiceFallback"),Ie=s("settings.voice.page.preview.voiceLine",{voiceName:ue});G(!0);const Oe=new SpeechSynthesisUtterance(Ie);Oe.rate=r,Oe.pitch=o,Oe.volume=c,y&&(Oe.voice=y,Oe.lang=y.lang),Oe.onend=()=>G(!1),Oe.onerror=()=>G(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(Oe)},[C,Ke,r,o,c,ce,s]);ge.useEffect(()=>()=>{ce&&Xa.cancelSpeech()},[ce]),ge.useEffect(()=>{if(!B||n!=="openai"&&n!=="openai-compatible"){Me(b.trim().length>0);return}(async()=>{try{const Oe=(await(await pt("/api/tts/status")).json()).available,We=b.trim().length>0;Me(Oe||We)}catch{Me(b.trim().length>0)}})()},[b,B,n]),ge.useEffect(()=>{if(!B){ye(!1),de([]);return}pt("/api/tts/say/status").then(y=>y.json()).then(y=>{if(ye(y.available),y.voices){const ue=y.voices.filter((Ie,Oe,We)=>We.findIndex(rt=>rt.name===Ie.name)===Oe).sort((Ie,Oe)=>Ie.name.localeCompare(Oe.name));de(ue)}}).catch(()=>{ye(!1)})},[B]);const Ee=ge.useCallback(async()=>{if(te){Ns(te),ae(null),W(!1);return}W(!0);let y=null;try{const ue=await pt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.voiceLine",{voiceName:u}),voice:u,rate:Math.round(100+(r-.5)*200)})});if(!ue.ok)throw new Error("Preview failed");const Ie=await ue.blob(),Oe=URL.createObjectURL(Ie);y=new Audio(Oe),y.onended=()=>{Ns(y),ae(null),W(!1)},y.onerror=()=>{Ns(y),ae(null),W(!1)},ae(y),await y.play()}catch{Ns(y),ae(null),W(!1)}},[u,r,te,s]);ge.useEffect(()=>()=>{Ns(te)},[te]);const Se=ge.useCallback(async()=>{if(Ae){Ns(Ae),Pe(null),De(!1);return}De(!0);let y=null;try{const ue=await pt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.voiceLine",{voiceName:k}),voice:k,speed:r,apiKey:b||void 0})});if(!ue.ok){const We=await ue.json().catch(()=>({error:"Unknown error"}));throw new Error(We.error||`HTTP ${ue.status}`)}const Ie=await ue.blob(),Oe=URL.createObjectURL(Ie);y=new Audio(Oe),y.onended=()=>{Ns(y),Pe(null),De(!1)},y.onerror=()=>{Ns(y),Pe(null),De(!1)},Pe(y),await y.play()}catch{Ns(y),Pe(null),De(!1)}},[k,r,Ae,b,s]);ge.useEffect(()=>()=>{Ns(Ae)},[Ae]);const Ve=ge.useCallback(async()=>{if(Ue){Ns(Ue),_e(null),Fe(!1);return}if(!U.trim())return;Fe(!0);let y=null;try{const ue=await pt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.customServerLine"),voice:P,model:R||void 0,speed:r,baseURL:U,apiKey:F||void 0})});if(!ue.ok){const We=await ue.json().catch(()=>({error:"Unknown error"}));throw new Error(We.error||`HTTP ${ue.status}`)}const Ie=await ue.blob(),Oe=URL.createObjectURL(Ie);y=new Audio(Oe),y.onended=()=>{Ns(y),_e(null),Fe(!1)},y.onerror=()=>{Ns(y),_e(null),Fe(!1)},_e(y),await y.play()}catch{Ns(y),_e(null),Fe(!1)}},[U,P,R,F,r,Ue,s]);ge.useEffect(()=>()=>{Ns(Ue)},[Ue]);const Z="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":B,onClick:()=>xe(!B),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),xe(!B))},children:[t.jsx(St,{checked:B,onChange:xe,ariaLabel:s("settings.voice.page.field.messageReadAloudButtonAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.messageReadAloudButton")})]}),B&&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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:t.jsxs("ul",{className:"space-y-1",children:[t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.browser")})," ",s("settings.voice.page.tooltip.browser")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.local")})," ",s("settings.voice.page.tooltip.localTts")]}),t.jsxs("li",{children:[t.jsx("strong",{children:"OpenAI:"})," ",s("settings.voice.page.tooltip.openai")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.custom")})," ",s("settings.voice.page.tooltip.custom")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.say")})," ",s("settings.voice.page.tooltip.say")]})]})})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":n==="browser",onClick:()=>a("browser"),className:"!font-normal",children:s("settings.voice.page.provider.browser")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":n==="local",onClick:()=>a("local"),className:"!font-normal",children:s("settings.voice.page.provider.local")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":n==="openai",onClick:()=>a("openai"),className:"!font-normal",children:"OpenAI"}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":n==="openai-compatible",onClick:()=>a("openai-compatible"),className:"!font-normal",children:s("settings.voice.page.provider.custom")}),we&&t.jsxs(J,{variant:"chip",size:"xs","aria-pressed":n==="say",onClick:()=>a("say"),className:"!font-normal",children:[t.jsx(A,{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:le("typography-ui-label text-foreground",!me&&"text-[var(--status-error)]"),children:s("settings.voice.page.field.apiKey")}),t.jsx("span",{className:le("typography-meta ml-2",me?"text-muted-foreground":"text-[var(--status-error)]/80"),children:s(me&&!b?"settings.voice.page.field.apiKeyHintUsingConfig":me?"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:b,onChange:y=>D(y.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"}),b&&t.jsx("button",{type:"button",onClick:()=>D(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(A,{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:le("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:y=>T(y.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:()=>T(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(A,{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:F,onChange:y=>j(y.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"}),F&&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(A,{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:y=>V(y.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.voice")}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:s("settings.voice.page.field.voiceIdentifierHint")}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[t.jsx("div",{className:"relative max-w-xs flex-1",children:t.jsx("input",{type:"text",value:P,onChange:y=>O(y.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),t.jsx(J,{size:"xs",variant:"ghost",onClick:Ve,title:s("settings.voice.page.actions.preview"),disabled:!U.trim(),children:Re?t.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),n==="local"&&t.jsx(lb,{}),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(Tt,{value:String(m),onValueChange:y=>I(Number.parseInt(y,10)||0),children:[t.jsx(Ft,{className:"w-fit",children:t.jsx(zt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder"),children:y=>fr.find(ue=>String(ue.id)===y)?.label??y})}),t.jsx(Lt,{children:fr.map(y=>t.jsx(ht,{value:String(y.id),children:y.label},y.id))})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:S,title:s("settings.voice.page.actions.preview"),children:x?t.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(A,{name:"play",className:"w-3.5 h-3.5"})}),E?t.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:E}):null]}),n==="openai"&&me&&t.jsxs(t.Fragment,{children:[t.jsxs(Tt,{value:k,onValueChange:v,children:[t.jsx(Ft,{className:"w-fit",children:t.jsx(zt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Lt,{children:cb.map(y=>t.jsx(ht,{value:y.value,children:y.label},y.value))})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:Se,title:s("settings.voice.page.actions.preview"),children:Ne?t.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(A,{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&&se.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(Tt,{value:u,onValueChange:p,children:[t.jsx(Ft,{className:"w-fit",children:t.jsx(zt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Lt,{children:se.map(y=>t.jsx(ht,{value:y.name,children:y.name},y.name))})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:Ee,title:s("settings.voice.page.actions.preview"),children:be?t.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]}),n==="browser"&&pe.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(Tt,{value:C||"$auto",onValueChange:y=>M(y==="$auto"?"":y),children:[t.jsx(Ft,{className:"w-fit max-w-[200px]",children:t.jsx(zt,{placeholder:s("settings.voice.page.field.auto")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"$auto",children:s("settings.voice.page.field.auto")}),pe.map(y=>t.jsxs(ht,{value:y.name,children:[y.name," (",y.lang,")"]},y.name))]})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:je,title:s("settings.voice.page.actions.preview"),children:ce?t.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(A,{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:y=>i(Number(y.target.value)),className:Z}),t.jsx(js,{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:o,onChange:y=>d(Number(y.target.value)),className:Z}),t.jsx(js,{value:o,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:y=>f(Number(y.target.value)),className:Z}),e?t.jsx(js,{value:Math.round(c*100),onValueChange:y=>f(y/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):t.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(c*100),"%"]})]})]}),t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.ttsInputMode")})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":ee==="sanitized",onClick:()=>Y("sanitized"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeSanitized")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":ee==="raw",onClick:()=>Y("raw"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeRaw")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":ee==="summarized",onClick:()=>Y("summarized"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeSummarized")})]})]})})]})]})]}),t.jsxs("div",{"data-settings-item":"voice.speech-recognition",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.voice.page.section.speechRecognition")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":Ce,onClick:()=>ve(!Ce),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),ve(!Ce))},children:[t.jsx(St,{checked:Ce,onChange:ve,ariaLabel:s("settings.voice.page.field.enableVoiceInputAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.enableVoiceInput")})]}),Ce&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.provider")}),t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:t.jsxs("ul",{className:"space-y-1",children:[t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.local")})," ",s("settings.voice.page.tooltip.sttLocal")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.server")})," ",s("settings.voice.page.tooltip.sttServer")]})]})})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":w==="local",onClick:()=>H("local"),className:"!font-normal",children:s("settings.voice.page.provider.local")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":w==="openai-compatible",onClick:()=>H("openai-compatible"),className:"!font-normal",children:s("settings.voice.page.provider.server")})]})]})}),w==="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(ob,{selectedModelId:re,onSelect:_})]}),w==="openai-compatible"&&t.jsxs("div",{className:"py-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:le("typography-ui-label text-foreground",!Q.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:Q,onChange:y=>z(y.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"}),Q&&t.jsx("button",{type:"button",onClick:()=>z(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(A,{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:L,onChange:y=>X(y.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"}),L&&t.jsx("button",{type:"button",onClick:()=>X(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.model")}),t.jsx("div",{className:"relative mt-1.5 max-w-xs",children:t.jsx("input",{type:"text",value:$,onChange:y=>ne(y.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:oe,onChange:y=>fe(y.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"})})]})]})]})]})]})]})},ba=[{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}],ya=[{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}],mb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",ub="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",br=[{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"}],pb=[".yml",".yaml",".json"],gb="settings.openchamber.tunnel.error.invalidConfigExtension",Qn=s=>{const e=s.trim().toLowerCase();return pb.some(n=>e.endsWith(n))},hb=s=>s==="ngrok"?"ngrok":"cloudflared",lc=()=>{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"},fb=(s,e=lc())=>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():hb(n),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():lc(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():fb(n,r);return{provider:n,dependency:a,installCommand:i}},cc=s=>s==="cloudflare"?"Cloudflare":s==="ngrok"?"Ngrok":s,el=s=>{const e=st.c(11),{provider:n}=s;let a;e[0]!==n?(a=cc(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=le("size-4 shrink-0",d),e[2]=d,e[3]=c):c=e[3];let f;e[4]!==c?(f=t.jsx(A,{name:"cloud",className:c}),e[4]=c,e[5]=f):f=e[5];let u;e[6]!==r?(u=t.jsx("span",{children:r}),e[6]=r,e[7]=u):u=e[7];let p;return e[8]!==f||e[9]!==u?(p=t.jsxs("span",{className:"flex items-center gap-2",children:[f,u]}),e[8]=f,e[9]=u,e[10]=p):p=e[10],p},en=s=>s==="quick"?"quick":s==="managed-remote"?"managed-remote":s==="managed-local"?"managed-local":"quick",Hr=(s,e,n)=>s.find(r=>r.ms===e)?.value||n,tl=(s,e,n)=>{const a=Hr(s,e,n);return s.find(r=>r.value===a)?.label||a},sl=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`},xb=(s,e)=>Rl(s,e,{hour:"2-digit",precision:"second"}),Ea=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()}},bb=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,o=typeof i.id=="string"?i.id.trim():"",d=typeof i.name=="string"?i.name.trim():"",c=Ea(typeof i.hostname=="string"?i.hostname:"");!o||!d||!c||e.has(o)||n.has(c)||(e.add(o),n.add(c),a.push({id:o,name:d,hostname:c}))}return a},yb=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,vb=()=>{const{t:s}=ot(),e=Le(ie=>ie.timeFormatPreference),n=l.useCallback(ie=>s(ie),[s]),[a,r]=l.useState("checking"),[i,o]=l.useState(null),[d,c]=l.useState(null),[f,u]=l.useState(null),[p,m]=l.useState(null),[I,g]=l.useState(null),[h,x]=l.useState(!1),[E,S]=l.useState(!1),[C,M]=l.useState(!1),[k,v]=l.useState("cloudflare"),[b,D]=l.useState(()=>yr("cloudflare")),[U,T]=l.useState([]),[F,j]=l.useState("quick"),[P,O]=l.useState(null),[R,V]=l.useState([]),[B,ee]=l.useState({}),[Y,w]=l.useState(""),[H,Q]=l.useState({}),[z,L]=l.useState(new Set),[X,$]=l.useState(!1),[ne,re]=l.useState(""),[_,oe]=l.useState(""),[fe,xe]=l.useState(""),[Ce,ve]=l.useState(1800*1e3),[we,ye]=l.useState(480*60*1e3),[se,de]=l.useState(""),[be,W]=l.useState([]),[te,ae]=l.useState(()=>Date.now()),[me,Me]=l.useState(null),Ne=s(gb),De=l.useRef(null),Ae=l.useMemo(()=>P?!Qn(P):!1,[P]),Pe=l.useMemo(()=>R.find(ie=>ie.id===Y)||R[0]||null,[R,Y]),Re=l.useMemo(()=>be.map(ie=>{const Be=ie.expiresAt<=te,Je=ie.status==="active"&&!Be,Ge=Je?sl(ie.expiresAt-te):ie.inactiveReason==="expired"||Be?"expired":"inactive",ut=Ge==="expired"?s("settings.openchamber.tunnel.state.expired"):ie.inactiveReason==="tunnel-revoked"?s("settings.openchamber.tunnel.state.revoked"):s("settings.openchamber.tunnel.state.inactive"),yt=en(ie.mode);return{...ie,isActive:Je,mode:yt,remainingTextForSession:Ge,inactiveLabel:ut}}),[te,be,s]),Fe=l.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>te:!1,[te,i?.bootstrapExpiresAt,i?.connectUrl]),Ue=l.useMemo(()=>!i||a!=="active"&&a!=="stopping"?!1:d===F,[d,a,i,F]),_e=l.useMemo(()=>!i||a!=="active"||!d?!1:d!==F,[d,a,i,F]),Ke=l.useMemo(()=>{if(typeof me=="number"&&Number.isFinite(me)&&me>0)return me;if(typeof window>"u")return null;const Be=Kn()||window.location.href;let Je=0;try{Je=Number(new URL(Be).port)}catch{Je=Number(window.location.port)}return Number.isFinite(Je)&&Je>0?Je:null},[me]),qe=l.useMemo(()=>U.find(ie=>ie.provider===k)??null,[U,k]),ce=l.useMemo(()=>{const ie=new Set(qe?.modes?.map(Be=>Be.key).filter(Be=>Be==="quick"||Be==="managed-remote"||Be==="managed-local"));return ie.size===0?br:br.filter(Be=>ie.has(Be.value))},[qe]),G=l.useMemo(()=>ce.some(ie=>ie.value==="managed-remote"||ie.value==="managed-local"),[ce]),pe=l.useMemo(()=>b.provider===k?b:yr(k),[b,k]),je=l.useCallback(async ie=>{await Ws(ie)},[]),Ee=l.useCallback((ie,Be)=>(D(yr(Be,ie)),ie.available===!0),[]),Se=l.useCallback(async(ie,Be)=>{try{const Je=await pt("/api/openchamber/tunnel/check",{query:{provider:ie},...Be?{signal:Be}:{}});if(!Je.ok)return null;const Ge=await Je.json();if(Be?.aborted)return null;const ut=Ee(Ge,ie);return r(yt=>yt==="checking"||yt==="starting"||yt==="active"||yt==="stopping"?yt:ut?"idle":"not-available"),ut}catch{return null}},[Ee]),Ve=l.useCallback(async ie=>{try{const[Be,Je,Ge,ut]=await Promise.all([pt("/api/openchamber/tunnel/check",{signal:ie}),pt("/api/openchamber/tunnel/status",{signal:ie}),pt("/api/config/settings",{signal:ie,headers:{Accept:"application/json"}}),pt("/api/openchamber/tunnel/providers",{signal:ie})]),yt=await Be.json(),gt=await Je.json(),Et=Ge.ok?await Ge.json():{},Qt=ut.ok?await ut.json():{},es=gt.ttlConfig?.bootstrapTtlMs??(Et?.tunnelBootstrapTtlMs===null?null:typeof Et?.tunnelBootstrapTtlMs=="number"?Et.tunnelBootstrapTtlMs:1800*1e3),ts=typeof gt.ttlConfig?.sessionTtlMs=="number"?gt.ttlConfig.sessionTtlMs:typeof Et?.tunnelSessionTtlMs=="number"?Et.tunnelSessionTtlMs:480*60*1e3,ss=en(gt.mode??Et?.tunnelMode),_t=typeof Et?.tunnelProvider=="string"&&Et.tunnelProvider.trim().length>0?Et.tunnelProvider.trim().toLowerCase():"cloudflare",ns=typeof Et?.managedLocalTunnelConfigPath=="string"&&Et.managedLocalTunnelConfigPath.trim()||null,ke=Ee(yt,_t),vt=bb(gt?.managedRemoteTunnelPresets),Nt=typeof gt.managedRemoteTunnelHostname=="string"?gt.managedRemoteTunnelHostname:"",Ze=vt.length>0?vt:Nt?[{id:`legacy-${Ea(Nt)}`,name:Nt,hostname:Ea(Nt)}]:[],kt=Ze[0]?.id||"";if(ve(es),ye(ts),v(_t),T(Array.isArray(Qt?.providers)?Qt.providers:[]),j(ss),O(ns),V(Ze),w(kt),W(Array.isArray(gt.activeSessions)?gt.activeSessions:[]),c(gt.activeTunnelMode?en(gt.activeTunnelMode):gt.active&>.mode?en(gt.mode):null),L(new Set(Array.isArray(gt.managedRemoteTunnelTokenPresetIds)?gt.managedRemoteTunnelTokenPresetIds:[])),Me(typeof gt.localPort=="number"?gt.localPort:null),gt.active&>.url){o({url:gt.url,connectUrl:null,bootstrapExpiresAt:typeof gt.bootstrapExpiresAt=="number"?gt.bootstrapExpiresAt:null}),r("active");return}r(ke?"idle":"not-available")}catch{ie.aborted||(r("error"),m(s("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Ee,s]);l.useEffect(()=>{const ie=new AbortController;return Ve(ie.signal),()=>ie.abort()},[Ve]),l.useEffect(()=>{if(!i?.connectUrl){u(null);return}let ie=!1;return Nl.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Be=>{ie||u(Be)}).catch(()=>{ie||u(null)}),()=>{ie=!0}},[i?.connectUrl]),l.useEffect(()=>{if(!i?.bootstrapExpiresAt){de(s("settings.openchamber.tunnel.state.noExpiry"));return}let ie=null,Be=Date.now();const Je=()=>{const yt=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;yt<=0?de(s("settings.openchamber.tunnel.state.expired")):de(sl(yt))},Ge=()=>{const yt=Date.now();yt-Be>=1e3&&(Je(),Be=yt),ie=requestAnimationFrame(Ge)};Je(),(typeof document>"u"||document.visibilityState==="visible")&&(ie=requestAnimationFrame(Ge));const ut=()=>{document.visibilityState==="visible"&&ie===null?ie=requestAnimationFrame(Ge):document.visibilityState!=="visible"&&ie!==null&&(cancelAnimationFrame(ie),ie=null)};return document.addEventListener("visibilitychange",ut),()=>{document.removeEventListener("visibilitychange",ut),ie!==null&&cancelAnimationFrame(ie)}},[s,i?.bootstrapExpiresAt]),l.useEffect(()=>{let ie=null,Be=Date.now();const Je=()=>{const ut=Date.now();ut-Be>=1e3&&(ae(ut),Be=ut),ie=requestAnimationFrame(Je)};(typeof document>"u"||document.visibilityState==="visible")&&(ie=requestAnimationFrame(Je));const Ge=()=>{document.visibilityState==="visible"&&ie===null?ie=requestAnimationFrame(Je):document.visibilityState!=="visible"&&ie!==null&&(cancelAnimationFrame(ie),ie=null)};return document.addEventListener("visibilitychange",Ge),()=>{document.removeEventListener("visibilitychange",Ge),ie!==null&&cancelAnimationFrame(ie)}},[]),l.useEffect(()=>{if(a==="starting"||a==="stopping"||a==="checking")return;let ie=!1;const Be=async()=>{try{const Ge=await pt("/api/openchamber/tunnel/status");if(!Ge.ok||ie)return;const ut=await Ge.json();if(ie)return;W(Array.isArray(ut.activeSessions)?ut.activeSessions:[]),L(new Set(Array.isArray(ut.managedRemoteTunnelTokenPresetIds)?ut.managedRemoteTunnelTokenPresetIds:[])),Me(typeof ut.localPort=="number"?ut.localPort:null)}catch{}},Je=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Be()},5e3);return()=>{ie=!0,window.clearInterval(Je)}},[a]);const Z=l.useCallback(async ie=>{M(!0);try{await Ct(ie),Object.prototype.hasOwnProperty.call(ie,"tunnelMode")&&ie.tunnelMode&&j(ie.tunnelMode),Object.prototype.hasOwnProperty.call(ie,"tunnelProvider")&&typeof ie.tunnelProvider=="string"&&v(ie.tunnelProvider),Object.prototype.hasOwnProperty.call(ie,"managedLocalTunnelConfigPath")&&O(ie.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ie,"managedRemoteTunnelPresets")&&ie.managedRemoteTunnelPresets&&V(ie.managedRemoteTunnelPresets)}catch{q.error(s("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{M(!1)}},[s]),y=l.useCallback(async(ie,Be)=>{S(!0);try{await Ct({tunnelBootstrapTtlMs:ie,tunnelSessionTtlMs:Be})}catch{q.error(s("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{S(!1)}},[s]),ue=l.useCallback(async ie=>{const Be=ie.token.trim();if(Be)try{const Je={...H,[ie.presetId]:Be};await Ct({managedRemoteTunnelPresetTokens:Je}),L(Ge=>{const ut=new Set(Ge);return ut.add(ie.presetId),ut})}catch{q.error(s("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[H,s]),Ie=l.useCallback(async ie=>{g(null),m(null);const Be=U.find(Ge=>Ge.provider===ie),Je=Be?.modes?.some(Ge=>Ge.key===F)?F:en(Be?.modes?.[0]?.key);await Z({tunnelProvider:ie,tunnelMode:Je}),Se(ie)},[U,Se,Z,F]),Oe=l.useCallback(async()=>{const ie=await Ll({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ie.success&&typeof ie.path=="string"&&ie.path.trim().length>0){const Be=ie.path.trim();if(!Qn(Be)){q.error(Ne);return}O(Be),await Z({managedLocalTunnelConfigPath:Be});return}De.current?.click()},[Ne,Z]),We=l.useCallback(ie=>{const Be=ie.trim();O(Be.length>0?Be:null)},[]),rt=l.useCallback(async()=>{if(P&&!Qn(P)){q.error(Ne);return}await Z({managedLocalTunnelConfigPath:P})},[Ne,P,Z]),it=l.useCallback(async()=>{O(null),await Z({managedLocalTunnelConfigPath:null})},[Z]),nt=l.useCallback(async ie=>{const Be=ie.target.files?.[0];if(!Be)return;const Je=Be.name.trim();if(Je.length!==0){if(!Qn(Je)){q.error(Ne);return}O(Je),await Z({managedLocalTunnelConfigPath:Je}),ie.target.value=""}},[Ne,Z]),dt=l.useCallback(async()=>{if(m(null),g(null),F==="managed-local"&&P&&!Qn(P)){m(Ne),q.error(Ne);return}r("starting");try{let ie="",Be="";if(F==="managed-remote"){if(!Pe){r("idle"),g(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),q.error(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}ie=Pe.hostname,Be=(H[Pe.id]||"").trim(),await Z({tunnelMode:"managed-remote",managedRemoteTunnelPresets:R})}const Je=await pt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:k,mode:F,...F==="managed-remote"&&Pe?{managedRemoteTunnelPresetId:Pe.id,managedRemoteTunnelPresetName:Pe.name}:{},...F==="managed-remote"&&ie?{managedRemoteTunnelHostname:ie}:{},...F==="managed-remote"&&Be?{managedRemoteTunnelToken:Be}:{},...F==="managed-local"&&P?{configPath:P}:{}})}),Ge=await Je.json();if(!Je.ok||!Ge.ok){if(F==="managed-remote"&&typeof Ge.error=="string"&&Ge.error.includes("Managed remote tunnel token is required")){r("idle"),g(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),q.error(s("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),m(Ge.error||s("settings.openchamber.tunnel.toast.startFailed")),q.error(Ge.error||s("settings.openchamber.tunnel.toast.startFailed"));return}const ut=typeof Ge.url=="string"?Ge.url:"";if(!ut){r("error"),m(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),q.error(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(o({url:ut,connectUrl:typeof Ge.connectUrl=="string"?Ge.connectUrl:null,bootstrapExpiresAt:typeof Ge.bootstrapExpiresAt=="number"?Ge.bootstrapExpiresAt:null}),c(Ge.activeTunnelMode?en(Ge.activeTunnelMode):Ge.mode?en(Ge.mode):F),W(Array.isArray(Ge.activeSessions)?Ge.activeSessions:[]),Array.isArray(Ge.managedRemoteTunnelTokenPresetIds)&&L(new Set(Ge.managedRemoteTunnelTokenPresetIds)),typeof Ge.localPort=="number"&&Me(Ge.localPort),typeof Ge.mode=="string"&&j(en(Ge.mode)),r("active"),Ge.replacedTunnel){const yt=typeof Ge.revokedBootstrapCount=="number"?Ge.revokedBootstrapCount:0,gt=typeof Ge.invalidatedSessionCount=="number"?Ge.invalidatedSessionCount:0;yt===1&>===1?q.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):yt===1?q.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:gt})):gt===1?q.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:yt})):q.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:yt,invalidatedSessionCount:gt}))}else q.success(s("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),m(s("settings.openchamber.tunnel.toast.startFailed")),q.error(s("settings.openchamber.tunnel.toast.startFailed"))}},[Ne,R,Z,Pe,H,s,k,F,P]),Ye=l.useCallback(async()=>{r("stopping");try{await pt("/api/openchamber/tunnel/stop",{method:"POST"});const ie=await pt("/api/openchamber/tunnel/status");if(ie.ok){const Be=await ie.json();W(Array.isArray(Be.activeSessions)?Be.activeSessions:[]),L(new Set(Array.isArray(Be.managedRemoteTunnelTokenPresetIds)?Be.managedRemoteTunnelTokenPresetIds:[])),Me(typeof Be.localPort=="number"?Be.localPort:null)}o(null),c(null),u(null),r("idle"),q.success(s("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),m(s("settings.openchamber.tunnel.toast.stopFailed")),q.error(s("settings.openchamber.tunnel.toast.stopFailed"))}},[s]),$e=l.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),x(!0),q.success(s("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>x(!1),2e3)}catch{q.error(s("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[s,i?.connectUrl]),mt=l.useCallback(async ie=>{const Be=ba.find(Je=>Je.value===ie);Be&&(ve(Be.ms),await y(Be.ms,we))},[y,we]),he=l.useCallback(async ie=>{const Be=ya.find(Je=>Je.value===ie);!Be||Be.ms===null||(ye(Be.ms),await y(Ce,Be.ms))},[Ce,y]),et=l.useCallback(async ie=>{g(null),m(null),a!=="active"&&a!=="stopping"&&a!=="starting"&&r("idle"),await Z({tunnelMode:ie,managedRemoteTunnelPresets:R})},[R,Z,a]),Xe=l.useCallback(async(ie,Be)=>{try{await Ct({managedRemoteTunnelPresets:Be})}catch{q.error(s("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[s]),He=l.useCallback(ie=>{const Be=R.find(Je=>Je.id===ie);Be&&(w(Be.id),g(null),Xe(Be,R))},[R,Xe]),bt=l.useCallback(async()=>{const ie=ne.trim(),Be=Ea(_),Je=fe.trim();if(!ie){q.error(s("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Be){q.error(s("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Je){q.error(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(R.some(yt=>yt.hostname===Be)){q.error(s("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ge={id:yb(),name:ie,hostname:Be},ut=[...R,Ge];V(ut),w(Ge.id),ee(yt=>({...yt,[Ge.id]:!0})),Q(yt=>({...yt,[Ge.id]:Je})),g(null),$(!1),re(""),oe(""),xe(""),await Z({tunnelMode:"managed-remote",managedRemoteTunnelPresets:ut,managedRemoteTunnelPresetTokens:{...H,[Ge.id]:Je}}),await ue({presetId:Ge.id,presetName:Ge.name,hostname:Ge.hostname,token:Je}),q.success(s("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[R,_,ne,fe,ue,Z,H,s]),wt=l.useCallback(async ie=>{const Be=R.find(gt=>gt.id===ie);if(!Be)return;const Je=R.filter(gt=>gt.id!==Be.id),Ge=Je[0]?.id||"",ut=Y===Be.id?Ge:Y,yt=Object.fromEntries(Object.entries(H).filter(([gt,Et])=>gt!==Be.id&&Et.trim().length>0));V(Je),w(ut),ee(gt=>{const Et={...gt};return delete Et[Be.id],Et}),Q(gt=>{const Et={...gt};return delete Et[Be.id],Et}),L(gt=>{const Et=new Set(gt);return Et.delete(Be.id),Et}),g(null),await Z({managedRemoteTunnelPresets:Je,managedRemoteTunnelPresetTokens:yt}),q.success(s("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[R,Z,Y,H,s]),Pt="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")})]}),Re.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(A,{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:Re.map(ie=>{const Be=ie.mode==="quick",Je=ie.mode==="managed-remote",Ge=Be?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Je?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",ut=ie.isActive?Be?"text-[var(--status-warning)]":Je?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",yt=s(Be?"settings.openchamber.tunnel.badge.quick":Je?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[t.jsx(A,{name:"checkbox-blank-circle-fill",className:le("size-2.5 shrink-0",ut)}),t.jsx("span",{className:le("typography-micro rounded border px-1.5 py-0.5 uppercase",Ge),children:yt}),t.jsx("span",{className:"typography-meta text-muted-foreground/80",children:s("settings.openchamber.tunnel.session.redeemedAt",{time:xb(ie.createdAt,e)})}),t.jsx("span",{className:"typography-meta text-foreground",children:ie.isActive?s("settings.openchamber.tunnel.session.expiresIn",{remaining:ie.remainingTextForSession}):ie.inactiveLabel===s("settings.openchamber.tunnel.state.inactive")?s("settings.openchamber.tunnel.state.inactive"):s("settings.openchamber.tunnel.session.inactiveWithReason",{reason:ie.inactiveLabel})})]},ie.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(A,{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:pe.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:pe.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(Tt,{value:k,onValueChange:ie=>{Ie(ie)},disabled:C||a==="starting"||a==="stopping",children:[t.jsx(Ft,{className:"max-w-[16rem]",children:t.jsx(zt,{placeholder:s("settings.openchamber.tunnel.field.providerPlaceholder"),children:cc(k)})}),t.jsxs(Lt,{children:[U.length>0?U.map(ie=>t.jsx(ht,{value:ie.provider,children:t.jsx(el,{provider:ie.provider})},ie.provider)):t.jsx(ht,{value:"cloudflare",children:t.jsx(el,{provider:"cloudflare"})}),t.jsx(ht,{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:ce.map(ie=>t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(J,{variant:"chip",size:"xs","aria-pressed":F===ie.value,className:"!font-normal",onClick:()=>{et(ie.value)},disabled:C||a==="starting"||a==="stopping",children:n(ie.labelKey)})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:n(ie.tooltipKey)})]},ie.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(Tt,{value:Hr(ba,Ce,"1800000"),onValueChange:ie=>{mt(ie)},disabled:E||C||a==="starting"||a==="stopping",children:[t.jsx(Ft,{className:"max-w-[11rem] min-w-0",children:t.jsx(zt,{className:"truncate",children:tl(ba,Ce,"1800000")})}),t.jsx(Lt,{children:ba.map(ie=>t.jsx(ht,{value:ie.value,children:ie.label},ie.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(Tt,{value:Hr(ya,we,"28800000"),onValueChange:ie=>{he(ie)},disabled:E||C||a==="starting"||a==="stopping",children:[t.jsx(Ft,{className:"max-w-[11rem] min-w-0",children:t.jsx(zt,{className:"truncate",children:tl(ya,we,"28800000")})}),t.jsx(Lt,{children:ya.map(ie=>t.jsx(ht,{value:ie.value,children:ie.label},ie.value))})]})]})]}),F==="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(A,{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")}),G&&t.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:s("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),F==="managed-remote"&&t.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Ke=="number"&&t.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:t.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[s("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",t.jsxs("code",{children:["http://localhost:",Ke]})]})}),t.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),t.jsxs(J,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>$(ie=>!ie),disabled:a==="starting"||a==="stopping"||C,children:[t.jsx(A,{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((ie,Be)=>{const Je=H[ie.id]||"",Ge=z.has(ie.id),ut=B[ie.id]??!1;return t.jsx("div",{className:le(Be<R.length-1&&"border-b border-[var(--surface-subtle)]"),children:t.jsxs(bn,{open:ut,onOpenChange:yt=>{ee(gt=>({...gt,[ie.id]:yt})),yt&&He(ie.id)},className:"py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-2 px-3",children:[t.jsxs(yn,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:a==="starting"||a==="stopping"||C,children:[ut?t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):t.jsx(A,{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:ie.name})]}),t.jsx(J,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":s("settings.openchamber.tunnel.actions.removePresetAria",{name:ie.name}),onClick:()=>{wt(ie.id)},disabled:a==="starting"||a==="stopping"||C,children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(vn,{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:ie.hostname})]}),t.jsx(tt,{type:"password",value:Je,onChange:yt=>{const gt=yt.target.value;g(null),Q(Et=>({...Et,[ie.id]:gt}))},onBlur:yt=>{const gt=yt.currentTarget.value.trim();gt&&ue({presetId:ie.id,presetName:ie.name,hostname:ie.hostname,token:gt})},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(J,{variant:"ghost",size:"xs",className:"!font-normal",disabled:a==="starting"||a==="stopping"||Je.trim().length===0,onClick:()=>{ue({presetId:ie.id,presetName:ie.name,hostname:ie.hostname,token:Je})},children:s("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},ie.id)})}):t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),X&&t.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[t.jsx(tt,{value:ne,onChange:ie=>re(ie.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:C||a==="starting"||a==="stopping"}),t.jsx(tt,{value:_,onChange:ie=>oe(ie.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:C||a==="starting"||a==="stopping"}),t.jsx(tt,{type:"password",value:fe,onChange:ie=>xe(ie.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:C||a==="starting"||a==="stopping"}),typeof Ke=="number"&&t.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[s("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",t.jsxs("code",{children:["http://localhost:",Ke]}),"."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{bt()},disabled:C||a==="starting"||a==="stopping",children:s("settings.common.actions.saveChanges")}),t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{$(!1),re(""),oe(""),xe("")},disabled:C||a==="starting"||a==="stopping",children:s("settings.common.actions.cancel")})]})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("p",{className:"typography-meta text-muted-foreground/80",children:s("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),t.jsxs(It,{children:[t.jsx(Dt,{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(A,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(At,{sideOffset:8,className:"max-w-xs",children:s("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!Pe&&I&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:I})]}),F==="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:ie=>{nt(ie)}}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(tt,{value:P||"",onChange:ie=>{We(ie.target.value)},onBlur:()=>{rt()},placeholder:s("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:a==="starting"||a==="stopping"||C}),t.jsx(J,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Oe()},disabled:a==="starting"||a==="stopping"||C,children:t.jsx(A,{name:"folder",className:"size-3.5"})}),P&&t.jsx(J,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{it()},disabled:a==="starting"||a==="stopping"||C,children:t.jsx(A,{name:"close",className:"size-3.5"})})]}),t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s(P?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Ae&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ne})]})}),!Ue&&t.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[t.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(A,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),t.jsxs("div",{className:"space-y-1",children:[F==="managed-remote"&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:s("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),t.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{je(mb)},children:[s("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),t.jsx(A,{name:"external-link",className:"size-3.5"})]})]}),F==="managed-local"&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:s("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),t.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{je(ub)},children:[s("settings.openchamber.tunnel.actions.openManagedLocalDocs"),t.jsx(A,{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(br.find(ie=>ie.value===F)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),F==="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(Tt,{value:Y||(R[0]?.id??""),onValueChange:ie=>{He(ie)},disabled:C||a==="starting"||a==="stopping"||R.length<=1,children:[t.jsx(Ft,{children:t.jsx(zt,{placeholder:s("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Pe?.name})}),t.jsx(Lt,{fitContent:!0,children:R.map(ie=>t.jsx(ht,{value:ie.id,children:ie.name},ie.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(A,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),t.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:s("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),t.jsx(J,{size:"sm",variant:"outline",onClick:dt,disabled:a==="starting"||C||F==="managed-remote"&&!Pe||F==="managed-local"&&Ae,className:le(Pt,a==="starting"&&"opacity-70"),children:a==="starting"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"})," ",s("settings.openchamber.tunnel.actions.startingTunnel")]}):s("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ue&&i&&t.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),t.jsx("p",{className:"typography-meta font-medium text-foreground",children:s("settings.openchamber.tunnel.state.tunnelReady")})]}),t.jsxs("div",{children:[t.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:s("settings.openchamber.tunnel.field.publicUrlHint")}),t.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.url})]}),Fe&&i.connectUrl&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:s("settings.openchamber.tunnel.field.connectLink")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.connectUrl}),t.jsxs(J,{size:"sm",variant:"ghost",onClick:$e,className:"shrink-0 gap-1.5",children:[h?t.jsx(A,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):t.jsx(A,{name:"file-copy",className:"size-3.5"}),s(h?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),t.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[s("settings.openchamber.tunnel.field.expires"),": ",i.bootstrapExpiresAt?se:s("settings.openchamber.tunnel.state.never")]})]}),t.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[f?t.jsx("img",{src:f,alt:s("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):t.jsx("div",{className:"size-48 rounded bg-muted/30"}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),t.jsx("div",{className:"pt-1",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(J,{size:"sm",variant:"outline",onClick:dt,disabled:a==="stopping"||C||F==="managed-local"&&Ae,className:Pt,children:[t.jsx(A,{name:"restart",className:"size-3.5"}),s("settings.openchamber.tunnel.actions.newConnectLink")]}),t.jsx(J,{size:"sm",variant:"ghost",onClick:Ye,disabled:a==="stopping"||C,className:"gap-2 text-[var(--status-error)]",children:a==="stopping"?t.jsxs(t.Fragment,{children:[t.jsx(A,{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(J,{size:"sm",variant:"ghost",onClick:dt,children:s("settings.openchamber.tunnel.actions.retry")})]})]})},dc=()=>{const{t:s}=ot(),[e,n]=ge.useState(""),[a,r]=ge.useState(!0),[i,o]=ge.useState(!1),d=Le(m=>m.showOpenCodeUpdateNotifications),c=Le(m=>m.setShowOpenCodeUpdateNotifications);ge.useEffect(()=>{let m=!1;return(async()=>{try{const I=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!I.ok)return;const g=await I.json().catch(()=>null);if(m||!g)return;const h=typeof g.opencodeBinary=="string"?g.opencodeBinary.trim():"";n(h)}catch{}finally{m||r(!1)}})(),()=>{m=!0}},[]);const f=ge.useCallback(async()=>{if(!(typeof window>"u")&&ls())try{const m=await Ll();m.success&&m.path&&m.path.trim().length>0&&n(m.path.trim())}catch{}},[]),u=ge.useCallback(async()=>{o(!0);try{const m=e.trim(),I=m.length>=2&&(m.startsWith('"')&&m.endsWith('"')||m.startsWith("'")&&m.endsWith("'"))?m.slice(1,-1).trim():m;await Ct({opencodeBinary:I}),await Mn({message:s("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{o(!1)}},[s,e]),p=ge.useCallback(m=>{c(m),Ct({showOpenCodeUpdateNotifications:m})},[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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(At,{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(tt,{value:e,onChange:m=>n(m.target.value),placeholder:s("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:a||i,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),t.jsx(J,{type:"button",variant:"outline",size:"xs",onClick:f,disabled:a||i||!ls(),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(A,{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(St,{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(J,{type:"button",size:"xs",onClick:u,disabled:a||i,className:"shrink-0 !font-normal",children:s(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},mc=()=>{const{t:s}=ot(),e=ls()&&zn(),[n,a]=ge.useState(!1),[r,i]=ge.useState(!1),[o,d]=ge.useState(""),[c,f]=ge.useState(""),[u,p]=ge.useState(!1),[m,I]=ge.useState(null),[g,h]=ge.useState(!0),[x,E]=ge.useState(!1),[S,C]=ge.useState(!1),[M,k]=ge.useState(!1),[v,b]=ge.useState(!1),[D,U]=ge.useState(!1),[T,F]=ge.useState(!1),[j,P]=ge.useState(!1),[O,R]=ge.useState(null),[V,B]=ge.useState(null);ge.useEffect(()=>{if(!e){h(!1);return}let _=!1;return(async()=>{try{const oe=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!oe.ok)throw new Error(s("settings.openchamber.desktopNetwork.error.loadFailed"));const fe=await oe.json().catch(()=>null);if(_)return;const xe=fe?.desktopLanAccessEnabled===!0,Ce=typeof fe?.desktopUiPassword=="string"?fe.desktopUiPassword:"";a(xe),i(xe),d(Ce),f(Ce),p(fe?.desktopLanAccessActive===!0),I(typeof fe?.desktopLanAccessBlockedReason=="string"?fe.desktopLanAccessBlockedReason:null),R(null)}catch(oe){_||R(oe instanceof Error?oe.message:s("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{_||h(!1)}})(),()=>{_=!0}},[e,s]),ge.useEffect(()=>{if(!e){C(!1);return}let _=!1;return(async()=>{const oe=await nu();_||(C(oe?.supported===!0),k(oe?.enabled===!0))})(),()=>{_=!0}},[e]),ge.useEffect(()=>{if(!e){U(!1);return}let _=!1;return(async()=>{const oe=await au();_||(U(oe?.supported===!0),F(oe?.enabled===!0))})(),()=>{_=!0}},[e]),ge.useEffect(()=>{if(!e||!r){B(null);return}let _=!1;return(async()=>{const oe=await Fl();_||B(oe)})(),()=>{_=!0}},[r,e]);const ee=r!==n||c!==o,Y=ge.useMemo(()=>{if(typeof window>"u")return null;const oe=Kn()||window.location.href;let fe=0;try{fe=Number(new URL(oe).port)}catch{fe=Number(window.location.port)}return Number.isFinite(fe)&&fe>0?fe:null},[]),w=r&&u&&V&&Y?`http://${V}:${Y}`:null,H=r&&!c.trim(),Q=n&&!u&&m==="missing-password",z=g||x||!ee||H,L=ge.useCallback(()=>{i(_=>!_)},[]),X=ge.useCallback(_=>{f(_),_.trim()||i(!1)},[]),$=ge.useCallback(async()=>{if(!S||v)return;const _=!M;k(_),b(!0),R(null);try{const oe=await ru(_);if(!oe?.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));k(oe.enabled)}catch(oe){k(!_),R(oe instanceof Error?oe.message:s("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{b(!1)}},[v,M,S,s]),ne=ge.useCallback(async()=>{if(!D||j)return;const _=!T;F(_),P(!0),R(null);try{const oe=await iu(_);if(!oe?.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));F(oe.enabled)}catch(oe){F(!_),R(oe instanceof Error?oe.message:s("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{P(!1)}},[j,T,D,s]),re=ge.useCallback(async()=>{if(ee){E(!0),R(null);try{if(!(await pt("/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 ou())throw new Error(s("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(_){R(_ instanceof Error?_.message:s("settings.openchamber.desktopNetwork.error.saveFailed")),E(!1)}}},[c,r,ee,s]);return e?t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.desktopNetwork.title")})}),t.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[S?t.jsxs("div",{"data-settings-item":"sessions.desktop-launch-at-login",className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:$,onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),$())},children:[t.jsx(St,{checked:M,onChange:$,ariaLabel:s("settings.openchamber.desktopNetwork.field.launchAtLoginAria"),disabled:v}),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,D?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:ne,onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),ne())},children:[t.jsx(St,{checked:T,onChange:ne,ariaLabel:s("settings.openchamber.desktopNetwork.field.keepAwakeAria"),disabled:j}),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(tt,{id:"desktop-ui-password",type:"password",className:"h-7 max-w-sm",value:c,onChange:_=>X(_.target.value),placeholder:s("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:g||x,required:r,"aria-invalid":H}),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:L,onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),L())},children:[t.jsx(St,{checked:r,onChange:L,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")}),H||Q?t.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:s("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]})]}),O?t.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:O}):null,w?t.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[s(ee&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),t.jsx("span",{className:"font-mono text-foreground",children:w})]}):null,t.jsx("div",{className:"flex justify-start py-1.5",children:t.jsx(J,{type:"button",size:"xs",onClick:re,disabled:z,className:"shrink-0 !font-normal",children:s(x?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},jb=new Set(["shift","control","alt","meta"]),wb=s=>{if(jb.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=Em(s.key);return n?(e.push(n),Pn(e.join("+"))):null},Nb=()=>{const s=st.c(61),{t:e}=ot();let n;s[0]!==e?(n=_=>e(_),s[0]=e,s[1]=n):n=s[1];const a=n,r=Le(kb),i=Le(Sb),o=Le(Cb),d=Le(Pb);let c;s[2]===Symbol.for("react.memo_cache_sentinel")?(c=Dm(),s[2]=c):c=s[2];const f=c;let u;s[3]!==a?(u=(_,oe)=>{const fe=`settings.openchamber.keyboardShortcuts.action.${_}.label`,xe=a(fe);return xe===fe?oe:xe},s[3]=a,s[4]=u):u=s[4];const p=u,[m,I]=l.useState(null);let g;s[5]===Symbol.for("react.memo_cache_sentinel")?(g={},s[5]=g):g=s[5];const[h,x]=l.useState(g),[E,S]=l.useState(""),[C,M]=l.useState(""),[k,v]=l.useState(null),b=Ib;let D;s[6]!==r?(D=(_,oe)=>{const fe=Pn(oe);for(const xe of f){if(xe.id===_)continue;const Ce=wi(xe.id,r);if(Pn(Ce)===fe)return xe.id}return null},s[6]=r,s[7]=D):D=s[7];const U=D;let T;s[8]!==U||s[9]!==i||s[10]!==r||s[11]!==e?(T=(_,oe)=>{const fe=Pn(oe),xe=U(_,fe);if(xe){v({actionId:_,combo:fe,conflictActionId:xe}),S("");return}const Ce={...r,[_]:fe};i(_,fe),b(Ce),v(null),S(""),M(Ni(fe)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(ve=>{const we={...ve};return delete we[_],we})},s[8]=U,s[9]=i,s[10]=r,s[11]=e,s[12]=T):T=s[12];const F=T;let j;s[13]!==k||s[14]!==i||s[15]!==r||s[16]!==e?(j=()=>{if(!k)return;const _={...r,[k.conflictActionId]:ki,[k.actionId]:k.combo};i(k.conflictActionId,ki),i(k.actionId,k.combo),b(_),v(null),S(""),M(Ni(k.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(oe=>{const fe={...oe};return delete fe[k.actionId],fe})},s[13]=k,s[14]=i,s[15]=r,s[16]=e,s[17]=j):j=s[17];const P=j;let O;s[18]!==o||s[19]!==r?(O=_=>{const oe={...r};delete oe[_],o(_),b(oe),x(fe=>{const xe={...fe};return delete xe[_],xe}),v(null),S(""),M("")},s[18]=o,s[19]=r,s[20]=O):O=s[20];const R=O;let V;s[21]!==e?(V=e("settings.openchamber.keyboardShortcuts.title"),s[21]=e,s[22]=V):V=s[22];let B;s[23]!==V?(B=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:V}),s[23]=V,s[24]=B):B=s[24];let ee;s[25]!==d?(ee=()=>{d(),b({}),x({}),v(null),S(""),M("")},s[25]=d,s[26]=ee):ee=s[26];let Y;s[27]!==e?(Y=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),s[27]=e,s[28]=Y):Y=s[28];let w;s[29]!==ee||s[30]!==Y?(w=t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ee,children:Y}),s[29]=ee,s[30]=Y,s[31]=w):w=s[31];let H;s[32]===Symbol.for("react.memo_cache_sentinel")?(H=t.jsx(Dt,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[32]=H):H=s[32];let Q;s[33]!==e?(Q=e("settings.openchamber.keyboardShortcuts.tooltip"),s[33]=e,s[34]=Q):Q=s[34];let z;s[35]!==Q?(z=t.jsxs(It,{children:[H,t.jsx(At,{sideOffset:8,className:"max-w-xs",children:Q})]}),s[35]=Q,s[36]=z):z=s[36];let L;s[37]!==w||s[38]!==z||s[39]!==B?(L=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[B,w,z]})}),s[37]=w,s[38]=z,s[39]=B,s[40]=L):L=s[40];let X;s[41]!==P||s[42]!==E||s[43]!==k||s[44]!==e||s[45]!==C?(X=(E||C||k)&&t.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[k&&t.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[t.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),t.jsxs("div",{className:"flex gap-2 shrink-0",children:[t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:P,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),t.jsx(J,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>v(null),children:e("settings.common.actions.cancel")})]})]}),E&&t.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:E}),C&&t.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:C})]}),s[41]=P,s[42]=E,s[43]=k,s[44]=e,s[45]=C,s[46]=X):X=s[46];let $;s[47]!==p||s[48]!==m||s[49]!==h||s[50]!==R||s[51]!==F||s[52]!==r||s[53]!==e?($=f.map((_,oe)=>{const fe=wi(_.id,r),xe=h[_.id],Ce=xe??fe,ve=typeof xe=="string"&&Pn(xe)!==Pn(fe);return t.jsxs("div",{className:le("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",oe>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(_.id,_.label)})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsx(tt,{readOnly:!0,value:m===_.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):Am(Ce),onFocus:()=>{I(_.id),S("")},onBlur:()=>{m===_.id&&I(null)},onKeyDown:we=>{if(we.preventDefault(),we.stopPropagation(),we.key==="Escape"){I(null);return}const ye=wb(we);ye&&(x(se=>({...se,[_.id]:ye})),I(null),v(null),S(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),t.jsx(J,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const we=h[_.id];if(!we){S(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}F(_.id,we)},disabled:!ve,children:e("settings.common.actions.saveChanges")}),t.jsx(J,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>R(_.id),children:e("settings.common.actions.reset")})]})]},_.id)}),s[47]=p,s[48]=m,s[49]=h,s[50]=R,s[51]=F,s[52]=r,s[53]=e,s[54]=$):$=s[54];let ne;s[55]!==$?(ne=t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:$}),s[55]=$,s[56]=ne):ne=s[56];let re;return s[57]!==L||s[58]!==X||s[59]!==ne?(re=t.jsxs("div",{"data-settings-item":"shortcuts.keyboard-shortcuts",className:"mb-8",children:[L,X,ne]}),s[57]=L,s[58]=X,s[59]=ne,s[60]=re):re=s[60],re};function kb(s){return s.shortcutOverrides}function Sb(s){return s.setShortcutOverride}function Cb(s){return s.clearShortcutOverride}function Pb(s){return s.resetAllShortcutOverrides}function Ib(s){Ct({shortcutOverrides:s})}const uc=()=>{const s=st.c(2),[e,n]=l.useState(0);let a,r;return s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>lu(()=>n(Kb)),r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),l.useEffect(a,r),e},Db=s=>{const e=st.c(20),{section:n}=s,{isMobile:a}=Is();uc();let r;e[0]!==a?(r=a&&hn(),e[0]=a,e[1]=r):r=e[1];const i=r;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=fs(),e[2]=o):o=e[2];const d=o;let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=ls()&&zn(),e[3]=c):c=e[3];const f=c;if(!n){let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=t.jsx(si,{}),e[4]=g):g=e[4];let h,x,E;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(oc,{})}),x=f&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(mc,{})}),E=!d&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(dc,{})}),e[5]=h,e[6]=x,e[7]=E):(h=e[5],x=e[6],E=e[7]);let S;e[8]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(rc,{})}),e[8]=S):S=e[8];let C;e[9]===Symbol.for("react.memo_cache_sentinel")?(C=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(ic,{})}),e[9]=C):C=e[9];let M;e[10]!==i?(M=i&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Kl,{})}),e[10]=i,e[11]=M):M=e[11];let k;return e[12]!==M?(k=t.jsx(qt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[g,h,x,E,S,C,M]})}),e[12]=M,e[13]=k):k=e[13],k}let u;e[14]!==n?(u=()=>{switch(n){case"visual":return t.jsx(Eb,{});case"chat":return t.jsx(Mb,{});case"sessions":return t.jsx(Rb,{});case"shortcuts":return t.jsx(Ab,{});case"git":return t.jsx(Tb,{});case"github":return t.jsx(Fb,{});case"notifications":return t.jsx(Lb,{});case"voice":return t.jsx(Ob,{});case"tunnel":return t.jsx(zb,{});default:return null}},e[14]=n,e[15]=u):u=e[15];const p=u;let m;e[16]!==p?(m=p(),e[16]=p,e[17]=m):m=e[17];let I;return e[18]!==m?(I=t.jsx(qt,{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:m})}),e[18]=m,e[19]=I):I=e[19],I},Ab=()=>{const s=st.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Nb,{}),s[0]=e):e=s[0],e},Eb=()=>{const s=st.c(3);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=fs(),s[0]=e):e=s[0];const n=e;let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=n?[]:["weekStart"],s[1]=a):a=s[1];let r;return s[2]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(si,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a,"fontSize","terminalFontSize","fileEditorKeymap","spacing","inputBarOffset","expandedEditorToolbar",...n?[]:["terminalQuickKeys"],"reportUsage"]}),s[2]=r):r=s[2],r},Mb=()=>{const s=st.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(si,{visibleSettings:["sessionAssist","chatRenderMode","messageTransport","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader","wideChatLayout","splitAssistantMessageActions","diffLayout","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck"]}),s[0]=e):e=s[0],e},Rb=()=>{const s=st.c(7);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=fs(),s[0]=e):e=s[0];const n=e;uc();let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=ls()&&zn(),s[1]=a):a=s[1];const r=a;let i,o,d;s[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(oc,{}),o=r&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(mc,{})}),d=!n&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(dc,{})}),s[2]=i,s[3]=o,s[4]=d):(i=s[2],o=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(rc,{})}),s[5]=c):c=s[5];let f;return s[6]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsxs("div",{className:"space-y-6",children:[i,o,d,c,t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(ic,{})})]}),s[6]=f):f=s[6],f},Tb=()=>{const s=st.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx("div",{className:"space-y-6",children:t.jsx(sc,{})}),s[0]=e):e=s[0],e},Fb=()=>{const s=st.c(1);if(fs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(nc,{}),s[0]=e):e=s[0],e},Lb=()=>{const s=st.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(rb,{}),s[0]=e):e=s[0],e},Ob=()=>{const s=st.c(1);if(fs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(db,{}),s[0]=e):e=s[0],e},zb=()=>{const s=st.c(1);if(fs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(vb,{}),s[0]=e):e=s[0],e};function Kb(s){return s+1}const pc=[{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}],Ub={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function En(s){const e=s.trim().toLowerCase();return pc.find(n=>n.slug===e)??null}function ni(s){const e=(s??"").trim().toLowerCase();if(!e)return"home";const n=Ub[e];if(n)return n;const a=En(e);return a?a.slug:"home"}const $b=[{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.openchamber.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.openchamber.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"],isAvailable:s=>!s.isVSCode},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:s=>!s.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:s=>!s.isVSCode},{id:"appearance.window-transparency",page:"appearance",titleKey:"settings.openchamber.visual.field.macVibrancy",descriptionKey:"settings.openchamber.visual.field.macVibrancyHint",keywords:["transparent","transparency","vibrancy","blur","macos","opaque"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.openchamber.visual.field.dockBadge",descriptionKey:"settings.openchamber.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:s=>s.isMac},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:s=>s.isWeb&&!s.isDesktop&&!s.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:s=>s.isWeb&&!s.isDesktop&&!s.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.openchamber.visual.field.mobileKeyboardMode",descriptionKey:"settings.openchamber.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:s=>s.isMobile&&s.isWeb&&!s.isDesktop&&!s.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:s=>!s.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"]},{id:"appearance.expanded-editor-toolbar",page:"appearance",titleKey:"settings.openchamber.visual.field.expandedEditorToolbar",keywords:["editor","toolbar","tabs","docked","files"]},{id:"appearance.file-editor-keymap",page:"appearance",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.terminal-quick-keys",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:s=>!s.isMobile&&!s.isVSCode},{id:"appearance.usage-reports",page:"appearance",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"chat",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:s=>!s.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:s=>!s.isMobile},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.openchamber.defaults.smallModel.title",descriptionKey:"settings.openchamber.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.openchamber.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"sessions.desktop-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"],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 nl(s){return s.trim().toLocaleLowerCase()}function Bb({query:s,runtimeCtx:e,visiblePageSlugs:n,t:a,getPageTitle:r}){const i=nl(s);if(!i)return[];const o=n?new Set(n):null,d=i.split(/\s+/).filter(Boolean);return $b.flatMap(c=>{if(o&&!o.has(c.page))return[];const f=En(c.page);if(!f||f.isAvailable&&!f.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const u=a(c.titleKey),p=c.descriptionKey?a(c.descriptionKey):null,m=nl([u,p,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return d.every(I=>m.includes(I))?[{...c,title:u,description:p,pageTitle:r(c.page)}]:[]})}const Wr=176,qr=280,al=8,gc="__openchamberSettingsDetail";function vr(s){return Math.min(qr,Math.max(Wr,s))}const Vb=["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"],_b={icon:"chat-thread"},Hb="__add_provider__";function Wb(s,e){const n=fs(),a=!s&&hn();return{isVSCode:n,isWeb:a,isDesktop:s,isMobile:e}}function rl(s,e){return s.isAvailable?s.isAvailable(e):!0}function Gr(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function Yn(s,e){const n=new Set(e);let a=s,r=1;for(;n.has(a);)a=`${s}-${r}`,r+=1;return a}function jr(s){if(!Gr(s))return null;const e=s[gc];if(!Gr(e))return null;const n=e.page,a=e.stage;return typeof n!="string"||a!=="page-content"?null:{page:ni(n),stage:a}}function qb(){return typeof window>"u"||!Gr(window.history.state)?{}:window.history.state}function hc(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 _b.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 wr=s=>{const e=st.c(95),{onOpen:n}=s,{t:a}=ot();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 o;e[4]!==a?(o=a("settings.view.home.description"),e[4]=a,e[5]=o):o=e[5];let d;e[6]!==o?(d=t.jsx("p",{className:"typography-ui text-muted-foreground",children:o}),e[6]=o,e[7]=d):d=e[7];let c;e[8]!==i||e[9]!==d?(c=t.jsxs("div",{className:"space-y-1",children:[i,d]}),e[8]=i,e[9]=d,e[10]=c):c=e[10];let f;e[11]!==n?(f=()=>n("providers"),e[11]=n,e[12]=f):f=e[12];let u;e[13]===Symbol.for("react.memo_cache_sentinel")?(u=le("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=u):u=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 m;e[16]!==p?(m=t.jsx("div",{className:"typography-ui-label text-foreground",children:p}),e[16]=p,e[17]=m):m=e[17];let I;e[18]!==a?(I=a("settings.view.home.cards.providers.description"),e[18]=a,e[19]=I):I=e[19];let g;e[20]!==I?(g=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:I}),e[20]=I,e[21]=g):g=e[21];let h;e[22]!==g||e[23]!==f||e[24]!==m?(h=t.jsxs("button",{type:"button",onClick:f,className:u,children:[m,g]}),e[22]=g,e[23]=f,e[24]=m,e[25]=h):h=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=le("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=E):E=e[28];let S;e[29]!==a?(S=a("settings.view.home.cards.agents.title"),e[29]=a,e[30]=S):S=e[30];let C;e[31]!==S?(C=t.jsx("div",{className:"typography-ui-label text-foreground",children:S}),e[31]=S,e[32]=C):C=e[32];let M;e[33]!==a?(M=a("settings.view.home.cards.agents.description"),e[33]=a,e[34]=M):M=e[34];let k;e[35]!==M?(k=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:M}),e[35]=M,e[36]=k):k=e[36];let v;e[37]!==x||e[38]!==C||e[39]!==k?(v=t.jsxs("button",{type:"button",onClick:x,className:E,children:[C,k]}),e[37]=x,e[38]=C,e[39]=k,e[40]=v):v=e[40];let b;e[41]!==n?(b=()=>n("skills.catalog"),e[41]=n,e[42]=b):b=e[42];let D;e[43]===Symbol.for("react.memo_cache_sentinel")?(D=le("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=D):D=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 T;e[46]!==U?(T=t.jsx("div",{className:"typography-ui-label text-foreground",children:U}),e[46]=U,e[47]=T):T=e[47];let F;e[48]!==a?(F=a("settings.view.home.cards.skillsCatalog.description"),e[48]=a,e[49]=F):F=e[49];let j;e[50]!==F?(j=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:F}),e[50]=F,e[51]=j):j=e[51];let P;e[52]!==b||e[53]!==T||e[54]!==j?(P=t.jsxs("button",{type:"button",onClick:b,className:D,children:[T,j]}),e[52]=b,e[53]=T,e[54]=j,e[55]=P):P=e[55];let O;e[56]!==n?(O=()=>n("mcp"),e[56]=n,e[57]=O):O=e[57];let R;e[58]===Symbol.for("react.memo_cache_sentinel")?(R=le("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 V;e[59]!==a?(V=a("settings.view.home.cards.mcp.title"),e[59]=a,e[60]=V):V=e[60];let B;e[61]!==V?(B=t.jsx("div",{className:"typography-ui-label text-foreground",children:V}),e[61]=V,e[62]=B):B=e[62];let ee;e[63]!==a?(ee=a("settings.view.home.cards.mcp.description"),e[63]=a,e[64]=ee):ee=e[64];let Y;e[65]!==ee?(Y=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ee}),e[65]=ee,e[66]=Y):Y=e[66];let w;e[67]!==O||e[68]!==B||e[69]!==Y?(w=t.jsxs("button",{type:"button",onClick:O,className:R,children:[B,Y]}),e[67]=O,e[68]=B,e[69]=Y,e[70]=w):w=e[70];let H;e[71]!==n?(H=()=>n("usage"),e[71]=n,e[72]=H):H=e[72];let Q;e[73]===Symbol.for("react.memo_cache_sentinel")?(Q=le("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=Q):Q=e[73];let z;e[74]!==a?(z=a("settings.view.home.cards.usage.title"),e[74]=a,e[75]=z):z=e[75];let L;e[76]!==z?(L=t.jsx("div",{className:"typography-ui-label text-foreground",children:z}),e[76]=z,e[77]=L):L=e[77];let X;e[78]!==a?(X=a("settings.view.home.cards.usage.description"),e[78]=a,e[79]=X):X=e[79];let $;e[80]!==X?($=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:X}),e[80]=X,e[81]=$):$=e[81];let ne;e[82]!==H||e[83]!==L||e[84]!==$?(ne=t.jsxs("button",{type:"button",onClick:H,className:Q,children:[L,$]}),e[82]=H,e[83]=L,e[84]=$,e[85]=ne):ne=e[85];let re;e[86]!==h||e[87]!==v||e[88]!==P||e[89]!==w||e[90]!==ne?(re=t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[h,v,P,w,ne]}),e[86]=h,e[87]=v,e[88]=P,e[89]=w,e[90]=ne,e[91]=re):re=e[91];let _;return e[92]!==re||e[93]!==c?(_=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,re]})}),e[92]=re,e[93]=c,e[94]=_):_=e[94],_},Gb=s=>{const e=st.c(127),{onClose:n,forceMobile:a,isWindowed:r,visiblePageSlugs:i,initialMobileStage:o}=s,d=o===void 0?"nav":o,{t:c}=ot(),f=Is(),u=a??f.isMobile,p=Le(Jb),m=Le(Qb),I=Le(Yb);let g;e[0]!==p?(g=ni(p),e[0]=p,e[1]=g):g=e[1];const h=g,[x,E]=l.useState(d),S=l.useRef(null),[C,M]=l.useState(216),[k,v]=l.useState(""),[b,D]=l.useState(null),[U,T]=l.useState(0),[F,j]=l.useState(!1),[P,O]=l.useState(!1),R=l.useRef(0),V=l.useRef(C),B=l.useRef(null);let ee;e[2]===Symbol.for("react.memo_cache_sentinel")?(ee=[],e[2]=ee):ee=e[2];const Y=l.useRef(ee),w=l.useRef(0),H=l.useRef(!1);let Q;e[3]===Symbol.for("react.memo_cache_sentinel")?(Q=ls(),e[3]=Q):Q=e[3];const z=Q;let L;e[4]===Symbol.for("react.memo_cache_sentinel")?(L=ls()&&zn(),e[4]=L):L=e[4];const X=L;let $;e[5]===Symbol.for("react.memo_cache_sentinel")?($=ls()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",e[5]=$):$=e[5];const ne=$;let re;e[6]!==u?(re=Wb(z,u),e[6]=u,e[7]=re):re=e[7];const _=re;let oe;if(e[8]!==u||e[9]!==_||e[10]!==i){const ct=i?new Set(i):null;let at;e[12]!==_?(at=Gt=>rl(Gt,_),e[12]=_,e[13]=at):at=e[13];let Rt;e[14]!==_.isVSCode?(Rt=Gt=>!(_.isVSCode&&Gt.slug==="projects"),e[14]=_.isVSCode,e[15]=Rt):Rt=e[15];let Yt;e[16]!==u?(Yt=Gt=>!(u&&Gt.slug==="shortcuts"),e[16]=u,e[17]=Yt):Yt=e[17],oe=pc.filter(Xb).filter(Gt=>!ct||ct.has(Gt.slug)).filter(at).filter(Rt).filter(Yt),e[8]=u,e[9]=_,e[10]=i,e[11]=oe}else oe=e[11];const fe=oe;let xe;e[18]===Symbol.for("react.memo_cache_sentinel")?(xe=new Map(Vb.map(Zb)),e[18]=xe):xe=e[18];const Ce=xe;let ve;if(e[19]!==fe){let ct;e[21]===Symbol.for("react.memo_cache_sentinel")?(ct=(at,Rt)=>(Ce.get(at.slug)??999)-(Ce.get(Rt.slug)??999),e[21]=ct):ct=e[21],ve=fe.slice().sort(ct),e[19]=fe,e[20]=ve}else ve=e[20];const we=ve,ye=os(ey);let se,de;e[22]!==F?(se=()=>{if(typeof window>"u")return;const ct=()=>{if(!F){const at=vr(Math.floor(window.innerWidth*.12));M(at)}};return window.addEventListener("resize",ct),()=>window.removeEventListener("resize",ct)},de=[F],e[22]=F,e[23]=se,e[24]=de):(se=e[23],de=e[24]),l.useEffect(se,de);let be,W;e[25]!==P?(be=()=>{if(!P)return;const ct=Rt=>{const Yt=Rt.clientX-R.current,Gt=vr(V.current+Yt);M(Gt),j(!0)},at=()=>O(!1);return window.addEventListener("pointermove",ct),window.addEventListener("pointerup",at,{once:!0}),()=>{window.removeEventListener("pointermove",ct),window.removeEventListener("pointerup",at)}},W=[P],e[25]=P,e[26]=be,e[27]=W):(be=e[26],W=e[27]),l.useEffect(be,W);let te;e[28]!==C?(te=ct=>{O(!0),R.current=ct.clientX,V.current=C,ct.preventDefault()},e[28]=C,e[29]=te):te=e[29];const ae=te;let me;e[30]!==C?(me=ct=>{const at=ct.shiftKey?al*4:al;let Rt;e:switch(ct.key){case"ArrowLeft":{Rt=C-at;break e}case"ArrowRight":{Rt=C+at;break e}case"Home":{Rt=Wr;break e}case"End":{Rt=qr;break e}default:return}ct.preventDefault(),M(vr(Rt)),j(!0)},e[30]=C,e[31]=me):me=e[31];const Me=me;let Ne;e[32]!==m||e[33]!==r||e[34]!==_.isVSCode||e[35]!==h?(Ne=()=>{if(!(!m&&!_.isVSCode&&!r)){if(h==="agents"){$a.getState().loadAgents();return}if(h==="commands"){Ba.getState().loadCommands();return}if(h==="mcp"){Ln.getState().loadMcpConfigs();return}if(h==="plugins"){ds.getState().loadPlugins();return}(h==="skills.installed"||h==="skills.catalog")&&(Hs.getState().loadSkills(),Vs.getState().loadCatalog()),h==="snippets"&&_a.getState().loadSnippets()}},e[32]=m,e[33]=r,e[34]=_.isVSCode,e[35]=h,e[36]=Ne):Ne=e[36];let De;e[37]!==ye||e[38]!==m||e[39]!==r||e[40]!==_.isVSCode||e[41]!==h?(De=[ye,m,r,_.isVSCode,h],e[37]=ye,e[38]=m,e[39]=r,e[40]=_.isVSCode,e[41]=h,e[42]=De):De=e[42],l.useEffect(Ne,De);let Ae;e[43]!==u||e[44]!==I?(Ae=ct=>{if(I(ct),S.current=ct,!u)return;const at=En(ct);if(!at||at.slug==="home"){E("nav");return}E(at.kind==="split"?"page-sidebar":"page-content")},e[43]=u,e[44]=I,e[45]=Ae):Ae=e[45];const Pe=Ae;let Re;e[46]!==h?(Re=En(h),e[46]=h,e[47]=Re):Re=e[47];const Fe=Re;let Ue;e[48]===Symbol.for("react.memo_cache_sentinel")?(Ue={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[48]=Ue):Ue=e[48];const _e=Ue;let Ke;e[49]!==c?(Ke=ct=>{switch(ct){case"projects":return c("settings.page.projects.title");case"remote-instances":return c("settings.page.remoteInstances.title");case"providers":return c("settings.page.providers.title");case"usage":return c("settings.page.usage.title");case"agents":return c("settings.page.agents.title");case"behavior":return c("settings.page.behavior.title");case"commands":return c("settings.page.commands.title");case"mcp":return c("settings.page.mcp.title");case"plugins":return c("settings.page.plugins.title");case"skills.installed":return c("settings.page.skills.title");case"skills.catalog":return c("settings.page.skillsCatalog.title");case"git":return c("settings.page.git.title");case"appearance":return c("settings.page.appearance.title");case"chat":return c("settings.page.chat.title");case"shortcuts":return c("settings.page.shortcuts.title");case"sessions":return c("settings.page.sessions.title");case"magic-prompts":return c("settings.page.magicPrompts.title");case"snippets":return c("settings.page.snippets.title");case"notifications":return c("settings.page.notifications.title");case"voice":return c("settings.page.voice.title");case"tunnel":return c("settings.page.tunnel.title");case"about":return c("settings.page.about.title");default:return c("settings.view.home.title")}},e[49]=c,e[50]=Ke):Ke=e[50];const qe=Ke;let ce;e[51]!==qe||e[52]!==_||e[53]!==k||e[54]!==c||e[55]!==i?(ce=Bb({query:k,runtimeCtx:{..._,isDesktopLocalOrigin:X,isMac:ne},visiblePageSlugs:i,t:c,getPageTitle:qe}),e[51]=qe,e[52]=_,e[53]=k,e[54]=c,e[55]=i,e[56]=ce):ce=e[56];const G=ce,pe=iy;let je;if(e[57]!==G){je=[];const ct=new Map;for(const at of G){let Rt=ct.get(at.page);Rt||(Rt={page:at.page,pageTitle:at.pageTitle,results:[]},ct.set(at.page,Rt),je.push(Rt)),Rt.results.push(at)}e[57]=G,e[58]=je}else je=e[58];const Ee=je;let Se;e[59]===Symbol.for("react.memo_cache_sentinel")?(Se=()=>{T(0),w.current=0,H.current=!1},e[59]=Se):Se=e[59];let Ve;e[60]!==k?(Ve=[k],e[60]=k,e[61]=Ve):Ve=e[61],l.useEffect(Se,Ve);let Z,y;e[62]!==U?(Z=()=>{w.current=U},y=[U],e[62]=U,e[63]=Z,e[64]=y):(Z=e[63],y=e[64]),l.useEffect(Z,y);let ue,Ie;e[65]!==U?(ue=()=>{Y.current[U]?.scrollIntoView({block:"nearest"})},Ie=[U],e[65]=U,e[66]=ue,e[67]=Ie):(ue=e[66],Ie=e[67]),l.useEffect(ue,Ie);let Oe,We;e[68]!==U||e[69]!==G.length?(Oe=()=>{U>=G.length&&T(Math.max(0,G.length-1)),Y.current.length=G.length},We=[U,G.length],e[68]=U,e[69]=G.length,e[70]=Oe,e[71]=We):(Oe=e[70],We=e[71]),l.useEffect(Oe,We);let rt;e[72]!==u||e[73]!==Pe?(rt=ct=>{const at=pe(ct);D(at),Pe(ct.page),u&&E("page-content"),ct.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(oy,50)},e[72]=u,e[73]=Pe,e[74]=rt):rt=e[74];const it=rt;let nt;e[75]!==it||e[76]!==k||e[77]!==G?(nt=ct=>{if(k.trim()){if(ct.key==="Escape"){ct.preventDefault(),v("");return}if(G.length!==0){if(ct.key==="ArrowDown"){ct.preventDefault(),H.current=!0,T(at=>(at+1)%G.length);return}if(ct.key==="ArrowUp"){ct.preventDefault(),H.current=!0,T(at=>(at-1+G.length)%G.length);return}if(ct.key==="Enter"){ct.preventDefault();const at=(w.current%G.length+G.length)%G.length,Rt=G[at]??G[0];Rt&&it(Rt)}}}},e[75]=it,e[76]=k,e[77]=G,e[78]=nt):nt=e[78];const dt=nt;let Ye;e[79]!==b?(Ye=()=>{const ct=b;if(!ct)return;let at=!1;const Rt=window.requestAnimationFrame(()=>{if(at)return;const Yt=typeof CSS<"u"&&CSS.escape?CSS.escape(ct):ct.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Gt=B.current?.querySelector(`[data-settings-item="${Yt}"]`);Gt&&(D(null),Gt.scrollIntoView({block:"center",behavior:"smooth"}),Gt.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Gt.removeAttribute("data-settings-search-highlight")},1600))});return()=>{at=!0,window.cancelAnimationFrame(Rt)}},e[79]=b,e[80]=Ye):Ye=e[80];let $e;e[81]!==b||e[82]!==h?($e=[b,h],e[81]=b,e[82]=h,e[83]=$e):$e=e[83],l.useEffect(Ye,$e);let mt;e[84]!==c?(mt=()=>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[84]=c,e[85]=mt):mt=e[85];const he=mt,et=ly;let Xe;e[86]!==Pe||e[87]!==he||e[88]!==_?(Xe=ct=>{const at=En(ct);if(at&&!rl(at,_))return he();switch(ct){case"home":return t.jsx(wr,{onOpen:Pe});case"projects":return t.jsx(rf,{});case"remote-instances":return t.jsx(Af,{});case"agents":return t.jsx(up,{});case"behavior":return t.jsx(xp,{});case"commands":return t.jsx(Cp,{});case"mcp":return t.jsx(sg,{});case"plugins":return t.jsx(Bg,{});case"skills.installed":return t.jsx(Do,{view:"installed"});case"skills.catalog":return t.jsx(Do,{view:"catalog"});case"providers":return t.jsx(Kf,{});case"usage":return t.jsx(yx,{});case"about":return t.jsx("div",{className:"h-full overflow-auto px-5 py-6",children:t.jsx(Kl,{})});case"magic-prompts":return t.jsx(kx,{});case"snippets":return t.jsx(Dx,{});case"git":return t.jsx(Tx,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const Rt=_e[ct]??"visual";return t.jsx(Db,{section:Rt})}default:return t.jsx(wr,{onOpen:Pe})}},e[86]=Pe,e[87]=he,e[88]=_,e[89]=Xe):Xe=e[89];const He=Xe;let bt,wt;e[90]!==u||e[91]!==x||e[92]!==h?(bt=()=>{if(!u||x!=="nav"||h==="home"||S.current===h)return;const ct=En(h);!ct||ct.slug==="home"||(S.current=h,E(ct.kind==="split"?"page-sidebar":"page-content"))},wt=[u,x,h],e[90]=u,e[91]=x,e[92]=h,e[93]=bt,e[94]=wt):(bt=e[93],wt=e[94]),l.useEffect(bt,wt);const Pt=u&&x!=="nav",ie=u&&x==="page-content"&&h==="skills.installed",Be=x==="page-content"&&Fe?.kind==="split"&&!ie;let Je;e[95]!==ie||e[96]!==Pt||e[97]!==c?(Je=c(ie?"settings.view.actions.back":Pt?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[95]=ie,e[96]=Pt,e[97]=c,e[98]=Je):Je=e[98];const Ge=Je,ut=Mm();let yt;e[99]!==_.isVSCode?(yt=ct=>{if(typeof window>"u"||_.isVSCode)return;const at=jr(window.history.state);at?.page===ct&&at.stage==="page-content"||window.history.pushState({...qb(),[gc]:{page:ct,stage:"page-content"}},"",window.location.href)},e[99]=_.isVSCode,e[100]=yt):yt=e[100];const gt=yt;let Et;e[101]!==gt||e[102]!==h?(Et=()=>{E("page-content"),h==="skills.installed"&>(h)},e[101]=gt,e[102]=h,e[103]=Et):Et=e[103];const Qt=Et;let es;e[104]!==ie||e[105]!==_.isVSCode||e[106]!==h?(es=()=>{if(ie){if((typeof window<"u"?jr(window.history.state):null)?.page===h&&!_.isVSCode){window.history.back();return}E("page-sidebar");return}E("nav")},e[104]=ie,e[105]=_.isVSCode,e[106]=h,e[107]=es):es=e[107];const ts=es;let ss,_t;e[108]!==u||e[109]!==_.isVSCode||e[110]!==h?(ss=()=>{if(!u||_.isVSCode)return;const ct=at=>{if(h!=="skills.installed")return;if(jr(at.state)?.page==="skills.installed"){E("page-content");return}E(cy)};return window.addEventListener("popstate",ct),()=>{window.removeEventListener("popstate",ct)}},_t=[u,_.isVSCode,h],e[108]=u,e[109]=_.isVSCode,e[110]=h,e[111]=ss,e[112]=_t):(ss=e[111],_t=e[112]),l.useEffect(ss,_t);let ns;e[113]===Symbol.for("react.memo_cache_sentinel")?(ns=()=>{E("page-sidebar")},e[113]=ns):ns=e[113];const ke=ns,vt=()=>{const ct=k.trim().length>0;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[t.jsx("div",{className:"px-2 pt-3",children:t.jsxs("div",{className:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[t.jsx(A,{name:"search",className:"h-4 w-4 shrink-0"}),t.jsx("input",{value:k,onChange:at=>v(at.target.value),onKeyDown:dt,placeholder:c("settings.view.search.placeholder"),"aria-label":c("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),ct&&t.jsx("button",{type:"button",onClick:()=>v(""),"aria-label":c("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:t.jsx("div",{className:"flex flex-col gap-0.5 pt-4 pb-2 px-2",children:ct?G.length>0?(()=>{let at=0;return Ee.map(Rt=>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:Rt.pageTitle}),Rt.results.map(Yt=>{const Gt=at;at=at+1;const Qe=Gt===U,Ss=!!Yt.description;return t.jsxs("button",{type:"button",ref:Gs=>{Y.current[Gt]=Gs},onMouseMove:()=>{H.current=!1,T(Gt)},onClick:()=>it(Yt),className:le("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ss?"min-h-11 py-1.5":"py-2",Qe?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Yt.title}),Ss&&t.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:Yt.description})]},Yt.id)})]},Rt.page))})():t.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:c("settings.view.search.noResults")}):we.map(at=>{const Rt=h===at.slug,Yt=hc(at.slug);return!Yt&&at.slug!=="mcp"?null:t.jsx(It,{children:t.jsx(Dt,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:()=>Pe(at.slug),"aria-current":Rt?"page":void 0,className:le("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",Rt?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[at.slug==="mcp"?t.jsx(yu,{className:"h-4 w-4 shrink-0"}):t.jsx(A,{name:Yt,className:"h-4 w-4 shrink-0"}),t.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[t.jsx("span",{className:"typography-ui-label font-normal truncate",children:qe(at.slug)}),at.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")})]})]})})},at.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:!_.isVSCode&&t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsxs("button",{type:"button",className:le("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:my,children:[t.jsx(A,{name:"restart",className:"h-4 w-4 shrink-0"}),t.jsx("span",{children:c("settings.view.actions.reloadOpenCode")})]})}),t.jsx(At,{children:c("settings.view.actions.reloadOpenCodeTooltip")})]})})})]})},Nt=()=>{if(x==="nav")return t.jsx("div",{className:le("flex-1 min-h-0 overflow-hidden",_.isVSCode?"bg-background":"bg-sidebar"),children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:t.jsx(Xs,{children:vt()})})});if(!Fe)return t.jsx("div",{className:"flex-1 bg-background"});if(x==="page-sidebar"){if(Fe.kind!=="split"){const at=He(h);return t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(Xs,{children:at})})}return t.jsx("div",{className:le("flex-1 min-h-0 overflow-hidden",_.isVSCode?"bg-background":"bg-sidebar"),children:t.jsx(Xs,{children:et(h,{onItemSelect:Qt})})})}const ct=He(h);return t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(Xs,{children:ct})})};let Ze;e[114]!==Fe||e[115]!==Pe||e[116]!==He||e[117]!==_.isVSCode||e[118]!==h?(Ze=()=>!Fe||h==="home"?t.jsx(wr,{onOpen:Pe}):Fe.kind==="split"?t.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[t.jsx("div",{className:le("w-[264px] min-w-[264px] border-r",_.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:t.jsx(Xs,{children:et(h,{})})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(Xs,{children:He(h)})})]}):t.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:t.jsx(Xs,{children:He(h)})}),e[114]=Fe,e[115]=Pe,e[116]=He,e[117]=_.isVSCode,e[118]=h,e[119]=Ze):Ze=e[119];const kt=Ze,Wt="true";let Jt;e[120]===Symbol.for("react.memo_cache_sentinel")?(Jt=le("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[120]=Jt):Jt=e[120];const as=u?t.jsxs("div",{className:le("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:[Pt||n?t.jsx("button",{type:"button",onClick:Pt?ts:n,"aria-label":Ge,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(A,{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"):Fe?qe(Fe.slug):c("settings.view.home.title")}),Be&&t.jsx("button",{type:"button",onClick:ke,"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(A,{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:ut}),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(A,{name:"close",className:"h-5 w-5"})})]}):t.jsxs(t.Fragment,{children:[Pt&&t.jsx("div",{className:le("absolute left-3 z-50",r?"top-2":"top-3"),children:t.jsx("button",{type:"button",onClick:ts,"aria-label":c("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:t.jsx(A,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&t.jsx("div",{className:le("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:ut}),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(A,{name:"close",className:"h-5 w-5"})})})]}),zs="flex flex-1 min-h-0 overflow-hidden",xs=u?Nt():t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:le("relative flex h-full min-h-0 flex-col overflow-hidden border-r",z?"bg-sidebar":_.isVSCode?"bg-background":"bg-sidebar",P?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${C}px`,minWidth:`${C}px`,borderColor:"var(--interactive-border)"},children:[t.jsx("div",{className:le("absolute right-0 top-0 z-20 h-full w-[6px] -mr-[3px] cursor-col-resize","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",P?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:ae,onKeyDown:Me,role:"separator","aria-orientation":"vertical","aria-valuemin":Wr,"aria-valuemax":qr,"aria-valuenow":C,"aria-label":c("settings.view.actions.resizeNavigation")}),t.jsx(Xs,{children:vt()})]}),t.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:kt()})]});let Rs;e[121]!==xs?(Rs=t.jsx("div",{className:zs,children:xs}),e[121]=xs,e[122]=Rs):Rs=e[122];let As;return e[123]!==Jt||e[124]!==as||e[125]!==Rs?(As=t.jsxs("div",{ref:B,"data-settings-view":Wt,className:Jt,children:[as,Rs]}),e[123]=Jt,e[124]=as,e[125]=Rs,e[126]=As):As=e[126],As};function Jb(s){return s.settingsPage}function Qb(s){return s.isSettingsDialogOpen}function Yb(s){return s.setSettingsPage}function Xb(s){return s.slug!=="home"}function Zb(s,e){return[s,e]}function ey(s){return s.activeProjectId}function ty(s){return s.name}function sy(s){return s.name}function ny(s){return s.name}function ay(s){return s.name}function ry(s){return s.name}function iy(s){if(s.id.startsWith("agents.")){const e=$a.getState(),n=Yn("new-agent",e.agents.map(ty));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=Ba.getState(),n=Yn("new-command",e.commands.map(sy));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=Ln.getState(),n=Yn("new-mcp-server",e.mcpServers.map(ny));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=_a.getState(),n=Yn("new-snippet",e.snippets.map(ay));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=Hs.getState(),n=Yn("new-skill",e.skills.map(ry));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(Hb),s.id==="plugins.create"?"plugins.spec":s.id}function oy(){window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))}function ly(s,e){switch(s){case"projects":return t.jsx(Hh,{onItemSelect:e.onItemSelect});case"agents":return t.jsx(rp,{onItemSelect:e.onItemSelect});case"commands":return t.jsx(bp,{onItemSelect:e.onItemSelect});case"mcp":return t.jsx(Pp,{onItemSelect:e.onItemSelect});case"plugins":return t.jsx(Ag,{onItemSelect:e.onItemSelect});case"skills.installed":return t.jsx(_g,{onItemSelect:e.onItemSelect});case"providers":return t.jsx(Rf,{onItemSelect:e.onItemSelect});case"usage":return t.jsx(Yf,{onItemSelect:e.onItemSelect});case"magic-prompts":return t.jsx(jx,{onItemSelect:e.onItemSelect});case"snippets":return t.jsx(Sx,{onItemSelect:e.onItemSelect});default:return null}}function cy(s){return s==="page-content"?"page-sidebar":s}function dy(){}function my(){Mn({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]}).catch(dy)}const Qv=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:Gb,getSettingsNavIcon:hc},Symbol.toStringTag,{value:"Module"})),uy=["chat","git","diff","terminal","files","diagram"],py=["settings","agents","commands","skills","providers","usage","git-identities"],Ds={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function il(s){const e=gy();return{sessionId:hy(e),tab:fy(e),settingsPath:xy(e),diffFile:by(e)}}function gy(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function hy(s){const e=s.get(Ds.SESSION);return!e||e.trim().length===0?null:e.trim()}function fy(s){const e=s.get(Ds.TAB);if(!e)return null;const n=e.toLowerCase().trim();return uy.includes(n)?n:null}function xy(s){const e=s.get(Ds.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(py.includes(n),n)}function by(s){const e=s.get(Ds.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function ol(){if(typeof window>"u")return!1;try{const s=new URLSearchParams(window.location.search);return s.has(Ds.SESSION)||s.has(Ds.TAB)||s.has(Ds.SETTINGS)||s.has(Ds.FILE)}catch{return!1}}const yy="chat";function fc(s){const e=new URLSearchParams;if(s.sessionId&&s.sessionId.trim().length>0&&e.set(Ds.SESSION,s.sessionId),s.isSettingsOpen){const n=s.settingsPath.trim().length>0?s.settingsPath:"home";return e.set(Ds.SETTINGS,n),e}return s.tab!==yy&&e.set(Ds.TAB,s.tab),s.tab==="diff"&&s.diffFile&&s.diffFile.trim().length>0&&e.set(Ds.FILE,s.diffFile),e}function vy(s,e){const n=typeof window<"u"?window.location.pathname:"/",a=s.toString();return a?`${n}?${a}`:n}function jy(s){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=fc(s),a=[...e.entries()].sort((i,o)=>i[0].localeCompare(o[0])),r=[...n.entries()].sort((i,o)=>i[0].localeCompare(o[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 wy(s,e={}){if(!(typeof window>"u")&&!Ny()&&!(!e.force&&jy(s)))try{const n=fc(s),a=vy(n);e.replace?window.history.replaceState({...window.history.state,route:s},"",a):window.history.pushState({route:s},"",a)}catch{}}function Ny(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function ky(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function Yv(){const s=l.useMemo(()=>ky(),[]),e=l.useRef(!1),n=l.useRef(!1),a=ks(p=>p.setCurrentSession),r=Le(p=>p.setActiveMainTab),i=Le(p=>p.setSettingsDialogOpen),o=Le(p=>p.setSettingsPage),d=Le(p=>p.navigateToDiff),c=l.useCallback(async p=>{if(!n.current){n.current=!0;try{if(p.sessionId){const m=ks.getState().currentSessionId;p.sessionId!==m&&await a(p.sessionId)}if(p.settingsPath){o(ni(p.settingsPath)),i(!0);return}Le.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,o,d]),f=l.useCallback(()=>{const p=ks.getState(),m=Le.getState();return{sessionId:p.currentSessionId,tab:m.activeMainTab,isSettingsOpen:m.isSettingsDialogOpen,settingsPath:m.settingsPage,diffFile:m.pendingDiffFile}},[]),u=l.useCallback((p={})=>{if(s||n.current)return;const m=f();wy(m,p)},[s,f]);l.useEffect(()=>{if(e.current||(e.current=!0,!ol()))return;const p=il();(async()=>(await c(p),s||u({replace:!0})))()},[c,s,u]),l.useEffect(()=>{if(s)return;let p=ks.getState().currentSessionId;return ks.subscribe(I=>{const g=I.currentSessionId;g===p||n.current||(p=g,u())})},[s,u]),l.useEffect(()=>{if(s)return;let p=Le.getState().activeMainTab,m=Le.getState().isSettingsDialogOpen,I=Le.getState().settingsPage,g=Le.getState().pendingDiffFile;return Le.subscribe(x=>{if(n.current)return;const E=x.activeMainTab!==p,S=x.isSettingsDialogOpen!==m,C=x.settingsPage!==I,M=x.pendingDiffFile!==g&&x.activeMainTab==="diff";p=x.activeMainTab,m=x.isSettingsDialogOpen,I=x.settingsPage,g=x.pendingDiffFile,(E||S||C||M)&&u()})},[s,u]),l.useEffect(()=>{if(typeof window>"u"||s)return;const p=()=>{const m=il();if(ol())c(m);else{const I=Le.getState();I.isSettingsDialogOpen&&i(!1),I.activeMainTab!=="chat"&&r("chat")}};return window.addEventListener("popstate",p),()=>{window.removeEventListener("popstate",p)}},[c,s,r,i])}function Xv(){const s=st.c(5),e=zl(Cy),n=l.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]),l.useEffect(a,r);let i,o;s[3]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{let d=!1,c=null;const f=Sy,u=p=>{d||(c=window.setTimeout(async()=>{const m=await n.current(),I=typeof m=="number"&&Number.isFinite(m)?f(m):36e5;u(I)},p))};return u(3e3),()=>{d=!0,c!==null&&window.clearTimeout(c)}},o=[],s[3]=i,s[4]=o):(i=s[3],o=s[4]),l.useEffect(i,o)}function Sy(s){const e=Math.round(s*1e3);return Math.max(3e5,Math.min(864e5,e))}function Cy(s){return s.checkForUpdates}const xc={"?":{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"}},Py=xc.M;function Iy(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 Dy(s){const e=Iy(s);return xc[e]??Py}const Ay=l.memo(function(e){const n=st.c(58),{file:a,actionLabel:r,actionSymbol:i,onAction:o,onViewDiff:d,onRevert:c,isReverting:f,stats:u,rowPaddingClassName:p,indentPx:m,actionAtStart:I,showRevert:g}=e,h=m===void 0?0:m,x=I===void 0?!1:I,E=g===void 0?!0:g;let S;n[0]!==a?(S=Dy(a),n[0]=a,n[1]=S):S=n[1];const C=S,{t:M}=ot(),k=C.description,v=u?.insertions??0,b=u?.deletions??0;let D;n[2]!==o||n[3]!==d?(D=xe=>{xe.key===" "?(xe.preventDefault(),o()):xe.key==="Enter"&&(xe.preventDefault(),d())},n[2]=o,n[3]=d,n[4]=D):D=n[4];const U=D;let T;n[5]!==o?(T=xe=>{xe.preventDefault(),xe.stopPropagation(),o()},n[5]=o,n[6]=T):T=n[6];const F=T;let j;n[7]!==c?(j=xe=>{xe.preventDefault(),xe.stopPropagation(),c()},n[7]=c,n[8]=j):j=n[8];const P=j;let O;n[9]!==r||n[10]!==i||n[11]!==F?(O=t.jsx("button",{type:"button",onClick:F,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]=F,n[12]=O):O=n[12];const R=O,V=`group flex items-center gap-2 py-1.5 cursor-pointer ${p??"px-3"}`;let B;n[13]!==h?(B=h>0?{paddingLeft:`${h}px`}:void 0,n[13]=h,n[14]=B):B=n[14];const ee=x?R:null;let Y;n[15]!==C.color?(Y={color:C.color},n[15]=C.color,n[16]=Y):Y=n[16];let w;n[17]!==C.code||n[18]!==k||n[19]!==Y?(w=t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:Y,title:k,"aria-label":k,children:C.code}),n[17]=C.code,n[18]=k,n[19]=Y,n[20]=w):w=n[20];let H;n[21]!==a.path?(H=t.jsx(Rm,{filePath:a.path,className:"h-3.5 w-3.5 shrink-0"}),n[21]=a.path,n[22]=H):H=n[22];let Q;if(n[23]!==a.path){e:{const xe=a.path.lastIndexOf("/");if(xe===-1){let be;n[25]===Symbol.for("react.memo_cache_sentinel")?(be={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[25]=be):be=n[25],Q=t.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:be,title:a.path,children:a.path});break e}const Ce=a.path.slice(0,xe),ve=a.path.slice(xe);let we;n[26]===Symbol.for("react.memo_cache_sentinel")?(we={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[26]=we):we=n[26];let ye;n[27]===Symbol.for("react.memo_cache_sentinel")?(ye=t.jsx("span",{className:"text-muted-foreground",children:"/"}),n[27]=ye):ye=n[27];const se=t.jsx("span",{className:"text-foreground",children:ve.slice(1)});let de;n[28]!==se?(de=t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[ye,se]}),n[28]=se,n[29]=de):de=n[29],Q=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:Ce}),de]})}n[23]=a.path,n[24]=Q}else Q=n[24];let z;n[30]===Symbol.for("react.memo_cache_sentinel")?(z={color:"var(--status-success)"},n[30]=z):z=n[30];let L;n[31]!==v?(L=t.jsxs("span",{style:z,children:["+",v]}),n[31]=v,n[32]=L):L=n[32];let X,$;n[33]===Symbol.for("react.memo_cache_sentinel")?(X=t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),$={color:"var(--status-error)"},n[33]=X,n[34]=$):(X=n[33],$=n[34]);let ne;n[35]!==b?(ne=t.jsxs("span",{style:$,children:["-",b]}),n[35]=b,n[36]=ne):ne=n[36];let re;n[37]!==L||n[38]!==ne?(re=t.jsxs("span",{className:"shrink-0 typography-micro",children:[L,X,ne]}),n[37]=L,n[38]=ne,n[39]=re):re=n[39];let _;n[40]!==a.path||n[41]!==P||n[42]!==f||n[43]!==E||n[44]!==M?(_=E?t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx("button",{type:"button",onClick:P,disabled:f,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":M("gitView.changes.revertFileAria",{path:a.path}),children:f?t.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(A,{name:"arrow-go-back",className:"size-3.5"})})}),t.jsx(At,{sideOffset:8,children:M("gitView.changes.revertFileTooltip")})]}):null,n[40]=a.path,n[41]=P,n[42]=f,n[43]=E,n[44]=M,n[45]=_):_=n[45];const oe=x?null:R;let fe;return n[46]!==U||n[47]!==d||n[48]!==B||n[49]!==ee||n[50]!==w||n[51]!==H||n[52]!==Q||n[53]!==re||n[54]!==_||n[55]!==oe||n[56]!==V?(fe=t.jsxs("div",{className:V,role:"button",tabIndex:0,onClick:d,onKeyDown:U,style:B,children:[ee,w,H,Q,re,_,oe]}),n[46]=U,n[47]=d,n[48]=B,n[49]=ee,n[50]=w,n[51]=H,n[52]=Q,n[53]=re,n[54]=_,n[55]=oe,n[56]=V,n[57]=fe):fe=n[57],fe}),ll=14,bc=s=>s.replace(/\\/g,"/").replace(/^\/+/,"").trim(),cl=(s,e)=>({id:`dir:${s}`,path:s,name:e,children:new Map,directFiles:[],files:[]}),Ey=s=>{const e=cl("","");for(const n of s){const a=bc(n.path);if(!a)continue;const i=a.split("/").filter(Boolean).slice(0,-1);let o=e;if(o.files.push(n),i.length>0){let d="";for(const c of i){d=d?`${d}/${c}`:c;const f=o.children.get(c);if(f){f.files.push(n),o=f;continue}const u=cl(d,c);u.files.push(n),o.children.set(c,u),o=u}}o.directFiles.push(n)}return e},My=(s,e)=>{const n=[],a=(r,i)=>{const o=Array.from(r.children.values()).sort((c,f)=>c.path.localeCompare(f.path));for(const c of o)n.push({key:c.id,kind:"directory",depth:i,directory:c}),e.has(c.path)&&a(c,i+1);const d=[...r.directFiles].sort((c,f)=>c.path.localeCompare(f.path));for(const c of d)n.push({key:`file:${bc(c.path)}`,kind:"file",depth:i,file:c})};return a(s,0),n},Ry=1e3,dl=34,Nr=30,va="pl-0 pr-2",kr=(s,e)=>`${s} ${e}`,Zv=({groups:s,diffStats:e,revertingPaths:n,isRevertingAll:a=!1,headerBackgroundClassName:r="bg-sidebar",onVisiblePathsChange:i,onRevertAll:o,onRevertDirectory:d})=>{const{t:c}=ot(),f=l.useRef(null),p=Le(L=>L.gitChangesViewMode)==="tree",m=l.useMemo(()=>s.filter(L=>L.entries.length>0),[s]),[I,g]=l.useState(new Set),[h,x]=l.useState(new Set),[E,S]=l.useState(!1),[C,M]=l.useState(null),k=l.useMemo(()=>m.map(L=>Ey(L.entries)),[m]),v=l.useMemo(()=>{const L=[];return m.forEach((X,$)=>{Array.from(k[$]?.children.values()??[]).forEach(ne=>{L.push(kr(X.id,ne.path))})}),L},[k,m]);l.useEffect(()=>{p&&x(L=>{const X=new Set,$=new Set(v);return L.forEach(ne=>{(ne.slice(ne.indexOf(" ")+1).includes("/")||$.has(ne))&&X.add(ne)}),v.forEach(ne=>X.add(ne)),X})},[p,v]);const b=l.useMemo(()=>{const L=[];return m.forEach((X,$)=>{if(L.push({type:"header",key:`header:${X.id}`,groupIndex:$}),!I.has(X.id)){if(p){const ne=new Set;h.forEach(_=>{_.startsWith(`${X.id} `)&&ne.add(_.slice(X.id.length+1))}),My(k[$],ne).forEach(_=>{_.kind==="file"?L.push({type:"file",key:`${X.id}:${_.key}`,groupIndex:$,file:_.file,depth:_.depth}):L.push({type:"directory",key:`${X.id}:${_.key}`,groupIndex:$,directory:_.directory,depth:_.depth})});return}X.entries.forEach(ne=>{L.push({type:"file",key:`${X.id}:file:${ne.path}`,groupIndex:$,file:ne,depth:0})})}}),o&&m.length>0&&L.push({type:"revert-all",key:"revert-all"}),L},[I,h,p,o,k,m]),D=b.length,U=D>=Ry,T=pd({count:D,enabled:U,getScrollElement:()=>f.current,estimateSize:()=>dl,overscan:12,getItemKey:L=>b[L]?.key??L}),F=T.getVirtualItems(),j=l.useMemo(()=>{if(!U)return 0;const L=f.current?.scrollTop??0;return F.find($=>$.end>L)?.index??0},[U,F,f]);l.useEffect(()=>{if(!i)return;const L=X=>X&&X.type==="file"?X.file.path:null;if(D===0){i([]);return}if(!U){const X=[];for(const $ of b)if($.type==="file"&&(X.push($.file.path),X.length>=Nr))break;i(X);return}i(b.slice(j,j+Math.ceil((f.current?.clientHeight??0)/dl)+Nr).map(X=>L(X)).filter(X=>!!X).slice(0,Nr))},[i,D,b,U,j]);const P=l.useCallback(L=>{g(X=>{const $=new Set(X);return $.has(L)?$.delete(L):$.add(L),$})},[]),O=l.useCallback((L,X)=>{x($=>{const ne=new Set($),re=kr(L,X);return ne.has(re)?ne.delete(re):ne.add(re),ne})},[]),R=l.useMemo(()=>{const L=new Set;return m.forEach(X=>X.entries.forEach($=>L.add($.path))),Array.from(L)},[m]),V=R.length,B=C?a||C.paths.some(L=>n.has(L)):!1,ee=l.useCallback(async()=>{!o||a||R.length===0||(await o(R),S(!1))},[R,a,o]),Y=l.useCallback(async()=>{!d||!C||B||(await d(C.paths),M(null))},[B,d,C]),w=l.useCallback((L,X)=>{const $=I.has(L.id),ne=L.entries.length;return t.jsxs("div",{className:le("sticky top-0 z-10 flex items-center gap-2 py-2",r,va,!X&&"mt-1 border-t border-border/40"),children:[t.jsx("button",{type:"button",onClick:()=>L.onActionAll(L.entries.map(re=>re.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":L.actionAllLabel,title:L.actionAllLabel,children:L.actionSymbol}),t.jsxs("button",{type:"button",onClick:()=>P(L.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!$,children:[t.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:L.title}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:ne}),t.jsx(A,{name:"arrow-down-s",className:le("size-3.5 shrink-0 text-muted-foreground transition-transform",$&&"-rotate-90")})]})]})},[I,r,P]),H=l.useCallback((L,X,$)=>{const ne=h.has(kr(L.id,X.path)),re=X.files.map(oe=>oe.path),_=a||re.some(oe=>n.has(oe));return t.jsxs("div",{className:le("group flex items-center gap-2 py-1.5",va),style:{paddingLeft:`${$*ll}px`},children:[t.jsxs("button",{type:"button",onClick:()=>O(L.id,X.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":ne?c("gitView.changes.collapseDirectoryAria",{path:X.path}):c("gitView.changes.expandDirectoryAria",{path:X.path}),children:[ne?t.jsx(A,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):t.jsx(A,{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:X.path,children:X.name}),t.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:X.files.length})]}),L.showRevertActions!==!1&&d?t.jsx("button",{type:"button",onClick:()=>M({path:X.path,paths:re,count:re.length}),disabled:_,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:X.path}),title:c("gitView.changes.revertDirectoryTooltip"),children:_?t.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(A,{name:"arrow-go-back",className:"size-3.5"})}):null,t.jsx("button",{type:"button",onClick:()=>L.onActionAll(X.files.map(oe=>oe.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":c(L.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:X.path}),title:c(L.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:X.path}),children:L.actionSymbol})]})},[h,a,d,n,c,O]),Q=l.useCallback((L,X)=>{if(L.type==="revert-all")return t.jsx("div",{className:le("flex justify-end py-2",va),children:t.jsxs(J,{variant:"ghost",size:"sm",onClick:()=>S(!0),disabled:a,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[t.jsx(A,{name:"arrow-go-back",className:"size-3.5"}),c("gitView.changes.revertAll")]})});const $=m[L.groupIndex];if(!$)return null;if(L.type==="header")return w($,X);if(L.type==="directory")return H($,L.directory,L.depth);const ne=L.file;return t.jsx(Ay,{file:ne,actionLabel:$.getActionLabel(ne.path),actionSymbol:$.actionSymbol,onAction:()=>$.onActionFile(ne.path),stats:e?.[ne.path],onViewDiff:()=>$.onViewDiff(ne.path),onRevert:()=>$.onRevertFile(ne.path),isReverting:n.has(ne.path)||a,rowPaddingClassName:va,indentPx:L.depth*ll,actionAtStart:!p,showRevert:$.showRevertActions!==!1})},[e,a,p,H,w,n,c,m]),z=l.useCallback(L=>{const X=b[L],$=b[L-1];return!X||!$||X.type!=="file"&&X.type!=="directory"||$.type!=="file"&&$.type!=="directory"?!1:$.groupIndex===X.groupIndex},[b]);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(Tm,{ref:f,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:T.getTotalSize(),position:"relative"},children:F.map(L=>{const X=b[L.index];return X?t.jsx("div",{"data-index":L.index,ref:T.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${L.start}px)`},className:le(z(L.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:Q(X,L.index===0)},X.key):null})}):t.jsx("div",{role:"list","aria-label":c("gitView.changes.changedFilesAria"),children:b.map((L,X)=>t.jsx("div",{className:le("relative",z(X)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:Q(L,X===0)},L.key))})}),t.jsx(Fm,{containerRef:f,disableHorizontal:!0})]}),t.jsx(Kt,{open:E,onOpenChange:L=>{!a&&!L&&S(!1)},children:t.jsxs(Ut,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:c("gitView.changes.revertAllDialogTitle")}),t.jsx(Ht,{children:V===1?c("gitView.changes.revertAllDescriptionSingle",{count:V}):c("gitView.changes.revertAllDescriptionPlural",{count:V})})]}),t.jsxs(Zt,{children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>S(!1),disabled:a,children:c("gitView.common.cancel")}),t.jsx(J,{variant:"destructive",size:"sm",onClick:()=>{ee()},disabled:a,children:c(a?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})}),t.jsx(Kt,{open:!!C,onOpenChange:L=>{!B&&!L&&M(null)},children:t.jsxs(Ut,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx($t,{children:c("gitView.changes.revertDirectoryDialogTitle")}),t.jsx(Ht,{children:C?C.count===1?c("gitView.changes.revertDirectoryDescriptionSingle",{count:C.count,path:C.path}):c("gitView.changes.revertDirectoryDescriptionPlural",{count:C.count,path:C.path}):null})]}),t.jsxs(Zt,{children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>M(null),disabled:B,children:c("gitView.common.cancel")}),t.jsx(J,{variant:"destructive",size:"sm",onClick:()=>{Y()},disabled:B||!C,children:c(B?"gitView.changes.reverting":"gitView.changes.revertDirectory")})]})]})})]})},Sr=38,ja=200,Ty=s=>{const e=st.c(20),{value:n,onChange:a,placeholder:r,disabled:i,hasTouchInput:o,isMobile:d}=s,c=i===void 0?!1:i,f=o===void 0?!1:o,u=d===void 0?!1:d,{t:p}=ot(),m=l.useRef(null),I=Le(Fy);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{const U=m.current;if(!U)return;const T=document.activeElement===U,F=()=>{U.style.height=`${Sr}px`;const P=U.scrollHeight,O=Math.min(Math.max(P,Sr),ja);U.style.height=`${O}px`,U.style.overflowY=P>ja?"auto":"hidden",P>ja&&!T&&(U.scrollTop=U.scrollHeight)};F();const j=window.requestAnimationFrame(F);return()=>{window.cancelAnimationFrame(j)}},e[0]=g):g=e[0];let h;e[1]!==n?(h=[n],e[1]=n,e[2]=h):h=e[2],l.useLayoutEffect(g,h);let x;e[3]!==a?(x=U=>a(U.target.value),e[3]=a,e[4]=x):x=e[4];let E;e[5]!==r||e[6]!==p?(E=r??p("gitView.commit.messagePlaceholder"),e[5]=r,e[6]=p,e[7]=E):E=e[7];const S=f?"on":"off",C=f?"sentences":"off",M=u||I,k=c&&"opacity-50";let v;e[8]!==k?(v=le("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",k),e[8]=k,e[9]=v):v=e[9];let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b={minHeight:Sr,maxHeight:ja},e[10]=b):b=e[10];let D;return e[11]!==c||e[12]!==M||e[13]!==v||e[14]!==x||e[15]!==E||e[16]!==S||e[17]!==C||e[18]!==n?(D=t.jsx("textarea",{ref:m,value:n,onChange:x,placeholder:E,rows:1,disabled:c,autoCorrect:S,autoCapitalize:C,spellCheck:M,className:v,style:b}),e[11]=c,e[12]=M,e[13]=v,e[14]=x,e[15]=E,e[16]=S,e[17]=C,e[18]=n,e[19]=D):D=e[19],D};function Fy(s){return s.inputSpellcheckEnabled}const Ly=s=>{const e=st.c(30),{highlights:n,onInsert:a}=s,{t:r}=ot();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 o=i;let d;e[3]!==r?(d=r("gitView.commit.aiHighlights.title"),e[3]=r,e[4]=d):d=e[4];let c;e[5]!==d?(c=t.jsx("p",{className:"typography-micro text-muted-foreground",children:d}),e[5]=d,e[6]=c):c=e[6];let f;e[7]!==r?(f=r("gitView.commit.aiHighlights.insertAria"),e[7]=r,e[8]=f):f=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(A,{name:"arrow-down",className:"size-4"}),e[9]=u):u=e[9];let p;e[10]!==o||e[11]!==f?(p=t.jsx(Dt,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"icon",className:"size-6",onClick:o,"aria-label":f,children:u})}),e[10]=o,e[11]=f,e[12]=p):p=e[12];let m;e[13]!==r?(m=r("gitView.commit.aiHighlights.insertTooltip"),e[13]=r,e[14]=m):m=e[14];let I;e[15]!==m?(I=t.jsx(At,{sideOffset:8,children:m}),e[15]=m,e[16]=I):I=e[16];let g;e[17]!==p||e[18]!==I?(g=t.jsxs(It,{children:[p,I]}),e[17]=p,e[18]=I,e[19]=g):g=e[19];let h;e[20]!==c||e[21]!==g?(h=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c,g]}),e[20]=c,e[21]=g,e[22]=h):h=e[22];let x;e[23]!==n?(x=n.map(Oy),e[23]=n,e[24]=x):x=e[24];let E;e[25]!==x?(E=t.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=E):E=e[26];let S;return e[27]!==h||e[28]!==E?(S=t.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[h,E]}),e[27]=h,e[28]=E,e[29]=S):S=e[29],S};function Oy(s,e){return t.jsx("li",{className:"typography-meta text-foreground",children:s},`${s}-${e}`)}const ej=s=>{const e=st.c(75),{stagedCount:n,commitMessage:a,onCommitMessageChange:r,generatedHighlights:i,onInsertHighlights:o,onGenerateMessage:d,isGeneratingMessage:c,onCommit:f,onCommitAndPush:u,commitAction:p,hasPendingIndexMutation:m,gitmojiEnabled:I,onOpenGitmojiPicker:g}=s,h=m===void 0?!1:m,{t:x}=ot(),E=n>0;let S;e[0]!==p||e[1]!==a||e[2]!==h||e[3]!==E?(S=a.trim()&&E&&p===null&&!h,e[0]=p,e[1]=a,e[2]=h,e[3]=E,e[4]=S):S=e[4];const C=S,{isMobile:M,hasTouchInput:k}=Is();let v;e[5]!==x?(v=x("gitView.commit.title"),e[5]=x,e[6]=v):v=e[6];let b;e[7]!==v?(b=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:v}),e[7]=v,e[8]=b):b=e[8];let D;e[9]!==E||e[10]!==x?(D=E?null:t.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:x("gitView.commit.stageFilesHint")}),e[9]=E,e[10]=x,e[11]=D):D=e[11];let U;e[12]!==b||e[13]!==D?(U=t.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[b,D]}),e[12]=b,e[13]=D,e[14]=U):U=e[14];let T;e[15]!==i||e[16]!==o?(T=t.jsx(Ly,{highlights:i,onInsert:o}),e[15]=i,e[16]=o,e[17]=T):T=e[17];let F;e[18]!==x?(F=x("gitView.commit.messagePlaceholder"),e[18]=x,e[19]=F):F=e[19];const j=p!==null;let P;e[20]!==a||e[21]!==k||e[22]!==M||e[23]!==r||e[24]!==F||e[25]!==j?(P=t.jsx(Ty,{value:a,onChange:r,placeholder:F,disabled:j,hasTouchInput:k,isMobile:M}),e[20]=a,e[21]=k,e[22]=M,e[23]=r,e[24]=F,e[25]=j,e[26]=P):P=e[26];let O;e[27]!==I||e[28]!==g||e[29]!==x?(O=I&&t.jsxs(J,{variant:"outline",size:"sm",onClick:g,className:"w-fit",type:"button",children:[t.jsx(A,{name:"emotion-happy",className:"size-4"}),x("gitView.commit.addGitmoji")]}),e[27]=I,e[28]=g,e[29]=x,e[30]=O):O=e[30];const R=c||p!==null||h||n===0;let V;e[31]!==x?(V=x("gitView.commit.generateAria"),e[31]=x,e[32]=V):V=e[32];let B;e[33]!==c?(B=c?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"ai-generate-2",className:"size-4 text-primary"}),e[33]=c,e[34]=B):B=e[34];let ee;e[35]!==x?(ee=x("gitView.commit.generate"),e[35]=x,e[36]=ee):ee=e[36];let Y;e[37]!==ee?(Y=t.jsx("span",{className:"commit-actions__label",children:ee}),e[37]=ee,e[38]=Y):Y=e[38];let w;e[39]!==d||e[40]!==R||e[41]!==V||e[42]!==B||e[43]!==Y?(w=t.jsxs(J,{variant:"outline",size:"sm",onClick:d,disabled:R,type:"button","aria-label":V,className:"commit-actions__btn",children:[B,Y]}),e[39]=d,e[40]=R,e[41]=V,e[42]=B,e[43]=Y,e[44]=w):w=e[44];let H;e[45]===Symbol.for("react.memo_cache_sentinel")?(H=t.jsx("div",{className:"flex-1"}),e[45]=H):H=e[45];const Q=!C||c;let z;e[46]!==x?(z=x("gitView.commit.commitAria"),e[46]=x,e[47]=z):z=e[47];let L;e[48]!==p||e[49]!==x?(L=p==="commit"?t.jsxs(t.Fragment,{children:[t.jsx(A,{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(A,{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]=L):L=e[50];let X;e[51]!==f||e[52]!==Q||e[53]!==z||e[54]!==L?(X=t.jsx(J,{size:"sm",variant:"outline",onClick:f,disabled:Q,className:"commit-actions__btn whitespace-nowrap","aria-label":z,children:L}),e[51]=f,e[52]=Q,e[53]=z,e[54]=L,e[55]=X):X=e[55];let $;e[56]!==C||e[57]!==p||e[58]!==c||e[59]!==M||e[60]!==u||e[61]!==x?($=M?t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(J,{variant:"default",size:"sm",onClick:()=>u(),disabled:!C||c,className:"h-7 w-7 p-0","aria-label":x("gitView.commit.pushAria"),children:p==="commitAndPush"?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"arrow-up",className:"size-3.5"})})}),t.jsx(At,{side:"top",children:t.jsx("p",{children:x("gitView.commit.push")})})]}):t.jsx(J,{size:"sm",variant:"default",onClick:()=>u(),disabled:!C||c,className:"commit-actions__btn","aria-label":x("gitView.commit.pushAria"),children:p==="commitAndPush"?t.jsxs(t.Fragment,{children:[t.jsx(A,{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(A,{name:"arrow-up",className:"size-3.5"}),t.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:x("gitView.commit.push")})]})}),e[56]=C,e[57]=p,e[58]=c,e[59]=M,e[60]=u,e[61]=x,e[62]=$):$=e[62];let ne;e[63]!==w||e[64]!==X||e[65]!==$?(ne=t.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[w,H,X,$]}),e[63]=w,e[64]=X,e[65]=$,e[66]=ne):ne=e[66];let re;e[67]!==P||e[68]!==O||e[69]!==ne||e[70]!==T?(re=t.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[T,P,O,ne]}),e[67]=P,e[68]=O,e[69]=ne,e[70]=T,e[71]=re):re=e[71];let _;return e[72]!==re||e[73]!==U?(_=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[U,re]}),e[72]=re,e[73]=U,e[74]=_):_=e[74],_},zy=s=>{const e=st.c(41),{syncAction:n,remotes:a,onFetch:r,onSync:i,onRemoveRemote:o,disabled:d,removingRemoteName:c,aheadCount:f,behindCount:u,trackingRemoteName:p,hasUncommittedChanges:m}=s,I=a===void 0?[]:a,g=c===void 0?null:c,h=f===void 0?0:f,x=u===void 0?0:u,E=m===void 0?!1:m,{t:S}=ot(),C=l.useRef(!1),M=!!g,k=I.find(de=>de.name===p)??I[0],v=x>0&&E,b=d||n!==null||M||!k||v,D=d||n!==null||M||I.length===0,U=h>0||x>0;let T;e[0]!==S?(T=S("gitView.sync.sync"),e[0]=S,e[1]=T):T=e[1];const F=x>0?`↓${x}`:null,j=h>0?`↑${h}`:null;let P;e[2]!==T||e[3]!==F||e[4]!==j?(P=[T,F,j].filter(Boolean),e[2]=T,e[3]=F,e[4]=j,e[5]=P):P=e[5];const O=P.join(" "),R=v?S("gitView.sync.commitOrStashTooltip"):k?U?S("gitView.sync.syncChangesTooltip",{ahead:h,behind:x}):S("gitView.sync.syncChanges"):S("gitView.sync.noRemoteTooltip"),V=()=>{k&&i(k)},B="inline-flex items-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] border border-border/60 bg-[var(--surface-elevated)] overflow-hidden";let ee;e[6]===Symbol.for("react.memo_cache_sentinel")?(ee=le("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=ee):ee=e[6];let Y;e[7]!==S?(Y=S("gitView.sync.syncChanges"),e[7]=S,e[8]=Y):Y=e[8];let w;e[9]!==n?(w=n==="sync"?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=w):w=e[10];let H;e[11]!==O?(H=t.jsx("span",{className:"whitespace-nowrap tabular-nums",children:O}),e[11]=O,e[12]=H):H=e[12];let Q;e[13]!==V||e[14]!==b||e[15]!==Y||e[16]!==w||e[17]!==H?(Q=t.jsx(Dt,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:V,disabled:b,className:ee,"aria-label":Y,children:[w,H]})}),e[13]=V,e[14]=b,e[15]=Y,e[16]=w,e[17]=H,e[18]=Q):Q=e[18];let z;e[19]!==R?(z=t.jsx(At,{sideOffset:8,children:R}),e[19]=R,e[20]=z):z=e[20];let L;e[21]!==Q||e[22]!==z?(L=t.jsxs(It,{children:[Q,z]}),e[21]=Q,e[22]=z,e[23]=L):L=e[23];const X=gs;let $;e[24]===Symbol.for("react.memo_cache_sentinel")?($=le("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[24]=$):$=e[24];let ne;e[25]!==S?(ne=S("gitView.sync.moreActionsAria"),e[25]=S,e[26]=ne):ne=e[26];let re;e[27]===Symbol.for("react.memo_cache_sentinel")?(re=t.jsx(A,{name:"arrow-down-s",className:"size-4"}),e[27]=re):re=e[27];let _;e[28]!==D||e[29]!==ne?(_=t.jsx(us,{asChild:!0,children:t.jsx("button",{type:"button",className:$,disabled:D,"aria-label":ne,children:re})}),e[28]=D,e[29]=ne,e[30]=_):_=e[30];const oe=ps,fe="start",xe=-40,Ce="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ve=I.map(de=>t.jsx(ws,{onSelect:be=>{if(C.current){be.preventDefault(),C.current=!1;return}r(de)},children:t.jsxs("div",{className:"flex w-full items-center gap-2",children:[t.jsx(A,{name:"refresh",className:"size-4 text-muted-foreground"}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:S("gitView.sync.fetchFromRemote",{name:de.name})}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:de.fetchUrl})]})}),o&&de.name!==p?t.jsx(J,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||M,onPointerDown:be=>{C.current=!0,be.preventDefault(),be.stopPropagation()},onClick:be=>{C.current=!0,be.preventDefault(),be.stopPropagation(),o(de)},"aria-label":S("gitView.header.removeRemoteAria",{name:de.name}),title:S("gitView.header.removeRemoteTitle",{name:de.name}),children:g===de.name?t.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(A,{name:"close",className:"size-3.5"})}):null]})},de.name));let we;e[31]!==oe||e[32]!==ve?(we=t.jsx(oe,{align:fe,alignOffset:xe,className:Ce,children:ve}),e[31]=oe,e[32]=ve,e[33]=we):we=e[33];let ye;e[34]!==X||e[35]!==_||e[36]!==we?(ye=t.jsxs(X,{children:[_,we]}),e[34]=X,e[35]=_,e[36]=we,e[37]=ye):ye=e[37];let se;return e[38]!==L||e[39]!==ye?(se=t.jsxs("div",{className:B,children:[L,ye]}),e[38]=L,e[39]=ye,e[40]=se):se=e[40],se};function Ky(s){const e=st.c(85),{draft:n,onEdit:a,onDelete:r,className:i,maxWidth:o}=s,{t:d}=ot(),f=Ua()?.currentTheme,[u,p]=ge.useState(!1),[m,I]=ge.useState(!1),g=typeof n.text=="string"?n.text:"";let h;e[0]!==g?(h=g.length>150||g.split(`
|
|
30
|
-
`).length>3,e[0]=g,e[1]=h):h=e[1];const x=h;let E;e[2]!==i?(E=le("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]=E):E=e[3];const S=f?.colors?.surface?.elevated,C=f?.colors?.interactive?.border,M=o?`${Math.max(200,Math.floor(o))}px`:void 0;let k;e[4]!==S||e[5]!==C||e[6]!==M?(k={backgroundColor:S,borderColor:C,maxWidth:M},e[4]=S,e[5]=C,e[6]=M,e[7]=k):k=e[7];let v;e[8]===Symbol.for("react.memo_cache_sentinel")?(v=W=>{W.preventDefault(),I(!0)},e[8]=v):v=e[8];let b;e[9]!==E||e[10]!==k?(b=t.jsx("div",{className:E,style:k,"data-comment-card":"true",onContextMenu:v}),e[9]=E,e[10]=k,e[11]=b):b=e[11];let D;e[12]!==n.fileLabel?(D=t.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[12]=n.fileLabel,e[13]=D):D=e[13];let U;e[14]===Symbol.for("react.memo_cache_sentinel")?(U=t.jsx("span",{children:"•"}),e[14]=U):U=e[14];let T;e[15]!==n.endLine||e[16]!==n.startLine||e[17]!==d?(T=d("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[15]=n.endLine,e[16]=n.startLine,e[17]=d,e[18]=T):T=e[18];let F;e[19]!==T?(F=t.jsx("span",{children:T}),e[19]=T,e[20]=F):F=e[20];let j;e[21]!==n.side?(j=n.side&&t.jsxs("span",{children:["(",n.side,")"]}),e[21]=n.side,e[22]=j):j=e[22];let P;e[23]!==F||e[24]!==j||e[25]!==D?(P=t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[D,U,F,j]}),e[23]=F,e[24]=j,e[25]=D,e[26]=P):P=e[26];const O=u||!x,R=!u&&x&&"line-clamp-3";let V;e[27]!==R?(V=le("text-sm whitespace-pre-wrap break-words leading-relaxed",R),e[27]=R,e[28]=V):V=e[28];let B;e[29]!==g||e[30]!==V?(B=t.jsx("div",{className:V,children:g}),e[29]=g,e[30]=V,e[31]=B):B=e[31];let ee;e[32]!==x||e[33]!==u||e[34]!==d?(ee=x&&t.jsx(yn,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:u?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"arrow-up-s",className:"size-3 mr-1"}),d("inlineComment.actions.showLess")]}):t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"arrow-down-s",className:"size-3 mr-1"}),d("inlineComment.actions.showMore")]})})}),e[32]=x,e[33]=u,e[34]=d,e[35]=ee):ee=e[35];let Y;e[36]===Symbol.for("react.memo_cache_sentinel")?(Y=t.jsx(vn,{}),e[36]=Y):Y=e[36];let w;e[37]!==O||e[38]!==B||e[39]!==ee?(w=t.jsxs(bn,{open:O,onOpenChange:p,children:[B,ee,Y]}),e[37]=O,e[38]=B,e[39]=ee,e[40]=w):w=e[40];let H;e[41]!==P||e[42]!==w?(H=t.jsxs("div",{className:"flex-1 min-w-0",children:[P,w]}),e[41]=P,e[42]=w,e[43]=H):H=e[43];let Q;e[44]===Symbol.for("react.memo_cache_sentinel")?(Q=t.jsx(us,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:t.jsx(A,{name:"more",className:"size-4"})})}),e[44]=Q):Q=e[44];let z;e[45]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx(A,{name:"edit",className:"size-4 mr-2"}),e[45]=z):z=e[45];let L;e[46]!==d?(L=d("inlineComment.actions.editComment"),e[46]=d,e[47]=L):L=e[47];let X;e[48]!==a||e[49]!==L?(X=t.jsxs(ws,{onClick:a,children:[z,L]}),e[48]=a,e[49]=L,e[50]=X):X=e[50];let $;e[51]===Symbol.for("react.memo_cache_sentinel")?($=t.jsx(A,{name:"delete-bin",className:"size-4 mr-2"}),e[51]=$):$=e[51];let ne;e[52]!==d?(ne=d("inlineComment.actions.deleteComment"),e[52]=d,e[53]=ne):ne=e[53];let re;e[54]!==r||e[55]!==ne?(re=t.jsxs(ws,{onClick:r,className:"text-destructive",children:[$,ne]}),e[54]=r,e[55]=ne,e[56]=re):re=e[56];let _;e[57]!==X||e[58]!==re?(_=t.jsxs(gs,{children:[Q,t.jsxs(ps,{align:"end",children:[X,re]})]}),e[57]=X,e[58]=re,e[59]=_):_=e[59];let oe;e[60]!==H||e[61]!==_?(oe=t.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[H,_]}),e[60]=H,e[61]=_,e[62]=oe):oe=e[62];let fe;e[63]!==oe||e[64]!==b?(fe=t.jsx(nn,{render:b,children:oe}),e[63]=oe,e[64]=b,e[65]=fe):fe=e[65];let xe;e[66]===Symbol.for("react.memo_cache_sentinel")?(xe=t.jsx(A,{name:"edit",className:"size-4 mr-2"}),e[66]=xe):xe=e[66];let Ce;e[67]!==d?(Ce=d("inlineComment.actions.editComment"),e[67]=d,e[68]=Ce):Ce=e[68];let ve;e[69]!==a||e[70]!==Ce?(ve=t.jsxs(qs,{onClick:a,children:[xe,Ce]}),e[69]=a,e[70]=Ce,e[71]=ve):ve=e[71];let we;e[72]===Symbol.for("react.memo_cache_sentinel")?(we=t.jsx(A,{name:"delete-bin",className:"size-4 mr-2"}),e[72]=we):we=e[72];let ye;e[73]!==d?(ye=d("inlineComment.actions.deleteComment"),e[73]=d,e[74]=ye):ye=e[74];let se;e[75]!==r||e[76]!==ye?(se=t.jsxs(qs,{onClick:r,className:"text-destructive focus:text-destructive",children:[we,ye]}),e[75]=r,e[76]=ye,e[77]=se):se=e[77];let de;e[78]!==ve||e[79]!==se?(de=t.jsxs(an,{children:[ve,se]}),e[78]=ve,e[79]=se,e[80]=de):de=e[80];let be;return e[81]!==m||e[82]!==fe||e[83]!==de?(be=t.jsxs(sn,{open:m,onOpenChange:I,children:[fe,de]}),e[81]=m,e[82]=fe,e[83]=de,e[84]=be):be=e[84],be}function ml(s){const e=st.c(62),{initialText:n,onTextChange:a,onSave:r,onCancel:i,fileLabel:o,lineRange:d,isEditing:c,className:f,maxWidth:u}=s,p=n===void 0?"":n,m=c===void 0?!1:c,{t:I}=ot(),h=Ua()?.currentTheme,{isMobile:x}=Is(),[E,S]=l.useState(p),C=ge.useRef(null);let M;e[0]!==a?(M=ae=>{S(ae),a?.(ae)},e[0]=a,e[1]=M):M=e[1];const k=M,v=ge.useRef(d);let b,D;e[2]!==d?(b=()=>{d&&(v.current=d)},D=[d],e[2]=d,e[3]=b,e[4]=D):(b=e[3],D=e[4]),ge.useEffect(b,D);const U=Wy,T=U(d);let F,j;e[5]!==x?(F=()=>{const ae=C.current;if(!ae)return;const me=ae.closest(".overlay-scrollbar-container"),Me=me?.scrollTop??window.scrollY,Ne=me?.scrollLeft??window.scrollX;if(x){ae.scrollIntoView({behavior:"auto",block:"nearest"});try{ae.focus({preventScroll:!0})}catch{ae.focus()}return}try{ae.focus({preventScroll:!0})}catch{ae.focus()}const De=ae.value.length;try{ae.setSelectionRange(De,De)}catch{}requestAnimationFrame(()=>{me?(me.scrollTop=Me,me.scrollLeft=Ne):window.scrollTo({top:Me,left:Ne})})},j=[x],e[5]=x,e[6]=F,e[7]=j):(F=e[6],j=e[7]),ge.useEffect(F,j);let P;e[8]!==i||e[9]!==r||e[10]!==E?(P=ae=>{(ae.metaKey||ae.ctrlKey)&&ae.key==="Enter"?(ae.preventDefault(),E.trim()&&r(E,U(v.current))):ae.key==="Escape"&&(ae.preventDefault(),i())},e[8]=i,e[9]=r,e[10]=E,e[11]=P):P=e[11];const O=P;let R;e[12]!==r||e[13]!==E?(R=ae=>{ae.stopPropagation(),E.trim()&&r(E,U(v.current))},e[12]=r,e[13]=E,e[14]=R):R=e[14];const V=R;let B;e[15]!==f?(B=le("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",f),e[15]=f,e[16]=B):B=e[16];const ee=h?.colors?.surface?.elevated,Y=h?.colors?.interactive?.border,w=u?`${Math.max(200,Math.floor(u))}px`:void 0;let H;e[17]!==ee||e[18]!==Y||e[19]!==w?(H={backgroundColor:ee,borderColor:Y,maxWidth:w},e[17]=ee,e[18]=Y,e[19]=w,e[20]=H):H=e[20];const Q="true",z=Hy,L=_y,X="p-3",$=(o||d)&&t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[o&&t.jsx("span",{className:"truncate max-w-[200px]",children:o}),o&&d&&t.jsx("span",{children:"•"}),T&&t.jsx("span",{children:I("inlineComment.range.lines",{start:T.start,end:T.end})})]});let ne;e[21]!==k?(ne=ae=>k(ae.target.value),e[21]=k,e[22]=ne):ne=e[22];let re;e[23]!==x||e[24]!==I?(re=I(x?"inlineComment.input.placeholderShort":"inlineComment.input.placeholder"),e[23]=x,e[24]=I,e[25]=re):re=e[25];let _;e[26]!==O||e[27]!==ne||e[28]!==re||e[29]!==E?(_=t.jsx(hs,{simple:!0,ref:C,value:E,onChange:ne,onKeyDown:O,placeholder:re,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]=O,e[27]=ne,e[28]=re,e[29]=E,e[30]=_):_=e[30];let oe;e[31]!==I?(oe=I("inlineComment.actions.cancel"),e[31]=I,e[32]=oe):oe=e[32];let fe;e[33]!==i||e[34]!==oe?(fe=t.jsx(J,{variant:"ghost",size:"sm",onClick:i,onPointerDown:Vy,onTouchStart:By,className:"h-8 text-muted-foreground hover:text-foreground",children:oe}),e[33]=i,e[34]=oe,e[35]=fe):fe=e[35];let xe;e[36]!==E?(xe=E.trim(),e[36]=E,e[37]=xe):xe=e[37];const Ce=!xe,ve=h?.colors?.status?.success,we=h?.colors?.status?.successForeground;let ye;e[38]!==ve||e[39]!==we?(ye={backgroundColor:ve,color:we},e[38]=ve,e[39]=we,e[40]=ye):ye=e[40];let se;e[41]!==m||e[42]!==I?(se=I(m?"inlineComment.actions.save":"inlineComment.actions.comment"),e[41]=m,e[42]=I,e[43]=se):se=e[43];let de;e[44]!==V||e[45]!==Ce||e[46]!==ye||e[47]!==se?(de=t.jsx(J,{size:"sm",onClick:V,onPointerDown:$y,onTouchStart:Uy,disabled:Ce,className:"h-8 min-w-[80px]",style:ye,children:se}),e[44]=V,e[45]=Ce,e[46]=ye,e[47]=se,e[48]=de):de=e[48];let be;e[49]!==fe||e[50]!==de?(be=t.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[fe,de]}),e[49]=fe,e[50]=de,e[51]=be):be=e[51];let W;e[52]!==$||e[53]!==_||e[54]!==be?(W=t.jsxs("div",{className:X,children:[$,_,be]}),e[52]=$,e[53]=_,e[54]=be,e[55]=W):W=e[55];let te;return e[56]!==B||e[57]!==H||e[58]!==z||e[59]!==L||e[60]!==W?(te=t.jsx("div",{className:B,style:H,"data-comment-input":Q,onPointerDown:z,onTouchStart:L,children:W}),e[56]=B,e[57]=H,e[58]=z,e[59]=L,e[60]=W,e[61]=te):te=e[61],te}function Uy(s){return s.stopPropagation()}function $y(s){return s.stopPropagation()}function By(s){return s.stopPropagation()}function Vy(s){return s.stopPropagation()}function _y(s){return s.stopPropagation()}function Hy(s){return s.stopPropagation()}function Wy(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 qy=s=>{const e=Math.min(s.startLine,s.endLine),n=Math.max(s.startLine,s.endLine);return{...s,startLine:e,endLine:n}},ul=s=>{const e=Math.min(s.start,s.end),n=Math.max(s.start,s.end);return{...s,start:e,end:n}};function Gy(s){const e=st.c(40),{t:n}=ot(),{source:a,fileLabel:r,language:i,getCodeForRange:o,toStoreRange:d,fromDraftRange:c}=s,f=ks(ev),u=ks(Zy),p=ia(Xy),m=ia(Yy),I=ia(Qy),g=ia(Jy),[h,x]=l.useState(null),[E,S]=l.useState(""),[C,M]=l.useState(null),k=f??(u?"draft":null);let v;e:{if(!k||!r){let Q;e[0]===Symbol.for("react.memo_cache_sentinel")?(Q=[],e[0]=Q):Q=e[0],v=Q;break e}let Y;e[1]!==g||e[2]!==k?(Y=g[k]??[],e[1]=g,e[2]=k,e[3]=Y):Y=e[3];const w=Y;let H;if(e[4]!==r||e[5]!==w||e[6]!==a){let Q;e[8]!==r||e[9]!==a?(Q=z=>z.source===a&&z.fileLabel===r,e[8]=r,e[9]=a,e[10]=Q):Q=e[10],H=w.filter(Q),e[4]=r,e[5]=w,e[6]=a,e[7]=H}else H=e[7];v=H}const b=v;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{x(null),S(""),M(null)},e[11]=D):D=e[11];const U=D;let T;e[12]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{U()},e[12]=T):T=e[12];const F=T;let j;e[13]!==c?(j=Y=>{const w=ul(c(Y));x(w),S(Y.text),M(Y.id)},e[13]=c,e[14]=j):j=e[14];const P=j;let O;e[15]!==C||e[16]!==I?(O=Y=>{I(Y.sessionKey,Y.id),C===Y.id&&U()},e[15]=C,e[16]=I,e[17]=O):O=e[17];const R=O;let V;e[18]!==p||e[19]!==C||e[20]!==r||e[21]!==o||e[22]!==i||e[23]!==h||e[24]!==k||e[25]!==a||e[26]!==n||e[27]!==d||e[28]!==m?(V=(Y,w)=>{const H=w??h,Q=Y.trim();if(!H||!Q||!r)return;if(!k){q.error(n("inlineComment.toast.selectSessionToSave"));return}const z=ul(H),L=qy(d(z)),X=o(z);C?m(k,C,{fileLabel:r,startLine:L.startLine,endLine:L.endLine,side:L.side,code:X,language:i,text:Q}):p({sessionKey:k,source:a,fileLabel:r,startLine:L.startLine,endLine:L.endLine,side:L.side,code:X,language:i,text:Q}),U()},e[18]=p,e[19]=C,e[20]=r,e[21]=o,e[22]=i,e[23]=h,e[24]=k,e[25]=a,e[26]=n,e[27]=d,e[28]=m,e[29]=V):V=e[29];const B=V;let ee;return e[30]!==E||e[31]!==R||e[32]!==b||e[33]!==C||e[34]!==c||e[35]!==B||e[36]!==h||e[37]!==k||e[38]!==P?(ee={sessionKey:k,drafts:b,selection:h,setSelection:x,commentText:E,setCommentText:S,editingDraftId:C,setEditingDraftId:M,reset:U,cancel:F,startEdit:P,deleteDraft:R,saveComment:B,fromDraftRange:c},e[30]=E,e[31]=R,e[32]=b,e[33]=C,e[34]=c,e[35]=B,e[36]=h,e[37]=k,e[38]=P,e[39]=ee):ee=e[39],ee}function Jy(s){return s.drafts}function Qy(s){return s.removeDraft}function Yy(s){return s.updateDraft}function Xy(s){return s.addDraft}function Zy(s){return s.newSessionDraft?.open}function ev(s){return s.currentSessionId}const Ma=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}`},tv=s=>{const{drafts:e,editingDraftId:n,selection:a}=s,r=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const o=Math.max(1,Math.floor(i.endLine)),d=i.side==="original"?"deletions":"additions";r.push({lineNumber:o,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 sv(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 pl(s){if(!(!s||s<=0))return Math.max(200,Math.floor(s))}function nv(s){const{diffRootRef:e,drafts:n,selection:a,editingDraftId:r,commentText:i,onTextChange:o,fileLabel:d,onSave:c,onCancel:f,onEdit:u,onDelete:p}=s,[m,I]=l.useState(0),[g,h]=l.useState(null),x=l.useMemo(()=>!a||r?null:Ma({type:"new",selection:a}),[r,a]),E=l.useMemo(()=>{const M=n.map(k=>Ma({type:k.id===r?"edit":"saved",draft:k}));return x&&M.push(x),M},[n,r,x]),S=l.useCallback(M=>{const k=e.current;if(!k)return null;const v=k.querySelector("diffs-container");if(!(v instanceof HTMLElement))return null;const b=v.querySelector(`[data-annotation-id="${M}"]`);if(b instanceof HTMLElement)return b;const D=v.shadowRoot;return D?D.querySelector(`[data-annotation-id="${M}"]`):null},[e]);l.useEffect(()=>{if(E.length===0)return;let M=!1,k=0;const v=12,b=()=>{M||E.every(U=>!!S(U))||k>=v||(k+=1,requestAnimationFrame(()=>{M||(I(U=>U+1),b())}))};return b(),()=>{M=!0}},[E,S]),l.useEffect(()=>{const M=e.current;if(!M)return;const k=()=>{const b=getComputedStyle(M),D=sv(b.getPropertyValue("--oc-context-panel-width")),U=M.getBoundingClientRect(),T=D??U.width;h(T>0?T:null)};k();const v=new ResizeObserver(()=>{k()});return v.observe(M),window.addEventListener("resize",k),()=>{v.disconnect(),window.removeEventListener("resize",k)}},[e]);const C=l.useCallback(M=>{const v=e.current?.getBoundingClientRect(),b=M.closest("[data-annotation-content]"),D=b instanceof HTMLElement?b.getBoundingClientRect():M.getBoundingClientRect(),U=[D.width];v&&U.push(v.right-D.left);const T=U.filter(F=>Number.isFinite(F)&&F>0);return T.length>0?pl(Math.min(...T)):pl(g)},[e,g]);return t.jsxs(t.Fragment,{children:[n.map(M=>{const k=Ma({type:M.id===r?"edit":"saved",draft:M}),v=S(k);if(!v)return null;const b=C(v);return M.id===r?Na.createPortal(t.jsx(ml,{initialText:i,onTextChange:o,fileLabel:d,lineRange:{start:M.startLine,end:M.endLine,side:M.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:f,maxWidth:b}),v,`draft-edit-${M.id}`):Na.createPortal(t.jsx(Ky,{draft:M,onEdit:()=>u(M),onDelete:()=>p(M),maxWidth:b}),v,`draft-card-${M.id}`)}),a&&!r&&x&&(()=>{const M=S(x);if(!M)return null;const k=C(M);return Na.createPortal(t.jsx(ml,{initialText:i,onTextChange:o,fileLabel:d,lineRange:a,isEditing:!1,onSave:c,onCancel:f,maxWidth:k}),M,x)})()]})}const gl=5e5,av=`
|
|
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
|
-
`,rv=`
|
|
53
|
-
${av}
|
|
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 iv(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 hl(s){const e=s.length>400?`${s.slice(0,200)}${s.slice(-200)}`:s;return`${s.length}:${iv(e)}`}const ov=(s,e,n,a)=>{const r=a.side==="deletions",o=(n?(r?n.deletionLines:n.additionLines).join(""):r?s:e).split(`
|
|
164
|
-
`),d=Math.min(a.start,a.end),c=Math.max(a.start,a.end),f=Math.max(1,d),u=Math.min(o.length,c);return f>u?"":o.slice(f-1,u).join(`
|
|
165
|
-
`)},lv=(s,e)=>s===e?!0:!s||!e?!1:s.start===e.start&&s.end===e.end&&s.side===e.side,cv=s=>s==="auto"||s==="scroll"||s==="overlay",dv=s=>{let e=s?.parentElement??null;for(;e;){const n=window.getComputedStyle(e);if(cv(n.overflowY))return e;e=e.parentElement}return null},mv=(s,e)=>{if(!s||!e||typeof window>"u")return()=>{};const n=dv(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 o=!1;return()=>{if(o)return;o=!0,e.style.minHeight=i;const c=s.getBoundingClientRect().top-n.getBoundingClientRect().top-r;c&&(n.scrollTop+=c)}},uv=(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()})}))},o=()=>s.querySelector("diffs-container")?.shadowRoot??void 0,d=(c=o())=>!!c?.querySelector("[data-line]");return d()?i():typeof MutationObserver<"u"?(a=new MutationObserver(()=>{const c=o();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)}},wa=new WeakMap,pv={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function gv(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 hv(s){if(typeof document>"u")return null;const e=gv(s);let n=wa.get(e.key);if(!n){const r=new xd;r.setup(e.root,e.content),n={virtualizer:r,refs:0},wa.set(e.key,n)}n.refs+=1;let a=!1;return{virtualizer:n.virtualizer,root:e.root,release:()=>{if(a)return;a=!0;const r=wa.get(e.key);r&&(r.refs-=1,!(r.refs>0)&&(r.virtualizer.cleanUp(),wa.delete(e.key)))}}}const fv=(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)}},tj=({original:s,modified:e,fileDiff:n,language:a,fileName:r,renderSideBySide:i,wrapLines:o,layout:d="fill",enableComments:c=!0})=>{const f=Ua(),u=f?.currentTheme.metadata.variant==="dark",p=f?.availableThemes.find(W=>W.metadata.id===f.lightThemeId)??Ta(!1),m=f?.availableThemes.find(W=>W.metadata.id===f.darkThemeId)??Ta(!0),{isMobile:I}=Is(),g=Gy({source:"diff",fileLabel:r||"unknown",language:a,getCodeForRange:W=>ov(s,e,n,W),toStoreRange:W=>({startLine:W.start,endLine:W.end,side:W.side==="deletions"?"original":"modified"}),fromDraftRange:W=>({start:W.startLine,end:W.endLine,side:W.side==="original"?"deletions":"additions"})}),{drafts:h,selection:x,setSelection:E,commentText:S,setCommentText:C,editingDraftId:M,saveComment:k,cancel:v,startEdit:b,deleteDraft:D}=g,U=ge.useRef(null),T=ge.useRef(null),F=ge.useRef(""),j=ge.useRef(!1),P=ge.useRef(null);ge.useEffect(()=>{U.current=x},[x]),ge.useEffect(()=>{T.current=M},[M]),ge.useEffect(()=>{F.current=S},[S]);const O=ge.useCallback(W=>{if(!c||j.current)return;const te=U.current;if(!(!W&&te&&F.current.trim())){if(I&&te&&W&&W.side===te.side){const ae=Math.min(te.start,W.start),me=Math.max(te.end,W.end);E({...W,start:ae,end:me})}else E(W);W&&(T.current||C(""))}},[c,I,C,E]),R=ge.useCallback(()=>{v()},[v]),V=ge.useCallback(W=>{const te=document.createElement("div");te.style.position="relative";const ae=Ma(W.metadata);return te.dataset.annotationId=ae,te.dataset.annotationSide=W.side,te.dataset.annotationLine=String(W.lineNumber),te},[]),B=ge.useCallback((W,te)=>{k(W,te??x??void 0)},[k,x]),ee=ge.useCallback(W=>{E(W);const te=L.current;if(te)try{j.current=!0,te.setSelectedLines(W),P.current=W}catch{}finally{j.current=!1}},[E]),Y=ge.useCallback(W=>{const te=W.closest("[data-line-type]")?.getAttribute("data-line-type")??W.getAttribute("data-line-type");if(te==="change-deletion")return"deletions";if(te==="change-addition")return"additions";const ae=W.getAttribute("data-column-side")??W.getAttribute("data-side")??W.closest("[data-column-side]")?.getAttribute("data-column-side");if(ae==="deletions"||ae==="left"||ae==="original")return"deletions";if(ae==="additions"||ae==="right"||ae==="modified")return"additions";const me=W.closest("[data-line-type]");if(me instanceof HTMLElement){const Me=me.getBoundingClientRect(),Ne=W.getBoundingClientRect(),De=Me.left+Me.width/2;return Ne.left+Ne.width/2<De?"deletions":"additions"}return"additions"},[]);Fa(p),Fa(m);const w=`${p.metadata.id}:${m.metadata.id}:${u?"dark":"light"}`,H=ge.useMemo(()=>{if(n){const W=n.deletionLines.reduce((ae,me)=>ae+me.length,0),te=n.additionLines.reduce((ae,me)=>ae+me.length,0);return Math.max(W,te)>gl}return Math.max(s.length,e.length)>gl},[n,e.length,s.length]),Q=ge.useRef(null),z=ge.useRef(null),L=ge.useRef(null),X=ge.useRef(null),$=ge.useRef(null),ne=ge.useRef(null),re=ge.useRef(void 0),_=ge.useRef(void 0),oe=ge.useRef(void 0),fe=ge.useRef(void 0),[,xe]=l.useReducer(W=>W+1,0),Ce=Lr(H?"unified":i?"split":"unified"),ve=ge.useMemo(()=>Ir(p),[p]),we=ge.useMemo(()=>Ir(m),[m]);l.useLayoutEffect(()=>{const W=Q.current;if(!W)return;const te=W.querySelector("diffs-container");if(!te)return;const ae=u?we:ve,me=(qe,ce)=>qe.colors?.[ce],Me=me(ve,"terminal.ansiGreen"),Ne=me(ve,"terminal.ansiRed"),De=me(ve,"terminal.ansiBlue"),Ae=me(we,"terminal.ansiGreen"),Pe=me(we,"terminal.ansiRed"),Re=me(we,"terminal.ansiBlue");te.style.setProperty("--shiki-light",ve.fg),te.style.setProperty("--shiki-light-bg",ve.bg),Me&&te.style.setProperty("--shiki-light-addition-color",Me),Ne&&te.style.setProperty("--shiki-light-deletion-color",Ne),De&&te.style.setProperty("--shiki-light-modified-color",De),te.style.setProperty("--shiki-dark",we.fg),te.style.setProperty("--shiki-dark-bg",we.bg),Ae&&te.style.setProperty("--shiki-dark-addition-color",Ae),Pe&&te.style.setProperty("--shiki-dark-deletion-color",Pe),Re&&te.style.setProperty("--shiki-dark-modified-color",Re),te.style.setProperty("--diffs-bg",ae.bg),te.style.setProperty("--diffs-fg",ae.fg);const Fe=u?Ae:Me,Ue=u?Pe:Ne,_e=u?Re:De;Fe&&te.style.setProperty("--diffs-addition-color-override",Fe),Ue&&te.style.setProperty("--diffs-deletion-color-override",Ue),_e&&te.style.setProperty("--diffs-modified-color-override",_e);const Ke=te.shadowRoot?.querySelector("pre");Ke&&(Ke.style.setProperty("--shiki-light",ve.fg),Ke.style.setProperty("--shiki-light-bg",ve.bg),Me&&Ke.style.setProperty("--shiki-light-addition-color",Me),Ne&&Ke.style.setProperty("--shiki-light-deletion-color",Ne),De&&Ke.style.setProperty("--shiki-light-modified-color",De),Ke.style.setProperty("--shiki-dark",we.fg),Ke.style.setProperty("--shiki-dark-bg",we.bg),Ae&&Ke.style.setProperty("--shiki-dark-addition-color",Ae),Pe&&Ke.style.setProperty("--shiki-dark-deletion-color",Pe),Re&&Ke.style.setProperty("--shiki-dark-modified-color",Re),Ke.style.setProperty("--diffs-bg",ae.bg),Ke.style.setProperty("--diffs-fg",ae.fg),Fe&&Ke.style.setProperty("--diffs-addition-color-override",Fe),Ue&&Ke.style.setProperty("--diffs-deletion-color-override",Ue),_e&&Ke.style.setProperty("--diffs-modified-color-override",_e))},[we,w,u,ve]);const ye=ge.useMemo(()=>({theme:{dark:m.metadata.id,light:p.metadata.id},themeType:u?"dark":"light",diffStyle:i?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:H?0:1e3,maxLineLengthForHighlighting:H?1:1e3,tokenizeMaxLineLength:H?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:o?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:c,enableHoverUtility:!1,onLineSelected:c?O:void 0,unsafeCSS:rv,renderAnnotation:c?V:void 0}),[m.metadata.id,c,u,H,p.metadata.id,i,o,O,V]),se=ge.useMemo(()=>c?tv({drafts:h,editingDraftId:M,selection:x}):[],[M,c,h,x]),de=ge.useRef(se);if(ge.useEffect(()=>{de.current=se},[se]),ge.useEffect(()=>{const W=z.current;return()=>{L.current?.cleanUp(),L.current=null,X.current?.release(),X.current=null,$.current=null,ne.current=null,re.current=void 0,_.current=void 0,oe.current=void 0,fe.current=void 0,W&&(W.innerHTML="")}},[]),ge.useEffect(()=>{if(typeof window>"u")return;const W=z.current,te=Q.current;if(!W||!Ce)return;const ae=mv(te,W);let me=X.current;me||(me=hv(W),X.current=me),X.current=me;const Me=me?.virtualizer??null,Ne=n?void 0:{name:r||"",contents:s,lang:a,cacheKey:`old:${w}:${r}:${hl(s)}`},De=n?void 0:{name:r||"",contents:e,lang:a,cacheKey:`new:${w}:${r}:${hl(e)}`},Ae=n?_.current!==n:_.current!==void 0||!Ne||!De||!oe.current||!fe.current||!mi(oe.current,Ne)||!mi(fe.current,De),Pe=L.current,Re=!!(Pe&&($.current!==Me||ne.current!==Ce||Me&&(re.current!==ye.hunkSeparators||Ae)));Re&&(Pe?.cleanUp(),L.current=null,W.innerHTML="");let Fe=L.current;const Ue=!Re&&Pe?!gd(Pe.options,ye):!1;if(Fe?Fe.setOptions(ye):(Fe=me?new hd(ye,me.virtualizer,pv,Ce):new fd(ye,Ce),L.current=Fe,P.current=null),$.current=Me,ne.current=Ce,re.current=Me?ye.hunkSeparators:void 0,_.current=n,oe.current=Ne,fe.current=De,n)Fe.render({fileDiff:n,forceRender:Ue,lineAnnotations:de.current,containerWrapper:W});else{if(!Ne||!De)return;Fe.render({oldFile:Ne,newFile:De,forceRender:Ue,lineAnnotations:de.current,containerWrapper:W})}const _e=uv(W,()=>{ae(),fv(Fe,me,xe)});return()=>{_e(),ae()}},[w,n,r,a,e,ye,s,Ce]),ge.useEffect(()=>{const W=L.current;if(W){try{W.setLineAnnotations(se)}catch(te){console.error("Failed to apply diff line annotations",te);try{W.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(L.current===W){try{W.rerender()}catch{}xe()}})}},[se]),ge.useEffect(()=>{const W=L.current;if(!W||x!==null)return;const te=P.current;if(!lv(x,te))try{j.current=!0,W.setSelectedLines(x),P.current=x}catch{}finally{j.current=!1}},[x]),ge.useEffect(()=>{if(!c)return;const W=z.current;if(!W)return;let te=null,ae=()=>{};const me=()=>{const Ne=W.querySelector("diffs-container")?.shadowRoot;if(!Ne){te=requestAnimationFrame(me);return}const De=Ae=>{if(!(Ae instanceof MouseEvent)||Ae.button!==0||!(Ae.target instanceof Element))return;const Pe=Ae.target.closest("[data-column-number]");if(!(Pe instanceof HTMLElement))return;const Re=Pe.getAttribute("data-column-number"),Fe=Re?parseInt(Re,10):NaN;if(Number.isNaN(Fe))return;const Ue=Y(Pe);O({start:Fe,end:Fe,side:Ue}),Ae.preventDefault(),Ae.stopPropagation()};Ne.addEventListener("click",De,!0),ae=()=>{Ne.removeEventListener("click",De,!0)}};return me(),()=>{te!==null&&cancelAnimationFrame(te),ae()}},[w,c,r,O,Y]),ge.useEffect(()=>{const W=z.current;if(!W)return;let te=null,ae=null;const Me=setTimeout(()=>{const Ne=W.querySelector("diffs-container");if(!(Ne instanceof HTMLElement))return;const De=Ne.shadowRoot;te=new MutationObserver(()=>{ae&&cancelAnimationFrame(ae),ae=requestAnimationFrame(()=>{xe(),ae=null})}),te.observe(Ne,{childList:!0,subtree:!0}),De&&te.observe(De,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(Me),ae&&cancelAnimationFrame(ae),te?.disconnect()}},[w,r]),typeof window>"u")return null;const be=c?t.jsx(nv,{diffRootRef:Q,drafts:h,selection:x,editingDraftId:M,commentText:S,onTextChange:C,fileLabel:r?.split("/").pop()??"",onSave:B,onCancel:R,onEdit:W=>{ee({start:W.startLine,end:W.endLine,side:W.side==="original"?"deletions":"additions"}),b(W)},onDelete:D}):null;return d==="fill"?t.jsx("div",{className:le("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(qt,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:t.jsx("div",{ref:Q,className:"size-full relative",children:t.jsx("div",{ref:z,className:"size-full"})})}),be]})}):t.jsxs("div",{className:le("relative","w-full"),children:[t.jsx("div",{ref:Q,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:t.jsx("div",{ref:z,className:"w-full"})}),be]})},xv=()=>{const s=st.c(13),[e,n]=ge.useState(!1);let a,r;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{n(ls())},r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),ge.useEffect(a,r);let i;s[2]!==e?(i=async m=>e?await cu(m):{success:!0,path:m},s[2]=e,s[3]=i):i=s[3];const o=i;let d;s[4]!==e?(d=async m=>e?await du():{success:!0},s[4]=e,s[5]=d):d=s[5];const c=d;let f;s[6]!==e?(f=async m=>e?await mu():{success:!0},s[6]=e,s[7]=f):f=s[7];const u=f;let p;return s[8]!==e||s[9]!==o||s[10]!==c||s[11]!==u?(p={isDesktop:e,requestAccess:o,startAccessing:c,stopAccessing:u},s[8]=e,s[9]=o,s[10]=c,s[11]=u,s[12]=p):p=s[12],p},bv=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),yv=({currentBranch:s,localBranches:e,remoteBranches:n,branchInfo:a,onCheckout:r,onCreate:i,remotes:o=[],disabled:d=!1})=>{const{t:c}=ot(),[f,u]=l.useState(!1),[p,m]=l.useState(""),[I,g]=l.useState(!1),[h,x]=l.useState(!1),[E,S]=l.useState(""),[C,M]=l.useState(!1),k=l.useRef(null),v=l.useCallback(B=>{B.stopPropagation()},[]),b=o.length>1,D=l.useMemo(()=>bv(E),[E]),U=l.useMemo(()=>{const B=p.toLowerCase();return B?e.filter(ee=>ee.toLowerCase().includes(B)):e},[p,e]),T=l.useMemo(()=>{const B=p.toLowerCase();return B?n.filter(ee=>ee.toLowerCase().includes(B)):n},[p,n]),F=B=>{if(B===s){u(!1);return}r(B),u(!1),m("")},j=()=>{g(!0),setTimeout(()=>k.current?.focus(),50)},P=async()=>{if(!(!D||C)){if(b){x(!0);return}M(!0);try{await i(D,o[0]),S(""),g(!1),u(!1)}finally{M(!1)}}},O=async B=>{if(!(!D||C)){M(!0);try{await i(D,B),S(""),g(!1),x(!1),u(!1)}finally{M(!1)}}},R=()=>{x(!1)},V=()=>{S(""),g(!1),x(!1)};return l.useEffect(()=>{f||(m(""),g(!1),x(!1),S(""))},[f]),t.jsxs(gs,{open:f,onOpenChange:u,children:[t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(us,{asChild:!0,children:t.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:d,children:[t.jsx(A,{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(A,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),t.jsx(At,{sideOffset:8,children:c("gitView.branch.currentBranchTooltip")})]}),t.jsx(ps,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:t.jsxs(Er,{className:"h-full min-h-0",children:[t.jsx(Mr,{placeholder:c("gitView.branch.searchPlaceholder"),value:p,onValueChange:m,onKeyDown:v}),t.jsxs(Rr,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Tr,{children:c("gitView.branch.empty")}),t.jsx(Bs,{children:h?t.jsxs("div",{className:"px-2 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("button",{type:"button",onClick:R,disabled:C,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(A,{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:D})," ",c("gitView.branch.pushToSuffix")]})]}),t.jsx("div",{className:"flex flex-col gap-1",children:o.map(B=>t.jsxs("button",{type:"button",onClick:()=>O(B),disabled:C,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[t.jsxs("span",{className:"typography-ui-label text-foreground",children:[C?t.jsx(A,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,B.name]}),t.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:B.pushUrl})]},B.name))})]}):I?t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[t.jsx("input",{ref:k,placeholder:c("gitView.branch.newBranchPlaceholder"),value:E,onChange:B=>S(B.target.value),onClick:B=>B.stopPropagation(),onKeyDown:B=>{v(B),B.key==="Enter"?(B.preventDefault(),P()):B.key==="Escape"&&(B.preventDefault(),V())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),t.jsx("button",{type:"button",onClick:P,disabled:!D||C,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:C?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"add",className:"size-4"})}),t.jsx("button",{type:"button",onClick:V,disabled:C,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(A,{name:"close",className:"size-4"})})]}):t.jsxs(Ms,{onSelect:j,children:[t.jsx(A,{name:"add",className:"size-4"}),t.jsx("span",{children:c("gitView.branch.create")})]})}),t.jsx(An,{}),t.jsxs(Bs,{heading:c("gitView.branch.localBranches"),children:[U.map(B=>t.jsxs(Ms,{onSelect:()=>F(B),children:[t.jsxs("span",{className:"flex flex-1 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:B}),(a?.[B]?.ahead||a?.[B]?.behind)&&t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[a[B].ahead||0," ahead ·"," ",a[B].behind||0," behind"]})]}),s===B&&t.jsx("span",{className:"typography-micro text-primary",children:c("gitView.branch.currentBadge")})]},`local-${B}`)),U.length===0&&t.jsx(Ms,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noLocalBranches")})})]}),t.jsx(An,{}),t.jsxs(Bs,{heading:c("gitView.branch.remoteBranches"),children:[T.map(B=>t.jsx(Ms,{onSelect:()=>F(B),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:B})},`remote-${B}`)),T.length===0&&t.jsx(Ms,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noRemoteBranches")})})]})]})]})})]})},vv=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),jv=({currentBranch:s,onRename:e,showEditButton:n=!0})=>{const{t:a}=ot(),[r,i]=l.useState(!1),[o,d]=l.useState(s||""),[c,f]=l.useState(!1),u=l.useRef(null),p=()=>{!s||!e||(d(s),i(!0),setTimeout(()=>u.current?.focus(),0))},m=async()=>{if(!s||!e||!o.trim())return;const h=vv(o);if(h===s){i(!1);return}f(!0);try{await e(s,h),i(!1),d("")}finally{f(!1)}},I=()=>{i(!1),d("")},g=h=>{h.key==="Enter"?(h.preventDefault(),m()):h.key==="Escape"&&(h.preventDefault(),I())};return r?t.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:t.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:h=>{h.preventDefault(),m()},children:[t.jsx(A,{name:"git-branch",className:"size-4 text-primary"}),t.jsx("input",{ref:u,value:o,onChange:h=>d(h.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:a("gitView.branch.namePlaceholder"),onKeyDown:g,autoFocus:!0}),t.jsx("button",{type:"submit",disabled:c,"aria-label":a(c?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:a(c?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:c?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"check",className:"size-4"})}),t.jsx("button",{type:"button",onClick:I,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(A,{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(A,{name:"git-branch",className:"size-4 text-primary shrink-0"}),t.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[t.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:s||a("gitView.branch.detachedHead")}),n&&e&&s&&t.jsx(J,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:p,title:a("gitView.branch.renameTitle"),children:t.jsx(A,{name:"edit",className:"size-4"})})]})]})},wv={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},Nv={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 yc(s){return s&&Nv[s]||"var(--primary)"}const fl=s=>{const e=st.c(8),{icon:n,className:a,colorToken:r}=s,i=wv[n??"branch"]??"user-3";let o;e[0]!==r?(o=yc(r),e[0]=r,e[1]=o):o=e[1];let d;e[2]!==o?(d={color:o},e[2]=o,e[3]=d):d=e[3];let c;return e[4]!==a||e[5]!==i||e[6]!==d?(c=t.jsx(A,{name:i,className:a,style:d}),e[4]=a,e[5]=i,e[6]=d,e[7]=c):c=e[7],c},vc=s=>{const e=st.c(35),{activeProfile:n,identities:a,onSelect:r,isApplying:i,iconOnly:o}=s,d=o===void 0?!1:o,{t:c}=ot(),f=i||a.length===0,u=n?.color;let p;e[0]!==u?(p=yc(u),e[0]=u,e[1]=p):p=e[1];let m;e[2]!==p?(m={color:p},e[2]=p,e[3]=m):m=e[3];let I;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(I=i?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(fl,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=I):I=e[7];let g;e[8]!==n?.name||e[9]!==d||e[10]!==c?(g=!d&&t.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||c("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=d,e[10]=c,e[11]=g):g=e[11];let h;e[12]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=h):h=e[12];let x;e[13]!==f||e[14]!==m||e[15]!==I||e[16]!==g?(x=t.jsx(Dt,{asChild:!0,children:t.jsx(us,{asChild:!0,children:t.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:m,disabled:f,children:[I,g,h]})})}),e[13]=f,e[14]=m,e[15]=I,e[16]=g,e[17]=x):x=e[17];let E;e[18]!==c?(E=c("gitView.header.identityTooltip"),e[18]=c,e[19]=E):E=e[19];let S;e[20]!==E?(S=t.jsx(At,{sideOffset:8,children:E}),e[20]=E,e[21]=S):S=e[21];let C;e[22]!==S||e[23]!==x?(C=t.jsxs(It,{children:[x,S]}),e[22]=S,e[23]=x,e[24]=C):C=e[24];let M;e[25]!==n?.id||e[26]!==a||e[27]!==r||e[28]!==c?(M=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(b=>{const D=n?.id===b.id;return t.jsx(ws,{onSelect:()=>r(b),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(fl,{icon:b.icon,colorToken:b.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:b.name}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:b.userEmail})]}),D?t.jsx(A,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},b.id)}),e[25]=n?.id,e[26]=a,e[27]=r,e[28]=c,e[29]=M):M=e[29];let k;e[30]!==M?(k=t.jsx(ps,{align:"end",className:"w-64",children:M}),e[30]=M,e[31]=k):k=e[31];let v;return e[32]!==C||e[33]!==k?(v=t.jsxs(gs,{children:[C,k]}),e[32]=C,e[33]=k,e[34]=v):v=e[34],v},kv=s=>{const e=st.c(21),{comparison:n,trackingBranch:a,tooltipDelayMs:r}=s,i=r===void 0?1e3:r,{t:o}=ot(),d=`${n.remote}/${n.branch}`,c=n.ahead===0&&n.behind===0;let f;e[0]!==o||e[1]!==d||e[2]!==a?(f=a?o("gitView.header.upstreamTooltipTracking",{target:d,tracking:a}):o("gitView.header.upstreamTooltip",{target:d}),e[0]=o,e[1]=d,e[2]=a,e[3]=f):f=e[3];const u=f;let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(A,{name:"git-branch",className:"size-3.5 shrink-0"}),e[4]=p):p=e[4];let m;e[5]!==d?(m=t.jsx("span",{className:"min-w-0 truncate text-foreground/80",children:d}),e[5]=d,e[6]=m):m=e[6];let I;e[7]!==n.ahead||e[8]!==n.behind||e[9]!==c||e[10]!==o?(I=c?t.jsx("span",{className:"tabular-nums text-muted-foreground",children:o("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]=o,e[11]=I):I=e[11];let g;e[12]!==m||e[13]!==I?(g=t.jsx(Dt,{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,m,I]})}),e[12]=m,e[13]=I,e[14]=g):g=e[14];let h;e[15]!==u?(h=t.jsx(At,{sideOffset:8,children:u}),e[15]=u,e[16]=h):h=e[16];let x;return e[17]!==g||e[18]!==h||e[19]!==i?(x=t.jsxs(It,{delayDuration:i,children:[g,h]}),e[17]=g,e[18]=h,e[19]=i,e[20]=x):x=e[20],x},sj=s=>{const e=st.c(54),{status:n,localBranches:a,remoteBranches:r,branchInfo:i,syncAction:o,remotes:d,onFetch:c,onSync:f,onRemoveRemote:u,removingRemoteName:p,onCheckoutBranch:m,onCreateBranch:I,onRenameBranch:g,activeIdentityProfile:h,availableIdentities:x,onSelectIdentity:E,isApplyingIdentity:S,isWorktreeMode:C,onOpenHistory:M,onOpenGraph:k,onOpenStashes:v,actionTabItems:b,activeActionTab:D,onSelectActionTab:U}=s,{t:T}=ot();if(!n)return null;let F;e[0]!==k||e[1]!==M||e[2]!==v||e[3]!==T?(F=M||k||v?t.jsxs(gs,{children:[t.jsxs(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(us,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":T("gitView.header.repositoryViews"),children:t.jsx(A,{name:"git-repository",className:"size-4"})})})}),t.jsx(At,{sideOffset:8,children:T("gitView.header.repositoryViews")})]}),t.jsxs(ps,{align:"end",children:[M?t.jsxs(ws,{onSelect:M,children:[t.jsx(A,{name:"history",className:"size-4"}),T("gitView.history.title")]}):null,k?t.jsxs(ws,{onSelect:k,children:[t.jsx(A,{name:"git-merge",className:"size-4"}),T("gitView.graph.title")]}):null,v?t.jsxs(ws,{onSelect:v,children:[t.jsx(A,{name:"archive-stack",className:"size-4"}),T("gitView.stashes.title")]}):null]})]}):null,e[0]=k,e[1]=M,e[2]=v,e[3]=T,e[4]=F):F=e[4];let j;e[5]!==F?(j=t.jsx("div",{className:"flex items-center gap-1 shrink-0",children:F}),e[5]=F,e[6]=j):j=e[6];const P=j,O=!n;let R;e[7]!==n.tracking?(R=n.tracking?.split("/")[0],e[7]=n.tracking,e[8]=R):R=e[8];const V=(n.files?.length??0)>0;let B;e[9]!==c||e[10]!==u||e[11]!==f||e[12]!==d||e[13]!==p||e[14]!==n.ahead||e[15]!==n.behind||e[16]!==o||e[17]!==O||e[18]!==R||e[19]!==V?(B=t.jsx(zy,{syncAction:o,remotes:d,onFetch:c,onSync:f,onRemoveRemote:u,removingRemoteName:p,disabled:O,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:R,hasUncommittedChanges:V}),e[9]=c,e[10]=u,e[11]=f,e[12]=d,e[13]=p,e[14]=n.ahead,e[15]=n.behind,e[16]=o,e[17]=O,e[18]=R,e[19]=V,e[20]=B):B=e[20];const ee=B;let Y;e[21]!==n.tracking||e[22]!==n.upstreamComparison?(Y=n.upstreamComparison?t.jsx(kv,{comparison:n.upstreamComparison,trackingBranch:n.tracking,tooltipDelayMs:1e3}):null,e[21]=n.tracking,e[22]=n.upstreamComparison,e[23]=Y):Y=e[23];const w=Y;let H;e[24]!==h||e[25]!==x||e[26]!==S||e[27]!==E?(H=t.jsx(vc,{activeProfile:h,identities:x,onSelect:E,isApplying:S,iconOnly:!0}),e[24]=h,e[25]=x,e[26]=S,e[27]=E,e[28]=H):H=e[28];const Q=H;let z;e[29]!==i||e[30]!==C||e[31]!==a||e[32]!==m||e[33]!==I||e[34]!==g||e[35]!==r||e[36]!==d||e[37]!==n.current?(z=t.jsx("div",{className:"min-w-0 flex-1",children:C?t.jsx(jv,{currentBranch:n.current,onRename:g}):t.jsx(yv,{currentBranch:n.current,localBranches:a,remoteBranches:r,branchInfo:i,onCheckout:m,onCreate:I,remotes:d})}),e[29]=i,e[30]=C,e[31]=a,e[32]=m,e[33]=I,e[34]=g,e[35]=r,e[36]=d,e[37]=n.current,e[38]=z):z=e[38];let L;e[39]!==Q||e[40]!==P?(L=t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[P,Q]}),e[39]=Q,e[40]=P,e[41]=L):L=e[41];let X;e[42]!==L||e[43]!==z?(X=t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[z,L]}),e[42]=L,e[43]=z,e[44]=X):X=e[44];let $;e[45]!==b||e[46]!==D||e[47]!==U||e[48]!==ee||e[49]!==w?($=b&&D&&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(jn,{items:b,activeId:D,onSelect:U,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),w?t.jsx("div",{className:"min-w-0 shrink",children:w}):null,t.jsx("div",{className:"shrink-0",children:ee})]}):null,e[45]=b,e[46]=D,e[47]=U,e[48]=ee,e[49]=w,e[50]=$):$=e[50];let ne;return e[51]!==X||e[52]!==$?(ne=t.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[X,$]}),e[51]=X,e[52]=$,e[53]=ne):ne=e[53],ne},Sv=s=>s==="/",za=s=>s.replace(/\\/g,"/"),ai=s=>{if(!s||Sv(s))return s;let e=s;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},Fn=s=>s.endsWith("/"),Cv=s=>{const e=s.trim();return!e||Fn(e)?e:`${e}/`},ri=s=>s.lastIndexOf("/"),jc=s=>{if(Fn(s))return s;const e=ri(s);return e<0?s:s.slice(0,e+1)},Pv=s=>{const e=ri(s);return s.slice(e+1)},wc=s=>{const e=ai(s.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=ri(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},Iv=s=>Fn(s)&&wc(s)!==null,Dv=(s,e)=>`${jc(s)}${e}/`,pn=s=>{if(!s)return null;const e=ai(za(s.trim()));return e?e.toLowerCase():null},xl=(s,e)=>{const n=s.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},Av=s=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey,Cr=s=>{if(!s)return;s.focus({preventScroll:!0});const e=s.value.length;s.setSelectionRange(e,e),s.scrollLeft=s.scrollWidth},Ev=async()=>{try{const s=await pt("/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 za(e.home.trim())}}catch{}return vs.getFilesystemHome().catch(()=>null)},nj=({open:s,onOpenChange:e})=>{const{t:n}=ot(),a=ys(y=>y.homeDirectory),r=os(y=>y.projects),i=os(y=>y.addProject),o=Cs(y=>y.profiles),d=Cs(y=>y.globalIdentity),c=Cs(y=>y.defaultGitIdentityId),f=Cs(y=>y.loadProfiles),u=Cs(y=>y.loadGlobalIdentity),p=Cs(y=>y.loadDefaultGitIdentityId),{isDesktop:m,requestAccess:I,startAccessing:g}=xv(),{isMobile:h}=Is(),x=l.useRef(null),E=l.useRef(null),S=l.useRef(new Map),[C,M]=l.useState(""),[k,v]=l.useState("~/"),[b,D]=l.useState([]),[U,T]=l.useState(!1),[F,j]=l.useState(!1),[P,O]=l.useState(0),[R,V]=l.useState(!1),[B,ee]=l.useState(!1),[Y,w]=l.useState(0),[H,Q]=l.useState(!1),[z,L]=l.useState(""),[X,$]=l.useState(null),[ne,re]=l.useState(!1),_=C||a,oe=l.useMemo(()=>new Set(r.map(y=>pn(y.path)).filter(y=>!!y)),[r]);l.useEffect(()=>{if(!s)return;v("~/"),D([]),O(0),V(!1),ee(!1),Q(!1),L(""),$(null),re(!1),requestAnimationFrame(()=>Cr(x.current));let y=!1;return(async()=>{const Ie=await Ev();y||(M(Ie||a||""),requestAnimationFrame(()=>Cr(x.current)))})(),()=>{y=!0}},[a,s]),l.useEffect(()=>{s&&(f(),u(),p())},[p,f,u,s]);const fe=l.useMemo(()=>{const y=new Map;d&&y.set(d.id,d);for(const ue of o)y.set(ue.id,ue);return Array.from(y.values())},[o,d]);l.useEffect(()=>{if(!s||!H||X!==null)return;const y=typeof c=="string"?c.trim():"";if(y&&fe.some(Ie=>Ie.id===y)){$(y);return}const ue=fe.find(Ie=>Ie.authType==="ssh"||Ie.sshKey);ue&&$(ue.id)},[fe,c,H,s,X]);const xe=l.useMemo(()=>fe.find(y=>y.id===X)??null,[fe,X]),Ce=l.useMemo(()=>jc(k),[k]),ve=l.useMemo(()=>Fn(k)?"":Pv(k),[k]),we=l.useMemo(()=>_?xl(Ce,_):"",[Ce,_]);l.useEffect(()=>{if(!s||!we){D([]);return}let y=!1;return T(!0),j(!1),vs.listLocalDirectory(we).then(ue=>{if(y)return;j(!1);const Ie=ue.filter(Oe=>Oe.isDirectory).map(Oe=>({name:Oe.name,path:za(Oe.path)})).sort((Oe,We)=>Oe.name.localeCompare(We.name));D(Ie)}).catch(()=>{y||(D([]),j(!0))}).finally(()=>{y||T(!1)}),()=>{y=!0}},[we,s]);const ye=l.useMemo(()=>{const y=ve.toLowerCase(),ue=ne||ve.startsWith(".");return b.filter(Ie=>Ie.name.toLowerCase().startsWith(y)&&(ue||!Ie.name.startsWith(".")))},[ve,b,ne]),se=l.useMemo(()=>{const y=[];Iv(k)&&y.push({type:"up",value:"browse:up",name:"..",path:wc(k)});for(const ue of ye){const Ie=pn(ue.path);y.push({type:"directory",value:`browse:${ue.path}`,name:ue.name,path:ue.path,disabled:!!(Ie&&oe.has(Ie))})}return y},[oe,ye,k]);l.useEffect(()=>{O(0)},[k,se.length]);const de=l.useMemo(()=>_?ai(xl(k,_)):"",[_,k]),be=pn(de),W=!!(be&&oe.has(be)),te=l.useMemo(()=>ve?ye.find(y=>y.name===ve)??null:null,[ve,ye]),ae=!!(de&&!W&&(Fn(k)&&F||!Fn(k)&&ve.trim().length>0&&te===null)),me=!R&&!B&&!W&&!!de,Me=me&&z.trim().length>0,Ne=se[P]??null,De=!!(Ne&&(Ne.type==="up"||Ne.type==="directory"&&!Ne.disabled)),Ae=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Pe=n(W?"directoryExplorerDialog.actions.alreadyAdded":H?R?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":R?"directoryExplorerDialog.actions.adding":ae?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const y=E.current;if(!y)return;const ue=()=>w(Math.ceil(y.getBoundingClientRect().width));if(ue(),typeof ResizeObserver>"u")return;const Ie=new ResizeObserver(ue);return Ie.observe(y),()=>Ie.disconnect()},[Pe]),l.useLayoutEffect(()=>{const y=x.current;y&&(y.scrollLeft=y.scrollWidth)},[Y,k]),l.useLayoutEffect(()=>{s&&Cr(x.current)},[s]),l.useLayoutEffect(()=>{const y=se[P];y&&S.current.get(y.value)?.scrollIntoView({block:"nearest"})},[P,se]);const Re=l.useCallback(()=>{e(!1)},[e]),Fe=l.useCallback((y,ue)=>{y.stopPropagation();const Ie=pn(ue);if(Ie&&oe.has(Ie))return;i(ue)||q.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")})},[i,oe,n]),Ue=l.useCallback(async y=>{if(!y||R)return;const ue=pn(y);if(ue&&oe.has(ue))return;let Ie=y;V(!0);try{const Oe=!H&&ae&&pn(y)===pn(de);if(H){const rt=z.trim();if(!rt){q.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ie=(await vs.cloneRepository({remoteUrl:rt,destinationPath:y,gitIdentityId:xe?.id??null})).path}else Oe&&await vs.createDirectory(y);if(!i(Ie)){q.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}Re()}catch(Oe){q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Oe instanceof Error?Oe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{V(!1)}},[i,oe,z,Re,H,R,xe?.id,ae,de,n]),_e=l.useCallback(y=>{v(Cv(y))},[]),Ke=l.useCallback(y=>{v(Dv(k,y.name))},[k]),qe=l.useCallback(y=>{if(y){if(y.type==="up"){y.path&&_e(y.path);return}y.disabled||Ke(y)}},[_e,Ke]),ce=l.useCallback(async()=>{if(!(!m||B)){ee(!0);try{const y=await I(de);if(!y.success||!y.path){y.error&&y.error!=="Directory selection cancelled"&&q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:y.error});return}const ue=await g(y.path);if(!ue.success){q.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:ue.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Ue(y.path)}catch(y){q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:y instanceof Error?y.message:n("directoryExplorerDialog.toast.unknownError")})}finally{ee(!1)}}},[Ue,m,B,I,g,n,de]),G=l.useCallback(y=>{if(y.key==="ArrowDown"){y.preventDefault(),O(ue=>Math.min(se.length-1,ue+1));return}if(y.key==="ArrowUp"){y.preventDefault(),O(ue=>Math.max(0,ue-1));return}if(y.key==="Enter"){if(y.preventDefault(),Av(y)){Ue(de);return}De&&qe(Ne);return}y.key==="Backspace"&&k===""&&(y.preventDefault(),Re())},[qe,Ue,Re,De,Ne,k,se.length,de]),pe=t.jsxs("button",{type:"button",onClick:()=>re(y=>!y),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:[ne?t.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}):t.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),je=t.jsxs("div",{className:"px-2.5 py-1.5",children:[H?t.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[t.jsx(tt,{value:z,onChange:y=>L(y.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(vc,{activeProfile:xe,identities:fe,onSelect:y=>$(y.id),isApplying:R,iconOnly:!0})]}):null,t.jsxs("div",{className:"relative",children:[t.jsx(A,{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(tt,{ref:x,value:k,onChange:y=>v(za(y.target.value)),onKeyDown:G,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!h&&Y>0?{paddingRight:`${Y+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),h?null:t.jsx(J,{ref:E,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:H?!Me:!me,onMouseDown:y=>y.preventDefault(),onClick:()=>{Ue(de)},title:Pe,children:Pe})]})]}),Ee=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")}):se.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:se.map((y,ue)=>{const Ie=ue===P;return t.jsxs("button",{ref:Oe=>{Oe?S.current.set(y.value,Oe):S.current.delete(y.value)},type:"button",disabled:y.type==="directory"&&y.disabled,onMouseEnter:()=>O(ue),onMouseDown:Oe=>Oe.preventDefault(),onClick:()=>qe(y),className:le("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",Ie&&"bg-interactive-selection text-interactive-selection-foreground",!Ie&&"hover:bg-interactive-hover/50",y.type==="directory"&&y.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[y.type==="up"?t.jsx(A,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):t.jsx(A,{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:y.name})}),y.type==="directory"&&y.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")}):y.type==="directory"?t.jsx("button",{type:"button",onMouseDown:Oe=>Oe.stopPropagation(),onClick:Oe=>Fe(Oe,y.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(A,{name:"add",className:"h-3.5 w-3.5"})}):null]},y.value)})})]})}),Se=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[je,Ee]}),Ve=t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(A,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),t.jsx(A,{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(A,{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:Ae}),t.jsx(A,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Z=()=>t.jsxs(t.Fragment,{children:[h?null:Ve,t.jsxs("div",{className:le("flex w-full flex-row justify-end gap-2 sm:w-auto",h&&"justify-stretch"),children:[m?t.jsx(J,{variant:"ghost",size:"xs",onClick:ce,disabled:R||B||H,children:n(B?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,t.jsx(J,{variant:"ghost",size:"xs",onClick:()=>Q(y=>!y),disabled:R||B,className:le(h&&"flex-1"),children:n(H?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),h?t.jsx(J,{size:"xs",onClick:()=>{Ue(de)},disabled:H?!Me:!me,className:"flex-1",children:Pe}):null]})]});return h?t.jsx(Zn,{open:s,onClose:Re,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:Z()}),children:t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[t.jsx("div",{className:"flex justify-end",children:pe}),Se]})}):t.jsx(Kt,{open:s,onOpenChange:e,children:t.jsxs(Ut,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(Bt,{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($t,{children:n("directoryExplorerDialog.title")}),t.jsx(Ht,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),pe]})}),t.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:Se}),t.jsx(Zt,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Z()})]})})};function bl(s){const{localBranches:e,remoteBranches:n,query:a}=s,r=a.trim();if(!r)return{matching:[],otherLocal:e,otherRemote:n};const i=Si(e,r,u=>u),o=Si(n,r,u=>u),d=[],c=i.other,f=o.other;for(const u of i.matching)d.push({label:u,value:u,source:"local"});for(const u of o.matching)d.push({label:u,value:`remotes/${u}`,source:"remote"});return d.sort((u,p)=>{const m=u.label.localeCompare(p.label,void 0,{sensitivity:"accent"});return m!==0?m:u.source!==p.source?u.source.localeCompare(p.source):u.value.localeCompare(p.value)}),{matching:d,otherLocal:c,otherRemote:f}}function Mv({open:s,onOpenChange:e,onSelect:n}){const{t:a}=ot(),r=Le(se=>se.isMobile),{github:i}=Xr(),o=_s(se=>se.status),d=_s(se=>se.hasChecked),c=Le(se=>se.setSettingsDialogOpen),f=Le(se=>se.setSettingsPage),u=os(se=>se.getActiveProject()),p=u?.path??null,m=ge.useMemo(()=>p&&u?{id:u.id,path:p}:null,[u,p]),[I,g]=ge.useState("issues"),[h,x]=ge.useState(""),[E,S]=ge.useState([]),[C,M]=ge.useState([]),[k,v]=ge.useState(!1),[b,D]=ge.useState(!1),[U,T]=ge.useState(null),[F,j]=ge.useState(null),[P,O]=ge.useState(null),[R,V]=ge.useState(!1),[B,ee]=ge.useState(new Map),[Y,w]=ge.useState(1),[H,Q]=ge.useState(!1),z=Lm(h,350),L=ge.useCallback(async se=>{if(!(!p||!i)&&!(d&&o?.connected===!1)){v(!0),T(null),w(1),Q(!1);try{if(I==="issues"&&i.issuesList){const de=await i.issuesList(p,{page:1,query:se});de.connected===!1?(T(a("session.githubIntegration.error.notConnected")),S([])):(S(de.issues??[]),w(de.page??1),Q(!!de.hasMore))}else if(I==="prs"&&i.prsList){const de=await i.prsList(p,{page:1,query:se});de.connected===!1?(T(a("session.githubIntegration.error.notConnected")),M([])):(M(de.prs??[]),w(de.page??1),Q(!!de.hasMore))}}catch(de){T(de instanceof Error?de.message:a("session.githubIntegration.error.loadDataFailed"))}finally{v(!1)}}},[p,i,d,o,I,a]);ge.useEffect(()=>{if(!s||!p||d&&o?.connected===!1||!i)return;if(!z.trim()){L();return}const se=new AbortController;v(!0),T(null),w(1),Q(!1);const de=I==="issues"&&i.issuesList?i.issuesList(p,{page:1,query:z.trim()}):I==="prs"&&i.prsList?i.prsList(p,{page:1,query:z.trim()}):null;if(!de){v(!1);return}return de.then(be=>{se.signal.aborted||("issues"in be?be.connected===!1?(T(a("session.githubIntegration.error.notConnected")),S([])):(S(be.issues??[]),w(be.page??1),Q(!!be.hasMore)):"prs"in be&&(be.connected===!1?(T(a("session.githubIntegration.error.notConnected")),M([])):(M(be.prs??[]),w(be.page??1),Q(!!be.hasMore))))}).catch(be=>{se.signal.aborted||T(be instanceof Error?be.message:a("session.githubIntegration.error.loadDataFailed"))}).finally(()=>{se.signal.aborted||v(!1)}),()=>se.abort()},[s,p,i,d,o,I,z,L,a]);const X=ge.useCallback(async()=>{if(!(!p||!i)&&!(k||b)&&H){D(!0);try{const se=Y+1;if(I==="issues"&&i.issuesList){const de=z.trim()?await i.issuesList(p,{page:se,query:z.trim()}):await i.issuesList(p,{page:se});de.connected!==!1&&(S(be=>[...be,...de.issues??[]]),w(de.page??se),Q(!!de.hasMore))}else if(I==="prs"&&i.prsList){const de=z.trim()?await i.prsList(p,{page:se,query:z.trim()}):await i.prsList(p,{page:se});de.connected!==!1&&(M(be=>[...be,...de.prs??[]]),w(de.page??se),Q(!!de.hasMore))}}catch{}finally{D(!1)}}},[p,i,I,Y,H,k,b,z]);ge.useEffect(()=>{if(!s){g("issues"),x(""),S([]),M([]),j(null),O(null),V(!1),T(null),ee(new Map),w(1),Q(!1);return}L()},[s,L]);const $=ge.useCallback(async se=>{if(!(!m||!se)&&!B.has(se))try{const be=(await Tl(m,{mode:"new",branchName:se,worktreeName:se})).errors.find(W=>W.code==="branch_in_use");ee(W=>new Map(W).set(se,{isValid:!be,error:be?a(be.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{ee(de=>new Map(de).set(se,{isValid:!1,error:a("session.githubIntegration.validation.failed")}))}},[m,B,a]);ge.useEffect(()=>{!s||I!=="prs"||C.forEach(se=>{se.head&&$(se.head)})},[s,I,C,$]);const ne=d&&o?.connected===!0,re=()=>{f("github"),c(!0)},_=se=>{j(se),O(null)},oe=se=>{O(se),j(null)},fe=()=>{F?n({type:"issue",item:F}):P&&n({type:"pr",item:P,includeDiff:R}),e(!1)},xe=()=>{j(null),O(null),V(!1)},Ce=F||P&&B.get(P.head??"")?.isValid!==!1,ve=se=>se.head?B.get(se.head)?.isValid===!1:!0,we=t.jsx(t.Fragment,{children:ne?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative mt-2",children:[t.jsx(A,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),t.jsx(tt,{value:h,onChange:se=>x(se.target.value),placeholder:a(I==="issues"?"session.githubIntegration.search.issuesPlaceholder":"session.githubIntegration.search.prsPlaceholder"),className:"h-8 pl-9"})]}),t.jsx("div",{className:"mt-2 h-[300px] overflow-hidden",children:t.jsxs("div",{className:"h-full overflow-y-auto",children:[k&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx(A,{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(A,{name:"error-warning",className:"h-4 w-4"}),t.jsx("span",{className:"typography-small",children:U})]})}),!k&&!U&&I==="issues"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[E.length>0?E.map(se=>t.jsx("button",{onClick:()=>_(se),className:le("w-full text-left px-2 py-1.5 rounded transition-colors",F?.number===se.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:["#",se.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-2",children:se.title}),se.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:[se.sourceRepo.owner,"/",se.sourceRepo.repo]}):null]})]})},`${se.sourceRepo?.owner??""}-${se.sourceRepo?.repo??""}-${se.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")}),H&&!b&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(J,{variant:"ghost",size:"sm",onClick:()=>{X()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),b&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!k&&!U&&I==="prs"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[C.length>0?C.map(se=>{const de=ve(se),be=se.head?B.get(se.head):void 0;return t.jsx("button",{onClick:()=>!de&&oe(se),disabled:de,className:le("w-full text-left px-2 py-1.5 rounded transition-colors",P?.number===se.number?"bg-interactive-selection text-interactive-selection-foreground":de?"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:["#",se.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-1",children:se.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[se.head," → ",se.base]}),se.sourceRepo?.source==="upstream"?t.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[se.sourceRepo.owner,"/",se.sourceRepo.repo]}):null,de&&be?.error&&t.jsx("span",{className:"typography-micro text-destructive",children:be.error})]})]})]})},`${se.sourceRepo?.owner??""}-${se.sourceRepo?.repo??""}-${se.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")}),H&&!b&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(J,{variant:"ghost",size:"sm",onClick:()=>{X()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),b&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(A,{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(A,{name:"github",className:"h-12 w-12 text-muted-foreground"}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:a("session.githubIntegration.connect.title")}),t.jsx("p",{className:"typography-small text-muted-foreground mt-1",children:a("session.githubIntegration.connect.description")})]}),t.jsx(J,{onClick:re,size:"sm",children:a("session.githubIntegration.connect.action")})]})}),ye=t.jsxs("div",{className:le("w-full",r?"flex flex-col gap-2":"flex flex-row items-center"),children:[t.jsxs("div",{className:le("flex items-center gap-4",r?"w-full justify-center order-1":"flex-1"),children:[!r&&(F||P)&&t.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[t.jsx(A,{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:F?a("session.githubIntegration.selected.issueNumber",{number:F.number}):a("session.githubIntegration.selected.prNumber",{number:P?.number??""})}),t.jsx("button",{onClick:xe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),I==="prs"&&P&&t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[t.jsx(St,{checked:R,onChange:se=>V(se),ariaLabel:a("session.githubIntegration.includeDiffAria")}),t.jsx("span",{className:"typography-small text-foreground",children:a("session.githubIntegration.includeDiff")})]})]}),t.jsxs("div",{className:le("flex gap-2",r?"w-full order-2":"justify-end"),children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>e(!1),className:le(r&&"flex-1"),children:a("session.githubIntegration.actions.cancel")}),t.jsx(J,{size:"sm",onClick:fe,disabled:!Ce,className:le(r&&"flex-1"),children:a("session.githubIntegration.actions.select")})]})]});return t.jsx(t.Fragment,{children:r?t.jsx(Zn,{open:s,title:a("session.githubIntegration.title"),onClose:()=>e(!1),footer:ne?ye:void 0,renderHeader:se=>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")}),se]}),t.jsx("div",{className:"w-full",children:t.jsx(jn,{items:[{id:"issues",label:a("session.githubIntegration.tabs.issues"),icon:t.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:a("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:I,onSelect:de=>{g(de),x("")},variant:"active-pill",layoutMode:"fit"})}),(F||P)&&t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[t.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),t.jsx("span",{className:"typography-small truncate flex-1",children:F?a("session.githubIntegration.selected.issueNumber",{number:F.number}):a("session.githubIntegration.selected.prNumber",{number:P?.number??""})}),t.jsx("button",{onClick:xe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:we}):t.jsx(Kt,{open:s,onOpenChange:e,children:t.jsxs(Ut,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsx(Bt,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs($t,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(A,{name:"github",className:"h-5 w-5"}),a("session.githubIntegration.title")]}),t.jsx("div",{className:"w-[220px]",children:t.jsx(jn,{items:[{id:"issues",label:a("session.githubIntegration.tabs.issues"),icon:t.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:a("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:I,onSelect:se=>{g(se),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),we,t.jsx(Zt,{className:"mt-1",children:ye})]})})})}const Xn=s=>s.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),bs=s=>s.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,"").split("/").join("-").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"").slice(0,80),yl="oc:lastWorktreeSourceBranch",Rv=s=>String(s).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",vl=(s,e,n)=>{const a=Xn(s.head||"");if(!a)throw new Error("PR head branch is missing");if(e.includes(a))return{existingBranch:a,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:a};const r=n.find(f=>{const u=f.indexOf("/");return u<=0||u>=f.length-1?!1:f.slice(u+1)===a});if(r){const f=r.indexOf("/"),u=r.slice(0,f);return{existingBranch:`remotes/${r}`,setUpstream:!0,upstreamRemote:u,upstreamBranch:a,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${u}/${a}`}}const i=String(s.headLabel||"").split(":")[0]?.trim(),o=s.headRepo?.owner||i||"pr-head",d=`pr-${Rv(o)}`,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}`}},Tv=s=>{const e={repo:s.repo??null,issue:s.issue,comments:s.comments};return`GitHub issue context (JSON)
|
|
166
|
-
${JSON.stringify(e,null,2)}`},Fv=s=>`GitHub pull request context (JSON)
|
|
167
|
-
${JSON.stringify(s,null,2)}`;function aj({open:s,onOpenChange:e,onWorktreeCreated:n}){const{t:a}=ot(),{github:r,git:i}=Xr(),o=Le(Z=>Z.isMobile),d=_s(Z=>Z.status),c=_s(Z=>Z.hasChecked),f=os(Z=>Z.getActiveProject()),u=f?.path??null,p=ge.useMemo(()=>u&&f?{id:f.id,path:u}:null,[f,u]),[m,I]=ge.useState("new-branch"),[g,h]=ge.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,E]=ge.useState({selectedBranch:"",worktreeName:""}),S=Om(u),C=zm(u),M=Km(Z=>Z.fetchBranches),k=ge.useMemo(()=>S?.all?S.all.filter(Z=>!Z.startsWith("remotes/")).sort():[],[S]),v=ge.useMemo(()=>S?.all?S.all.filter(Z=>Z.startsWith("remotes/")).map(Z=>Z.replace(/^remotes\//,"")).sort():[],[S]),b=ks(Z=>Z.availableWorktreesByProject),D=ge.useMemo(()=>{if(!u)return new Set;const Z=b.get(u)??[];return new Set(Z.map(y=>y.name))},[b,u]),U=ge.useCallback((Z=10)=>{for(let y=0;y<Z;y++){const ue=Za();if(!D.has(ue))return ue}return`${Za()}-${Date.now().toString(36).slice(-4)}`},[D]),[T,F]=ge.useState(!1),[j,P]=ge.useState(!1),[O,R]=ge.useState(!1),[V,B]=ge.useState(!1),[ee,Y]=ge.useState(!1),[w,H]=ge.useState(""),[Q,z]=ge.useState(""),L=ge.useRef(null),X=ge.useRef(null),$=ge.useRef(null),ne=ge.useRef(null),re=ge.useCallback(Z=>{Z.stopPropagation()},[]),_=ge.useCallback(Z=>{let y=Z;for(;y&&y!==document.body;){const{overflowY:ue}=window.getComputedStyle(y);if((ue==="auto"||ue==="scroll")&&y.scrollHeight>y.clientHeight)return y;y=y.parentElement}return null},[]),oe=ge.useCallback(Z=>{Z&&(Z.scrollTop=0)},[]),fe=ge.useCallback(Z=>{const y=Z.current?.querySelector('[data-slot="command-list"]')??null;oe(y)},[oe]),xe=ge.useCallback(Z=>{const y=_(Z.current);oe(y)},[_,oe]),Ce=ge.useMemo(()=>bl({localBranches:k,remoteBranches:v,query:w}),[k,v,w]),ve=ge.useMemo(()=>bl({localBranches:k,remoteBranches:v,query:Q}),[k,v,Q]),we=w.trim().length>0,ye=Q.trim().length>0,se=Ce.matching.length>0,de=ve.matching.length>0,be=!!(u&&i),W=ge.useCallback(()=>{!u||!i||M(u,i)},[u,i,M]);ge.useEffect(()=>{!s||!u||!i||S?.all||M(u,i)},[s,u,i,S?.all,M]),ge.useEffect(()=>{!j&&!V&&H("")},[j,V]),ge.useEffect(()=>{!O&&!ee&&z("")},[O,ee]),ge.useEffect(()=>{j&&fe(L),V&&xe($)},[j,V,w,fe,xe]),ge.useEffect(()=>{O&&fe(X),ee&&xe(ne)},[O,ee,Q,fe,xe]);const[te,ae]=ge.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[me,Me]=ge.useState(!1),[Ne,De]=ge.useState(null),Ae=ge.useCallback(()=>{const Z=lt.getState(),y=Z.getVisibleAgents();if(Z.settingsDefaultAgent){const ue=y.find(Ie=>Ie.name===Z.settingsDefaultAgent);if(ue)return ue.name}return y.find(ue=>ue.name==="build")?.name||y[0]?.name},[]),Pe=ge.useCallback(()=>{const Z=lt.getState(),y=Z.settingsDefaultModel;if(!y)return null;const ue=xn(y);if(!ue)return null;const{providerId:Ie,modelId:Oe}=ue;return Z.getModelMetadata(Ie,Oe)?{providerID:Ie,modelID:Oe}:null},[]),Re=ge.useCallback((Z,y)=>{const ue=lt.getState(),Ie=ue.settingsDefaultVariant,Oe=ue.currentProviderId===Z&&ue.currentModelId===y?ue.currentVariant:void 0,it=ue.providers.find(nt=>nt.id===Z)?.models.find(nt=>nt.id===y)?.variants;if(!it)return Ie||Oe||void 0;if(Ie&&Object.prototype.hasOwnProperty.call(it,Ie))return Ie;if(Oe&&Object.prototype.hasOwnProperty.call(it,Oe))return Oe},[]),Fe=ge.useCallback(async Z=>{if(!u||!r)return;const y=lt.getState(),ue=Um.getState().lastUsedProvider,Ie=Pe(),Oe=Ie?.providerID||y.currentProviderId||ue?.providerID,We=Ie?.modelID||y.currentModelId||ue?.modelID,rt=Ae()||y.currentAgentName||void 0;if(!Oe||!We){q.error(a("session.newWorktree.error.noModelSelected"));return}const it=Re(Oe,We);if(Z.issue){if(!r.issueGet||!r.issueComments)return;const nt=await r.issueGet(u,Z.issue.number);if(nt.connected===!1||!nt.repo||!nt.issue)throw new Error("Failed to load issue context");const dt=await r.issueComments(u,Z.issue.number);if(dt.connected===!1)throw new Error("Failed to load issue comments");const Ye=await oa("github.issue.review.visible",{issue_number:String(Z.issue.number)}),$e=await oa("github.issue.review.instructions"),mt=Tv({repo:nt.repo,issue:nt.issue,comments:dt.comments??[]});await ks.getState().sendMessage(Ye,Oe,We,rt,void 0,void 0,[{text:$e,synthetic:!0},{text:mt,synthetic:!0}],it,void 0,{sessionId:Z.sessionId}),q.success(a("session.newWorktree.toast.sessionFromIssue"));return}if(Z.pr){if(!r.prContext)return;const nt=await r.prContext(u,Z.pr.number,{includeDiff:Z.includeDiff,includeCheckDetails:!1});if(nt.connected===!1||!nt.repo||!nt.pr)throw new Error("Failed to load PR context");const dt=await oa("github.pr.review.visible",{pr_number:String(Z.pr.number)}),Ye=await oa("github.pr.review.instructions"),$e=Fv(nt);await ks.getState().sendMessage(dt,Oe,We,rt,void 0,void 0,[{text:Ye,synthetic:!0},{text:$e,synthetic:!0}],it,void 0,{sessionId:Z.sessionId}),q.success(a("session.newWorktree.toast.sessionFromPr"))}},[r,u,Ae,Pe,Re,a]),Ue=m==="new-branch"?g:x;ge.useEffect(()=>{if(!S?.all||!u||g.sourceBranch)return;(async()=>{try{const y=await $m(u).catch(()=>null),ue=localStorage.getItem(yl),Ie=ue&&S.all?.includes(ue)?ue:y&&S.all?.includes(y)?y:S.all?.includes("main")?"main":S.all?.includes("master")?"master":S.all?.[0]||"";Ie&&h(Oe=>({...Oe,sourceBranch:Ie}))}catch{}})()},[S,u,g.sourceBranch]),ge.useEffect(()=>{if(!s)return;I("new-branch"),E({selectedBranch:"",worktreeName:""}),P(!1),R(!1),B(!1),Y(!1),H(""),z(""),ae({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const Z=U();h({branchName:Z,worktreeName:Z,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[s,U]),ge.useEffect(()=>{if(m!=="new-branch"||!g.isSyncingWorktreeName)return;const Z=Xn(g.branchName),y=bs(Z);h(ue=>({...ue,worktreeName:y}))},[m,g.branchName,g.isSyncingWorktreeName]);const _e=ge.useCallback(async()=>{if(!p||!te.touched||me)return;Ne&&Ne.abort();const Z=new AbortController;De(Z),ae(y=>({...y,isValidating:!0}));try{const y=m==="new-branch"?g.branchName:x.selectedBranch,ue=Ue.worktreeName,Ie=Xn(y),Oe=bs(ue);let We=null,rt=null;if(Ie||(We=a("session.newWorktree.error.branchNameRequired")),Oe||(rt=a("session.newWorktree.error.worktreeDirectoryRequired")),Ie&&Oe){const it=m==="new-branch"?g.linkedPr:null,nt=it?vl(it,k,v):null,dt=await Tl(p,{mode:m==="existing-branch"||nt?"existing":"new",branchName:Ie,worktreeName:Oe,existingBranch:nt?.existingBranch??(m==="existing-branch"?Ie:void 0),...nt?.ensureRemoteName?{ensureRemoteName:nt.ensureRemoteName}:{},...nt?.ensureRemoteUrl?{ensureRemoteUrl:nt.ensureRemoteUrl}:{}});if(Z.signal.aborted)return;dt.ok||dt.errors.forEach(Ye=>{if(Ye.code==="worktree_exists"){rt=rt??Ye.message;return}Ye.code.startsWith("branch_")&&(We=We??Ye.message)})}Z.signal.aborted||ae(it=>({...it,isValidating:!1,branchError:We,worktreeError:rt}))}catch{Z.signal.aborted||ae(y=>({...y,isValidating:!1}))}},[p,m,g.branchName,g.linkedPr,x.selectedBranch,Ue.worktreeName,k,v,te.touched,Ne,me,a]),Ke=m==="new-branch"?g.branchName:x.selectedBranch;ge.useEffect(()=>{if(!s||!p||!te.touched||me)return;const Z=setTimeout(()=>{_e()},300);return()=>clearTimeout(Z)},[Ue.worktreeName,Ke,s,p,_e,te.touched,me]);const qe=async()=>{if(!p||!u){q.error(a("session.newWorktree.error.noActiveProject"));return}ae(Oe=>({...Oe,touched:!0}));const Z=m==="new-branch"?g.branchName:x.selectedBranch,y=Ue.worktreeName,ue=Xn(Z),Ie=bs(y);if(!ue){q.error(a("session.newWorktree.error.branchNameRequired"));return}if(!Ie){q.error(a("session.newWorktree.error.worktreeDirectoryRequired"));return}Ne&&(Ne.abort(),De(null)),ae(Oe=>({...Oe,isValidating:!1,branchError:null,worktreeError:null})),Me(!0);try{const Oe=m==="new-branch"?g.linkedPr:null,We=m==="new-branch"?g.linkedIssue:null,rt=m==="new-branch"?g.linkedPr:null,it=m==="new-branch"?g.includePrDiff:!1,nt=!!(We||rt),dt=await Al(p),Ye=g.sourceBranch;let $e="";const mt=(()=>{if(Oe){const He=vl(Oe,k,v);return $e=He.sourceLabel,{preferredName:ue||Ie,mode:"existing",branchName:ue,worktreeName:Ie,existingBranch:He.existingBranch,setupCommands:dt,setUpstream:He.setUpstream,upstreamRemote:He.upstreamRemote,upstreamBranch:He.upstreamBranch,returnAfterDirectoryCreated:!0,...He.ensureRemoteName?{ensureRemoteName:He.ensureRemoteName}:{},...He.ensureRemoteUrl?{ensureRemoteUrl:He.ensureRemoteUrl}:{}}}return $e=m==="new-branch"?Ye:"",{preferredName:ue||Ie,mode:m==="existing-branch"?"existing":"new",branchName:m==="existing-branch"?void 0:ue,worktreeName:Ie,existingBranch:m==="existing-branch"?ue:void 0,setupCommands:dt,returnAfterDirectoryCreated:!0,...Ye&&m==="new-branch"?{startRef:Ye}:{}}})(),he=await Bm(u,mt),et=await Vm(p,he);let Xe=null;if(nt){await El(p)&&await _m(et.path);const He=We?`#${We.number} ${We.title}`.trim():rt?`#${rt.number} ${rt.title}`.trim():a("session.newWorktree.newSessionTitle"),bt=await Hm(He,et.path,null);if(!bt?.id)throw new Error("Failed to create session");Xe=bt.id,n?.(et.path,{sessionId:Xe}),e(!1),Me(!1),Wm(bt.id,He).catch(()=>{});try{ks.getState().initializeNewOpenChamberSession(bt.id,lt.getState().agents)}catch{}}else e(!1),Me(!1);g.sourceBranch&&m==="new-branch"&&!g.linkedPr&&localStorage.setItem(yl,g.sourceBranch),q.success(a("session.newWorktree.toast.worktreeCreated"),{description:a("session.newWorktree.toast.worktreeCreatedDescription",{target:`${et.branch||et.name}${$e?` ${a("session.newWorktree.fromSource",{source:$e})}`:""}`})}),Xe?Fe({sessionId:Xe,directory:et.path,issue:We,pr:rt,includeDiff:it}).catch(He=>{const bt=He instanceof Error?He.message:a("session.newWorktree.error.sendGitHubContextFailed");q.error(a("session.newWorktree.error.sendGitHubContextFailed"),{description:bt})}):n?.(et.path)}catch(Oe){const We=Oe instanceof Error?Oe.message:a("session.newWorktree.error.createWorktreeFailed");q.error(a("session.newWorktree.error.createWorktreeFailed"),{description:We})}finally{Me(!1)}},ce=Z=>{I(Z),ae(y=>({...y,touched:!1,branchError:null,worktreeError:null}))},G=Z=>{if(!Z){h(y=>({...y,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(Z.type==="issue"){const y=Z.item,ue=`issue-${y.number}-${Za()}`;h(Ie=>({...Ie,linkedIssue:y,linkedPr:null,includePrDiff:!1,branchName:ue,worktreeName:bs(ue),isSyncingWorktreeName:!0}))}else if(Z.type==="pr"){const y=Z.item;h(ue=>({...ue,linkedPr:y,linkedIssue:null,includePrDiff:Z.includeDiff??!1,branchName:y.head,worktreeName:bs(y.head),isSyncingWorktreeName:!0}))}},pe=c&&d?.connected===!0,Ee=(m==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!te.branchError&&!te.worktreeError:!!Xn(g.branchName)&&!!g.worktreeName&&!te.branchError&&!te.worktreeError)&&!me,Se=()=>{h(Z=>({...Z,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Ve=t.jsxs("div",{className:le("flex gap-2",o?"flex-col w-full":"flex-row items-center"),children:[t.jsx("div",{className:le("flex items-center gap-1.5 text-destructive",o?"w-full justify-center order-first":"mr-auto"),children:te.touched&&(te.branchError||te.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:te.branchError||te.worktreeError})]})}),t.jsxs("div",{className:le("flex gap-2",o&&"w-full"),children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:me,className:le(o&&"flex-1"),children:a("session.newWorktree.actions.cancel")}),t.jsxs(J,{size:"sm",onClick:qe,disabled:!Ee||me,className:le("gap-1.5",o&&"flex-1"),children:[me&&t.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(me?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return t.jsxs(t.Fragment,{children:[o?t.jsxs(Zn,{open:s,title:a("session.newWorktree.title"),onClose:()=>e(!1),footer:Ve,children:[t.jsx("div",{className:"w-full mb-4",children:t.jsx(jn,{items:[{id:"new-branch",label:a("session.newWorktree.mode.newBranch"),icon:t.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:a("session.newWorktree.mode.existingBranch"),icon:t.jsx(A,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:m,onSelect:Z=>ce(Z),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),t.jsxs("div",{className:"space-y-6",children:[m==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>B(!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(A,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),t.jsx(J,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:W,disabled:!be||C,title:a("session.newWorktree.fetchBranches"),children:C?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"refresh",className:"size-4"})})]}),t.jsx(Zn,{open:V,title:a("session.newWorktree.selectBranch"),onClose:()=>B(!1),children:t.jsxs("div",{className:"space-y-4",ref:$,children:[t.jsx(tt,{value:w,onChange:Z=>H(Z.target.value),placeholder:a("session.newWorktree.searchBranches"),className:"h-8"}),C?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):k.length===0&&v.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[we&&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:Ce.matching.map(Z=>t.jsx("button",{onClick:()=>{E(y=>({...y,selectedBranch:Z.value,worktreeName:bs(Z.label)})),ae(y=>({...y,touched:!0})),B(!1)},className:le("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===Z.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:Z.label})},`${Z.source}-${Z.value}`))})]}),we&&!se&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),Ce.otherLocal.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(we?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:Ce.otherLocal.map(Z=>t.jsx("button",{onClick:()=>{E(y=>({...y,selectedBranch:Z,worktreeName:bs(Z)})),ae(y=>({...y,touched:!0})),B(!1)},className:le("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===Z?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:Z})},Z))})]}),Ce.otherRemote.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(we?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:Ce.otherRemote.map(Z=>t.jsx("button",{onClick:()=>{E(y=>({...y,selectedBranch:`remotes/${Z}`,worktreeName:bs(Z)})),ae(y=>({...y,touched:!0})),B(!1)},className:le("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${Z}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:Z})},`remotes/${Z}`))})]})]})]})})]}):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")}),m==="new-branch"&&pe&&t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>F(!0),className:"gap-1.5 h-7",children:[t.jsx(A,{name:"github",className:"size-4 text-status-success"}),g.linkedIssue||g.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(tt,{value:g.branchName,onChange:Z=>{h(y=>({...y,branchName:Z.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ae(Z=>({...Z,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:le("h-8",te.touched&&te.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(A,{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(A,{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")}),m!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const Z=bs(m==="new-branch"?g.branchName:"");h(y=>({...y,worktreeName:Z,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===bs(g.branchName),className:le("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===bs(g.branchName)||!g.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:a("session.newWorktree.resetToMatchBranchName"),children:[t.jsx(A,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:a("session.newWorktree.actions.reset")})]})]}),t.jsx(tt,{value:Ue.worktreeName,onChange:Z=>{m==="new-branch"?h(y=>({...y,worktreeName:Z.target.value,isSyncingWorktreeName:!1})):E(y=>({...y,worktreeName:Z.target.value}))},onBlur:()=>ae(Z=>({...Z,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:le("h-8",te.touched&&te.worktreeError&&"border-destructive")})]}),m==="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(J,{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(A,{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(Zn,{open:ee,title:a("session.newWorktree.selectSourceBranch"),onClose:()=>Y(!1),children:t.jsxs("div",{className:"space-y-4",ref:ne,children:[t.jsx(tt,{value:Q,onChange:Z=>z(Z.target.value),placeholder:a("session.newWorktree.searchBranches"),className:"h-8"}),C?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):k.length===0&&v.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[ye&&de&&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:ve.matching.map(Z=>t.jsx("button",{onClick:()=>{h(y=>({...y,sourceBranch:Z.value})),Y(!1)},className:le("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===Z.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:Z.label})},`${Z.source}-${Z.value}`))})]}),ye&&!de&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),ve.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(ye?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:ve.otherLocal.map(Z=>t.jsx("button",{onClick:()=>{h(y=>({...y,sourceBranch:Z})),Y(!1)},className:le("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===Z?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:Z})},Z))})]}),ve.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(ye?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:ve.otherRemote.map(Z=>t.jsx("button",{onClick:()=>{h(y=>({...y,sourceBranch:`remotes/${Z}`})),Y(!1)},className:le("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===`remotes/${Z}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:Z})},`remotes/${Z}`))})]})]})]})})]}),(g.linkedIssue||g.linkedPr)&&m==="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(A,{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:Z=>Z.stopPropagation(),children:t.jsx(A,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:Se,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(A,{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(Kt,{open:s,onOpenChange:e,children:t.jsxs(Ut,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[t.jsx(Bt,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs($t,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(A,{name:"git-branch",className:"h-5 w-5"}),a("session.newWorktree.title")]}),t.jsx("div",{className:"w-[280px] shrink-0",children:t.jsx(jn,{items:[{id:"new-branch",label:a("session.newWorktree.mode.newBranch"),icon:t.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:a("session.newWorktree.mode.existingBranch"),icon:t.jsx(A,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:m,onSelect:Z=>ce(Z),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),t.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[m==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(gs,{open:j,onOpenChange:P,children:[t.jsx(us,{asChild:!0,children:t.jsxs(J,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[t.jsx("span",{className:le("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||a("session.newWorktree.chooseBranch")}),t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(ps,{align:"start",sideOffset:6,portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:L,children:t.jsxs(Er,{shouldFilter:!1,children:[t.jsx(Mr,{placeholder:a("session.newWorktree.searchBranches"),value:w,onValueChange:H,onKeyDown:re}),t.jsx(Rr,{disableHorizontal:!0,children:C?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):k.length===0&&v.length===0?t.jsx(Tr,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[we&&se&&t.jsx(Bs,{heading:a("session.newWorktree.matchingBranches"),children:Ce.matching.map(Z=>t.jsx(Ms,{value:Z.value,onSelect:()=>{E(y=>({...y,selectedBranch:Z.value,worktreeName:bs(Z.label)})),ae(y=>({...y,touched:!0})),P(!1)},children:t.jsx("span",{className:"typography-small break-all",children:Z.label})},`${Z.source}-${Z.value}`))}),we&&!se&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),Ce.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[we&&t.jsx(An,{}),t.jsx(Bs,{heading:a(we?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:Ce.otherLocal.map(Z=>t.jsx(Ms,{value:Z,onSelect:()=>{E(y=>({...y,selectedBranch:Z,worktreeName:bs(Z)})),ae(y=>({...y,touched:!0})),P(!1)},children:t.jsx("span",{className:"typography-small break-all",children:Z})},`local-${Z}`))})]}),Ce.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(Ce.otherLocal.length>0||we)&&t.jsx(An,{}),t.jsx(Bs,{heading:a(we?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:Ce.otherRemote.map(Z=>t.jsx(Ms,{value:`remotes/${Z}`,onSelect:()=>{E(y=>({...y,selectedBranch:`remotes/${Z}`,worktreeName:bs(Z)})),ae(y=>({...y,touched:!0})),P(!1)},children:t.jsx("span",{className:"typography-small break-all",children:Z})},`remote-${Z}`))})]})]})})]})})]}),t.jsx(J,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:W,disabled:!be||C,title:a("session.newWorktree.fetchBranches"),children:C?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{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")}),m==="new-branch"&&pe&&t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>F(!0),className:"gap-1.5 h-7",children:[t.jsx(A,{name:"github",className:"size-4 text-status-success"}),g.linkedIssue||g.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(tt,{value:g.branchName,onChange:Z=>{h(y=>({...y,branchName:Z.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ae(Z=>({...Z,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:le("h-8",te.touched&&te.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(A,{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(A,{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")}),m!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const Z=bs(m==="new-branch"?g.branchName:"");h(y=>({...y,worktreeName:Z,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===bs(g.branchName),className:le("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===bs(g.branchName)||!g.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:a("session.newWorktree.resetToMatchBranchName"),children:[t.jsx(A,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:a("session.newWorktree.actions.reset")})]})]}),t.jsx(tt,{value:Ue.worktreeName,onChange:Z=>{m==="new-branch"?h(y=>({...y,worktreeName:Z.target.value,isSyncingWorktreeName:!1})):E(y=>({...y,worktreeName:Z.target.value}))},onBlur:()=>ae(Z=>({...Z,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:le("h-8",te.touched&&te.worktreeError&&"border-destructive")})]}),m==="new-branch"&&!g.linkedPr&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.sourceBranch")}),t.jsxs(gs,{open:O,onOpenChange:R,children:[t.jsx(us,{asChild:!0,children:t.jsxs(J,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[t.jsx("span",{className:le("truncate",g.sourceBranch?"text-foreground":"text-muted-foreground"),children:g.sourceBranch||a("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(ps,{align:"start",portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:X,children:t.jsxs(Er,{shouldFilter:!1,children:[t.jsx(Mr,{placeholder:a("session.newWorktree.searchBranches"),value:Q,onValueChange:z,onKeyDown:re}),t.jsx(Rr,{disableHorizontal:!0,children:C?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):k.length===0&&v.length===0?t.jsx(Tr,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[ye&&de&&t.jsx(Bs,{heading:a("session.newWorktree.matchingBranches"),children:ve.matching.map(Z=>t.jsx(Ms,{value:Z.value,onSelect:()=>{h(y=>({...y,sourceBranch:Z.value})),R(!1)},children:t.jsx("span",{className:"typography-small break-all",children:Z.label})},`${Z.source}-${Z.value}`))}),ye&&!de&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),ve.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[ye&&t.jsx(An,{}),t.jsx(Bs,{heading:a(ye?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ve.otherLocal.map(Z=>t.jsx(Ms,{value:Z,onSelect:()=>{h(y=>({...y,sourceBranch:Z})),R(!1)},children:t.jsx("span",{className:"typography-small break-all",children:Z})},`local-${Z}`))})]}),ve.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(ve.otherLocal.length>0||ye)&&t.jsx(An,{}),t.jsx(Bs,{heading:a(ye?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ve.otherRemote.map(Z=>t.jsx(Ms,{value:`remotes/${Z}`,onSelect:()=>{h(y=>({...y,sourceBranch:`remotes/${Z}`})),R(!1)},children:t.jsx("span",{className:"typography-small break-all",children:Z})},`remote-${Z}`))})]})]})})]})})]}),g.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:a("session.newWorktree.newBranchFromSource",{source:g.sourceBranch})})]}),(g.linkedIssue||g.linkedPr)&&m==="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(A,{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:Z=>Z.stopPropagation(),children:t.jsx(A,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:Se,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(A,{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(Zt,{className:"mt-1 flex items-center justify-between",children:[t.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:te.touched&&(te.branchError||te.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:te.branchError||te.worktreeError})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:me,children:a("session.newWorktree.actions.cancel")}),t.jsxs(J,{size:"sm",onClick:qe,disabled:!Ee||me,className:"gap-1.5",children:[me&&t.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(me?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),t.jsx(Mv,{open:T,onOpenChange:F,onSelect:G})]})}const rj=s=>{ks.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),Le.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),s.previousRuntimeKey&&qm.getState().stopRunningRunsForRuntime(s.previousRuntimeKey),uu(),vs.reconnectToRuntimeBaseUrl(),lt.setState({providers:[],agents:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),os.getState().resetForRuntimeSwitch(),Dr.getState().resetForRuntimeSwitch(),ks.getState().restoreForRuntimeSwitch(s.runtimeKey),Le.getState().restoreForRuntimeSwitch(s.runtimeKey),Gm()};export{Oh as $,Kl as A,yn as B,Zv as C,nj as D,vn as E,Jv as F,$f as G,Bf as H,ml as I,Hi as J,Cs as K,sj as L,$v as M,aj as N,Vv as O,tj as P,on as Q,an as R,zy as S,Wv as T,px as U,qs as V,nn as W,sn as X,Gy as Y,ul as Z,Po as _,ej as a,Co as a0,oh as a1,pc as a2,hc as a3,zx as a4,Bv as a5,_p as a6,Vl as a7,Bp as a8,Qv as a9,av as b,Yv as c,_v as d,zl as e,Ln as f,cs as g,Gb as h,Vt as i,Wf as j,zo as k,yu as l,Hv as m,Uv as n,Ky as o,ms as p,Zh as q,rj as r,Xh as s,qv as t,Xv as u,Gv as v,Yh as w,jn as x,gx as y,bn as z};
|