import{u as E,a as S,g as N,j as n,aG as j,r as f,aH as b,c as L,m as P}from"./index-DkVMZPZp.js";import{i as x}from"./Loading01-BpkkTLVp.js";import{c as I}from"./binder-_fA_QfCQ.js";import{u as H,L as w}from"./localstorage-keys-DVhuzRr7.js";import{e as k}from"./use-connection-BNgYG_2P.js";import{u as z}from"./constants-Chp3RuVB.js";import"./useQuery-BSKCoFrF.js";import"./useMutation-CFQDhqDA.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 O({binding:e,renderHeader:r,renderEmptyState:a}){const{org:i}=E(),{pluginId:t}=S({strict:!1}),d=k(),{data:o}=N.useSession(),l=B(d,e),[s,m]=H(w.pluginConnection(i.slug,t),c=>c??""),u=l.find(c=>c.id===s)??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:i.id,slug:i.slug,name:i.name};if(l.length===0||!u){const c={connectionId:null,connection:null,toolCaller:null,org:g,session:p};return n.jsx(j,{value:c,children:n.jsx("div",{className:"h-full flex flex-col overflow-hidden",children:a()})})}const h=z({connectionId:u.id,orgId:i.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 n.jsx(j,{value:v,children:n.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[r({connections:l.map(y),selectedConnectionId:u.id,onConnectionChange:m}),n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(f.Suspense,{fallback:n.jsxs("div",{className:"flex flex-col items-center justify-center h-full",children:[n.jsx(x,{size:32,className:"animate-spin text-muted-foreground mb-4"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."})]}),children:n.jsx(b,{})})})]})})}function q(){const e=L.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 i;e[1]!==a?(i=P.find(s=>s.id===a),e[1]=a,e[2]=i):i=e[2];const t=i;if(t?.renderHeader&&t?.renderEmptyState){let s;e[3]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsxs("div",{className:"flex flex-col items-center justify-center h-full",children:[n.jsx(x,{size:32,className:"animate-spin text-muted-foreground mb-4"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading plugin..."})]}),e[3]=s):s=e[3];let m;return e[4]!==t.binding||e[5]!==t.renderEmptyState||e[6]!==t.renderHeader?(m=n.jsx(f.Suspense,{fallback:s,children:n.jsx(O,{binding:t.binding,renderHeader:t.renderHeader,renderEmptyState:t.renderEmptyState})}),e[4]=t.binding,e[5]=t.renderEmptyState,e[6]=t.renderHeader,e[7]=m):m=e[7],m}const d=t?.LayoutComponent;if(!d){let s;return e[8]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsx(b,{}),e[8]=s):s=e[8],s}let o;e[9]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsxs("div",{className:"flex flex-col items-center justify-center h-full",children:[n.jsx(x,{size:32,className:"animate-spin text-muted-foreground mb-4"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading plugin..."})]}),e[9]=o):o=e[9];let l;return e[10]!==d?(l=n.jsx(f.Suspense,{fallback:o,children:n.jsx(d,{})}),e[10]=d,e[11]=l):l=e[11],l}export{q as default};
