import{r as m}from"./redux-1.0.63-Df-eBzJn.js";import{b as G}from"./ActionsApp-1.0.63-BpC5ZVKE.js";import{l as O,A as r,F as g,G as j,H as w,a as u}from"./lib-1.0.63-DJZPtMem.js";import{e as f}from"./notistack-1.0.63-B49ULGrj.js";import{u as z,S as B,D as h}from"./StoreTypeEnum-1.0.63-Cbd7XZ4r.js";import{a as K}from"./hooks-1.0.63-CWs3kTdT.js";const I=(t,s,L,b,H,Q,A,o)=>{const a=K(),{prepareAppStore:J,prepareApp:k}=z(t,B.APP),[x,c]=m.useState(!1),[R,i]=m.useState(),[q,S]=m.useState(""),y=e=>{var n,D,M,P,T,_,E,N,v,C;if(O.debug(e),e.app&&e.app.app&&Array.isArray(e.app.app)&&e.app.container&&Array.isArray(e.app.container)&&e.app.apps&&Array.isArray(e.app.apps))if(e.app.app[0].app_type==r.APPCONTAINER)k(e,A),i(r.APPCONTAINER),c(!0);else if(e.app.app[0].app_type==r.CHART){const p={...e};p.src=h(s,(D=(n=e==null?void 0:e.app)==null?void 0:n.container[0])==null?void 0:D.cnt_id),A===!0&&(p.isExploring=!0),o!==void 0&&(p.appRootId=o),a(g({appId:t,metaData:p})),i(r.CHART),c(!0)}else if(e.app.app[0].app_type==r.MAP){const p={...e};p.src=h(s,(P=(M=e==null?void 0:e.app)==null?void 0:M.container[0])==null?void 0:P.cnt_id),A===!0&&(p.isExploring=!0),o!==void 0&&(p.appRootId=o);let l={};try{((_=(T=e==null?void 0:e.app)==null?void 0:T.container[0])==null?void 0:_.cnt_map)!==void 0&&((N=(E=e==null?void 0:e.app)==null?void 0:E.container[0])==null?void 0:N.cnt_map)!==null&&(l=JSON.parse((C=(v=e==null?void 0:e.app)==null?void 0:v.container[0])==null?void 0:C.cnt_map),delete l.state)}catch(F){console.error("Invalid JSON - map settings"),console.error(F),f("Invalid JSON, check console",{variant:"error"})}a(j({appId:t,mapState:l})),a(g({appId:t,metaData:p})),i(r.MAP),c(!0)}else J(s,e,L===!0,void 0,o,()=>{})&&(a(w({appId:t,property:{staticFilter:b,shortcodeArgs:H}})),i(e.app.app[0].app_type),c(!0));else f(u.contactSupport,{variant:"error"}),S(u.contactSupport)};return{loadAppMetaData:()=>{G(s,e=>{const n=e==null?void 0:e.data;O.debug("response data",n),y(n)},e=>{console.error("error",e),f(e??u.contactSupport,{variant:"error"}),S(e??u.contactSupport)})},processMetaData:y,metaDataLoaded:x,loadError:q,appType:R}};export{I as u};
