import{a5 as P,a6 as M,f as D,H as E,O as $,a7 as j,J as F,i as h,L as K,m as u,v as O,l as c,S as v,n as b,G as q,t as m}from"./index-Cl9Gy4vs.js";import{L as B}from"./list-CbLd2QpP.js";import{S as G}from"./switch-DnfWoh_i.js";var H=m('<span class="text-11-regular text-text-weaker">'),J=m('<span class="text-11-regular text-text-weak">'),T=m('<span class="text-11-regular text-text-weaker truncate">'),z=m('<div class="w-full flex items-center justify-between gap-x-3"><div class="flex flex-col gap-0.5 min-w-0"><div class="flex items-center gap-2"><span class=truncate></span></div></div><div>');const A={connected:"mcp.status.connected",failed:"mcp.status.failed",needs_auth:"mcp.status.needs_auth",disabled:"mcp.status.disabled"},R=()=>{const s=P(),d=M(),l=D(),[_,o]=E({done:!1,loading:!1});$(j(()=>s.data.mcp_ready,(e,t)=>{!e&&t&&o("done",!1)},{defer:!0})),$(()=>{if(!(_.done||_.loading)){if(s.data.mcp_ready){o("done",!0);return}o("loading",!0),d.client.mcp.status().then(e=>{s.set("mcp",e.data??{}),s.set("mcp_ready",!0),o("done",!0)}).catch(e=>{o("done",!0),F({variant:"error",title:l.t("common.requestFailed"),description:e instanceof Error?e.message:String(e)})}).finally(()=>{o("loading",!1)})}});const p=h(()=>Object.entries(s.data.mcp??{}).map(([e,t])=>({name:e,status:t.status})).sort((e,t)=>e.name.localeCompare(t.name))),n=K(()=>({mutationFn:async e=>{s.data.mcp[e]?.status==="connected"?await d.client.mcp.disconnect({name:e}):await d.client.mcp.connect({name:e});const i=await d.client.mcp.status();i.data&&s.set("mcp",i.data)}})),S=h(()=>p().filter(e=>e.status==="connected").length),k=h(()=>p().length);return u(q,{get title(){return l.t("dialog.mcp.title")},get description(){return l.t("dialog.mcp.description",{enabled:S(),total:k()})},get children(){return u(B,{get search(){return{placeholder:l.t("common.search.placeholder"),autofocus:!0}},get emptyMessage(){return l.t("dialog.mcp.empty")},key:e=>e?.name??"",items:p,filterKeys:["name","status"],sortBy:(e,t)=>e.name.localeCompare(t.name),onSelect:e=>{!e||n.isPending||n.mutate(e.name)},children:e=>{const t=()=>s.data.mcp[e.name],i=()=>t()?.status,w=()=>{const r=i()?A[i()]:void 0;if(r)return l.t(r)},x=()=>{const r=t();return r?.status==="failed"?r.error:void 0},C=()=>i()==="connected";return(()=>{var r=z(),g=r.firstChild,f=g.firstChild,L=f.firstChild,y=g.nextSibling;return c(L,()=>e.name),c(f,u(v,{get when(){return w()},get children(){var a=H();return c(a,w),a}}),null),c(f,u(v,{get when(){return b(()=>!!n.isPending)()&&n.variables===e.name},get children(){var a=J();return c(a,()=>l.t("common.loading.ellipsis")),a}}),null),c(g,u(v,{get when(){return x()},get children(){var a=T();return c(a,x),a}}),null),y.$$click=a=>a.stopPropagation(),c(y,u(G,{get checked(){return C()},get disabled(){return b(()=>!!n.isPending)()&&n.variables===e.name},onChange:()=>{n.isPending||n.mutate(e.name)}})),r})()}})}})};O(["click"]);export{R as DialogSelectMcp};
