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