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