import{r as e,L as Y,D as _,M as B,F as u,N as F}from"./vendor-CiEcCTfT.js";import{L as K,a as q}from"./index-Bi8EUTME.js";import{u as J,s as Q,a as X,e as Z,g as ee,b as te,E as se,c as ae,S as oe,r as ne,d as re,f as ie,h as ce,i as le,j as ue}from"./LogPanel-HjwtJYDf.js";import{u as de,a as fe,b as ge,c as pe,d as he,A as me,G as be,L as k,f as Se}from"./LocalWorkspaceStorage-BaP2a7jq.js";import"./helpers-BosuxZz1.js";const b=K.module("EmbedWidget.App"),De={hasHeaders:!0,defaultComponentConfig:{isClosable:!1}};function Me(){var E;const[f,x]=e.useState(),[a,P]=e.useState(),r=e.useMemo(()=>new URLSearchParams(window.location.search),[]).get("name"),S=J(),d=de(),D=fe(),w=ge(),o=Y(),g=pe();e.useEffect(function(){async function n(){try{if(r==null)throw new Error('Missing URL parameter "name"');const t=D.getStorageService(),c=new be(t,""),A=await new k(c).load({isConsoleAvailable:!1}),{data:{settings:R}}=A,{shortcutOverrides:v={}}=R,T=oe.isMacPlatform?v.mac??{}:v.windows??{};Object.entries(T).forEach(([N,V])=>{var M;(M=ne.get(N))==null||M.setKeyState(V)}),o(re(S)),o(ie(g)),o(ce(w)),o(le(A)),o(ue(k.makeDefaultWorkspaceSettings(g))),b.debug(`Loading widget definition for ${r}...`);const z=await Se(d,r);P(z),b.debug(`Widget definition successfully loaded for ${r}`)}catch(t){b.error(`Unable to load widget definition for ${r}`,t),x(`${t}`)}}n()},[S,D,d,o,r,g,w]);const p=a!=null&&f==null,j=a==null&&f==null,C=e.useMemo(()=>a==null?async()=>{throw new Error("Definition is null")}:()=>d.getObject(a),[d,a]),[s,W]=e.useState(null),[h,H]=e.useState("default-embed-widget"),O=e.useCallback(({pluginId:i,data:n})=>{const t=_();o(Q(t,i,n)),H(t)},[o]);X(s==null?void 0:s.eventHub,O);const[y,$]=e.useState(!1),U=e.useCallback(()=>{s==null||a==null||y||($(!0),Z(s.eventHub,{fetch:C,widget:ee(a)}))},[s,a,C,y]),G=B(te),I=he(),m=((E=G[h])==null?void 0:E.layoutConfig)??se,L=e.useMemo(()=>{function i(n){if(n.length===0)return 0;let t=0;for(let c=0;c<n.length;c+=1){const l=n[c];l.type==="react-component"||l.type==="component"?t+=1:l.content!=null&&(t+=i(l.content))}return t}return i(m)>1},[m]);return e.useEffect(function(){s!=null&&(L?s.enableHeaders():s.disableHeaders())},[L,s]),u.jsxs("div",{className:"App",children:[p&&u.jsx(ae,{children:u.jsx(me,{dashboards:[{id:h,layoutConfig:m,layoutSettings:De}],activeDashboard:h,onLayoutInitialized:U,onGoldenLayoutChange:W,plugins:I})}),!p&&u.jsx(q,{isLoaded:p,isLoading:j,errorMessage:f??null}),u.jsx(F,{})]})}export{Me as default};
//# sourceMappingURL=App-C_CVZ1ws.js.map
