import{r as m}from"./redux-1.0.74-D8bIc6ki.js";import{R as i}from"./RestApi-1.0.74-5XKxNzpR.js";import{l as n,C as o,E as k,A as r,F as K,G as z,H as I,I as Q,J as V,K as W,b as S}from"./lib-1.0.74-B5IEqfHg.js";import{e as D}from"./utils-1.0.74-7xWhx9mc.js";import{u as X,S as Y,D as Z}from"./StoreTypeEnum-1.0.74-BO7CLiE1.js";import{a as $}from"./hooks-1.0.74-NYCTWeI9.js";const lp=(p,a,s=!1)=>{i(o.appUrlAppList,{},p,a,s)},ip=(p,a,s=!1)=>{i(o.appUrlAppInit,{},p,a,s)},cp=(p,a,s,t=!1)=>{i(o.appUrlAppSetSiteLanguage,{lang:p},a,s,t)},Ap=(p,a,s,t,l=!1)=>{n.debug(p,a);const c=k(p);p.appType==r.APPCONTAINER?(c.app_apps=p.appApps,delete c.app_dbs,delete c.app_tbl,delete c.app_cls):p.appType==r.DASHBOARD?(c.app_dbs="na",c.app_tbl="na",c.app_table=JSON.stringify({})):c.app_table=JSON.stringify(a),n.debug(c),i(p.appType==r.APPCONTAINER?o.appUrlAppCreateApp:o.appUrlAppCreate,c,s,t,l)},up=(p,a,s,t=!1)=>{n.debug(p),i(o.appUrlAppDetails,p,a,s,t)},fp=(p,a,s,t=!1)=>{n.debug(p),i(o.appUrlAppRelationshipCreate,p,a,s,t)},bp=(p,a,s,t=!1)=>{n.debug(p),i(o.appUrlAppRelationshipUpdate,p,a,s,t)},Sp=(p,a,s,t=!1)=>{n.debug(p);const l=k(p,!0);p.appType==r.APPCONTAINER&&(l.app_apps=p.appApps,delete l.app_dbs,delete l.app_tbl,delete l.app_cls),n.debug(l),i(p.appType==r.APPCONTAINER?o.appUrlAppSaveApp:o.appUrlAppSave,l,a,s,t)},gp=(p,a,s,t=!1)=>{n.debug(p),i(o.appUrlAppRemove,{app_id:p},a,s,t)},_p=(p,a,s,t=!1)=>{n.debug(p),i(o.appUrlAppCopy,{app_id:p},a,s,t)},yp=(p,a,s,t=!1)=>{n.debug(p),i(o.appUrlAppExport,{app_id:p},a,s,t)},pp=(p,a,s,t=!1)=>{n.debug(p),i(o.appUrlAppMeta,{app_id:p},a,s,t)},mp=(p,a,s,t,l,c=!1)=>{n.debug(p,a),i(o.appUrlTableMeta,{dbs:p,tbl:a,waa:s},t,l,c)},Dp=(p,a,s,t,l=!1)=>{n.debug(p,a),i(o.appUrlRenameDatabase,{dbs_source:p,dbs_destination:a},s,t,l)},Rp=(p,a,s,t,l,c,R,g)=>{const f=$(),{prepareAppStore:x,prepareApp:B}=X(p,Y.APP),[j,_]=m.useState(!1),[q,A]=m.useState(),[w,T]=m.useState(""),C=e=>{var u,P,N,U,h,O,E,M,d,v,H,L;if(n.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)B(e,R),A(r.APPCONTAINER),_(!0);else if(e.app.app[0].app_type==r.CHART||e.app.app[0].app_type==r.MAP||e.app.app[0].app_type==r.DASHBOARD){const b={...e};switch(b.src=Z(a,(P=(u=e==null?void 0:e.app)==null?void 0:u.container[0])==null?void 0:P.cnt_id),R===!0&&(b.isExploring=!0),g!==void 0&&(b.appRootId=g),f(K({appId:p,metaData:b})),String(e.app.app[0].app_type)){case String(r.CHART):A(r.CHART);break;case String(r.MAP):let y={};try{((U=(N=e==null?void 0:e.app)==null?void 0:N.container[0])==null?void 0:U.cnt_map)!==void 0&&((O=(h=e==null?void 0:e.app)==null?void 0:h.container[0])==null?void 0:O.cnt_map)!==null&&(y=JSON.parse((M=(E=e==null?void 0:e.app)==null?void 0:E.container[0])==null?void 0:M.cnt_map),delete y.state)}catch(G){console.error("Invalid JSON - map settings"),console.error(G),D("Invalid JSON, check console",{variant:"error"})}f(V({appId:p,mapState:y})),A(r.MAP);break;case String(r.DASHBOARD):const J={...I};((v=(d=e==null?void 0:e.app)==null?void 0:d.container[0])==null?void 0:v.cnt_dashboard)!==null&&(J.grid=[]);const F=z({},J,JSON.parse((L=(H=e==null?void 0:e.app)==null?void 0:H.container[0])==null?void 0:L.cnt_dashboard));f(Q({appId:p,dashboard:F})),A(r.DASHBOARD);break}_(!0)}else x(a,e,s===!0,void 0,g,()=>{})&&(f(W({appId:p,property:{staticFilter:t,shortcodeArgs:l}})),A(e.app.app[0].app_type),_(!0));else D(S.contactSupport,{variant:"error"}),T(S.contactSupport)};return{loadAppMetaData:()=>{pp(a,e=>{const u=e==null?void 0:e.data;n.debug("response data",u),C(u)},e=>{console.error("error",e),D(e??S.contactSupport,{variant:"error"}),T(e??S.contactSupport)})},processMetaData:C,metaDataLoaded:j,loadError:w,appType:q}};export{Sp as a,pp as b,_p as c,yp as d,gp as e,Ap as f,cp as g,Dp as h,ip as i,lp as j,mp as k,up as l,fp as m,bp as n,Rp as u};
