import{u as E,a as S,e as L,j as t,aK as j,r as f,aL as b,c as N,aM as P}from"./index-_B-Zy6Ft.js";import{i as x}from"./Loading01-CI_v2_GN.js";import{c as I}from"./binder-BU8oZbeE.js";import{u as H,L as w}from"./localstorage-keys-MeV98x1G.js";import{b as k}from"./use-connection-CfqFbPzC.js";import{u as z}from"./constants-C8myDR0I.js";import"./useQuery-CC8ASXOP.js";import"./useMutation-EHy22ute.js";import"./use-collections-DGoeBGCb.js";function B(e,r){return e?e.filter(a=>I(a,r)):[]}function y(e){return{id:e.id,title:e.title,icon:e.icon,description:e.description,app_name:e.app_name,app_id:e.app_id,tools:e.tools,metadata:e.metadata}}function M({binding:e,renderHeader:r,renderEmptyState:a}){const{org:s}=E(),{pluginId:n}=S({strict:!1}),d=k(),{data:o}=L.useSession(),l=B(d,e),[i,m]=H(w.pluginConnection(s.slug,n),c=>c??""),u=l.find(c=>c.id===i)??l[0]??null,p=o?.user?{user:{id:o.user.id,name:o.user.name,email:o.user.email,image:o.user.image}}:null,g={id:s.id,slug:s.slug,name:s.name};if(l.length===0||!u){const c={connectionId:null,connection:null,toolCaller:null,org:g,session:p};return t.jsx(j,{value:c,children:t.jsx("div",{className:"h-full flex flex-col overflow-hidden",children:a()})})}const h=z({connectionId:u.id,orgId:s.id}),v={connectionId:u.id,connection:y(u),toolCaller:((c,_)=>h?h.callTool({name:c,arguments:_}).then(C=>C.structuredContent??C):Promise.reject(new Error("MCP client is not available"))),org:g,session:p};return t.jsx(j,{value:v,children:t.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[r({connections:l.map(y),selectedConnectionId:u.id,onConnectionChange:m}),t.jsx("div",{className:"flex-1 overflow-hidden",children:t.jsx(f.Suspense,{fallback:t.jsxs("div",{className:"flex flex-col items-center justify-center h-full",children:[t.jsx(x,{size:32,className:"animate-spin text-muted-foreground mb-4"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."})]}),children:t.jsx(b,{})})})]})})}function F(){const e=N.c(12);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={strict:!1},e[0]=r):r=e[0];const{pluginId:a}=S(r);let s;e[1]!==a?(s=P.find(i=>i.id===a),e[1]=a,e[2]=s):s=e[2];const n=s;if(n?.renderHeader&&n?.renderEmptyState){let i;e[3]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsxs("div",{className:"flex flex-col items-center justify-center h-full",children:[t.jsx(x,{size:32,className:"animate-spin text-muted-foreground mb-4"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading plugin..."})]}),e[3]=i):i=e[3];let m;return e[4]!==n.binding||e[5]!==n.renderEmptyState||e[6]!==n.renderHeader?(m=t.jsx(f.Suspense,{fallback:i,children:t.jsx(M,{binding:n.binding,renderHeader:n.renderHeader,renderEmptyState:n.renderEmptyState})}),e[4]=n.binding,e[5]=n.renderEmptyState,e[6]=n.renderHeader,e[7]=m):m=e[7],m}const d=n?.LayoutComponent;if(!d){let i;return e[8]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(b,{}),e[8]=i):i=e[8],i}let o;e[9]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsxs("div",{className:"flex flex-col items-center justify-center h-full",children:[t.jsx(x,{size:32,className:"animate-spin text-muted-foreground mb-4"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading plugin..."})]}),e[9]=o):o=e[9];let l;return e[10]!==d?(l=t.jsx(f.Suspense,{fallback:o,children:t.jsx(d,{})}),e[10]=d,e[11]=l):l=e[11],l}export{F as default};
