import{a as e}from"./rolldown-runtime-COnpUsM8.js";import{c as t}from"./vendor-charts-95ykyDlI.js";import{C as n,c as r,d as i,n as a,x as o}from"./api-DGtW0Fh4.js";import{l as s}from"./copy-button-BvU3RDZa.js";import{n as c}from"./utils-XFKvwlFT.js";import{r as l}from"./engine-store-DMULdR_V.js";import{n as u,r as d,t as f}from"./runtime-link-PMxeHxd6.js";var p=c(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]),m=`group relative border border-solid border-border transition-colors hover:border-muted-foreground/25`,h=`group relative border border-solid border-border`,g=`blueprint-card ${m} overflow-hidden rounded-[var(--miravo-radius-stadium-sm)]`,_=`${h} w-full min-w-0 overflow-hidden rounded-[var(--miravo-radius-stadium-sm)] bg-transparent`,v=`${h} w-full min-w-0 overflow-hidden rounded-[var(--miravo-radius-stadium-sm)] bg-transparent`,y=`blueprint-card catalog-card-frame group relative border border-solid overflow-hidden rounded-[var(--miravo-radius-stadium-sm)]`,b=y,x=`border-border bg-muted/40 text-primary shadow-none hover:border-muted-foreground/30 hover:bg-muted/60 hover:text-primary focus-visible:border-ring border-border bg-muted/30 hover:border-muted-foreground/35 hover:bg-muted/45 [&_svg]:text-primary`,S=e(t(),1),C=new Set([`spawn`,`removeInstance`,`loadTemplate`,`unloadTemplateRun`,`resetEnvironment`,`enableAdapter`,`disableAdapter`]);function w(e){if(e instanceof f){s.error(`Command not sent`,{description:e.detail});return}if(e instanceof a){s.error(e.result.message,{description:e.result.error});return}if(n.is(e)){s.error(e.message,{description:e.hint});return}if(e instanceof TypeError){if(typeof navigator<`u`&&navigator.onLine===!1){s.error(`Command not sent`,{description:`This browser is offline — reconnect to the network and try again.`});return}let{connectionState:e}=l.getState(),t=d(e);if(t){s.error(`Command not sent`,{description:t});return}s.error(`Command failed`,{description:`Could not reach the Miravo server — it may have stopped or restarted.`});return}s.error(`Command failed`,{description:e instanceof Error?e.message:`Unknown error.`})}async function T(){try{let e=await r();if(o.setQueryData([`bootstrap`],e),e.authenticated){let t=l.getState();e.runtime.revision>=t.lastRevision&&t.replaceRuntime(e.runtime,{allowSameRevision:!0})}else l.getState().markUnauthenticated()}catch{}finally{o.invalidateQueries({queryKey:[`bootstrap`]})}}function E(){let[e,t]=(0,S.useState)(!1);return{mutate:(0,S.useCallback)(e=>{try{u(l.getState().connectionState)}catch(e){w(e);return}t(!0),i(e).then(t=>{if(s.success(t.message),C.has(e.type))return T()}).catch(w).finally(()=>{t(!1)})},[]),mutateAsync:(0,S.useCallback)(async e=>{try{u(l.getState().connectionState)}catch(e){throw w(e),e}t(!0);try{let t=await i(e);return s.success(t.message),C.has(e.type)&&await T(),t}catch(e){throw w(e),e}finally{t(!1)}},[]),isPending:e}}export{v as a,p as c,y as i,x as n,_ as o,g as r,b as s,E as t};