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