import{r as e,K,C as N,L as _,D as d,M as B}from"./vendor-D8aaNQoj.js";import{L as q,a as F}from"./index-BweOkQpw.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 le,i as ce,j as de}from"./LogPanel-BfaE547X.js";import{u as ue,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-sVQ35qZY.js";import"./helpers-BosuxZz1.js";const b=q.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(),u=ue(),D=fe(),w=ge(),o=K(),g=pe();e.useEffect(function(){async function n(){try{if(r==null)throw new Error('Missing URL parameter "name"');const t=D.getStorageService(),l=new be(t,""),A=await new k(l).load({isConsoleAvailable:!1}),{data:{settings:R}}=A,{shortcutOverrides:v={}}=R,T=oe.isMacPlatform?v.mac??{}:v.windows??{};Object.entries(T).forEach(([V,Y])=>{var M;(M=ne.get(V))==null||M.setKeyState(Y)}),o(re(S)),o(ie(g)),o(le(w)),o(ce(A)),o(de(k.makeDefaultWorkspaceSettings(g))),b.debug(`Loading widget definition for ${r}...`);const z=await Se(u,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,u,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")}:()=>u.getObject(a),[u,a]),[s,W]=e.useState(null),[h,H]=e.useState("default-embed-widget"),O=e.useCallback(({pluginId:i,data:n})=>{const t=N();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=_(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 l=0;l<n.length;l+=1){const c=n[l];c.type==="react-component"||c.type==="component"?t+=1:c.content!=null&&(t+=i(c.content))}return t}return i(m)>1},[m]);return e.useEffect(function(){s!=null&&(L?s.enableHeaders():s.disableHeaders())},[L,s]),d.jsxs("div",{className:"App",children:[p&&d.jsx(ae,{children:d.jsx(me,{dashboards:[{id:h,layoutConfig:m,layoutSettings:De}],activeDashboard:h,onLayoutInitialized:U,onGoldenLayoutChange:W,plugins:I})}),!p&&d.jsx(F,{"data-testid":"embed-widget-app-loading",isLoaded:p,isLoading:j,errorMessage:f??null}),d.jsx(B,{})]})}export{Me as default};
//# sourceMappingURL=App-Bk9LBQA6.js.map
