import t from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/slicedToArray";import i from"@babel/runtime/helpers/objectWithoutProperties";import{memo as r,useState as s,useEffect as o,useMemo as n}from"react";import p from"classnames";import a from"lodash/noop";import{Map as m,fromJS as l}from"immutable";import{makeStyles as c,useTheme as u,Typography as d}from"@material-ui/core";import{AppInfo as b,AppInfoMaximized as A}from"./components/AppInfo.js";import f from"./styles.css.js";import{isNativeDetected as h}from"../../utils/mobileDetect.js";import{Size as g}from"../../constants/sizes.js";import y from"../LoadingIndicator/LoadingIndicator.js";import{Tooltip as T}from"../Tooltip/Tooltip.js";import"../Tooltip/ScrollableTooltip.js";import{DEFAULT_SUBSCRIPTION_META as v}from"../../constants/subscriptions.js";import{COLLECTIONS as j}from"../../constants/bha.js";import*as C from"../../utils/convert.js";import{jsx as D,jsxs as O,Fragment as S}from"react/jsx-runtime";var I=["assetId","appId","asset","appSize","widthCols","appHeight","appWidth","orientation","appComponentKey","appComponentCategory","subscriptions","requiresSubscription","timestamp","appContext","appContainerClassName","settings","time","appData","appRegistry","subscribeAppForAsset","unsubscribeAppFromAsset","internalSelectors"];function E(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,r)}return i}function x(e){for(var i=1;i<arguments.length;i++){var r=null!=arguments[i]?arguments[i]:{};i%2?E(Object(r),!0).forEach((function(i){t(e,i,r[i])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):E(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var M=c({h6:{fontSize:"1.15rem",margin:"0 0 0 3px"},subtitle:{fontSize:"0.755rem",lineHeight:"1",margin:"0 0 0 3px",color:"#888!important"}}),P=function(r){var c,E=r.assetId,P=r.appId,w=r.asset,z=r.appSize,N=r.widthCols,W=r.appHeight,F=r.appWidth,H=r.orientation,L=r.appComponentKey,R=r.appComponentCategory;r.subscriptions;var q=r.requiresSubscription,U=r.timestamp,k=r.appContext,G=r.appContainerClassName,K=r.settings,X=r.time,B=r.appData,J=r.appRegistry,Q=r.subscribeAppForAsset,V=r.unsubscribeAppFromAsset,Y=r.internalSelectors,Z=Y.isSubDataLoading,$=Y.getSubErrors,_=Y.isSubDataEmpty,tt=i(r,I),et=u(),it=M(),rt=s(!1),st=e(rt,2),ot=st[0],nt=st[1],pt=J.uiApps.getIn([R,"appTypes",L]),at=(r.subscriptions.length?r.subscriptions:pt.constants.SUBSCRIPTIONS).map((function(t){return x(x({},t),{},{meta:x(x(x({},v),t.meta),{},{subscribeOnlyForInitialData:!0,subscribeToLatestOnly:t.collection===j.survey.collection})})})),mt=pt.constants.METADATA.title||pt.constants.METADATA.settingsTitle,lt=pt.constants.METADATA.customEmptyDataHandling;o((function(){return q&&Q(P,at,E,m({query:"{timestamp#lte#".concat(U,"}")})),function(){V(P,at)}}),[]);var ct=!1,ut=!1,dt=null,bt=B.get(P,m());B&&(ct=Z(bt,at),dt=$(bt,at),ut=_(bt,at));var At=n((function(){return Object.keys(K).reduce((function(e,i){return x(x({},e),{},t({},i,l(K[i])))}),{})}),[]),ft=ut&&!lt;return pt?ct?D(y,{fullscreen:!1}):dt?O(d,{variant:"body2",children:["Data error: ",dt.length?dt.message:"No error message"]}):ft?D(d,{variant:"body2",children:"Data is empty"}):O("div",{className:p(f.embeddedApp,G,(c={},t(c,f.embeddedAppMaximized,ot),t(c,f.embeddedAppNative,h),c)),children:[!ot&&D(b,{setMaximized:nt}),!pt.constants.METADATA.disableAppTitle&&O(S,{children:[D("div",{className:f.embeddedAppTitle,children:D(d,{classes:{h6:it.h6},variant:"h6",noWrap:!0,children:mt})}),D(T,{title:pt.constants.METADATA.title,children:D(d,{classes:{subtitle1:it.subtitle},variant:"subtitle1",noWrap:!0,children:pt.constants.METADATA.subtitle})})]}),D("div",{className:p(f.embeddedAppContent,t({},f.embeddedAppContentWithTitle,!pt.constants.METADATA.disableAppTitle)),children:D(pt.AppComponent,x(x({asset:w,appId:P,data:bt,size:ot?g.XLARGE:z,coordinates:m({h:0,w:0,x:0,y:0,pixelHeight:W,pixelWidth:F}),widthCols:N,maximized:ot,theme:et,orientation:H,registerMenuItems:a,convert:C,onAppSubscribeForAsset:Q,onAppUnsubscribeFromAsset:V,onSettingsChange:function(){},isNative:h,appContext:k,layoutType:"singleApp",appTitle:mt,time:X},At),tt))},ot?g.XLARGE:z),ot&&D(A,{setMaximized:nt})]}):null};P.defaultProps={appContainerClassName:void 0,assetId:void 0,appId:0,asset:m(),requiresSubscription:!0,appSize:g.MEDIUM,subscriptions:[],widthCols:1,appWidth:600,appHeight:500,orientation:"vertical",settings:{},timestamp:null,time:null};var w=r(P);export{w as default};
