"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/objectWithoutProperties"),r=require("@babel/runtime/helpers/typeof"),n=require("react/jsx-runtime"),o=require("react"),i=require("./AppCommonsContext.js"),a=require("./utils.js"),l=require("../../utils/completion.js");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=p(e),c=p(t),s=p(r),d=["children","app"];function v(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?v(Object(r),!0).forEach((function(t){u.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var g="development"===process.env.NODE_ENV,m=function(e){var t=o.useCallback((function(){null==e||e()}),[e]);return e?t:void 0},b=function(e){var t=o.useRef(e);return t.current=e,o.useCallback((function(){for(var e,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return null===(e=t.current)||void 0===e?void 0:e.call.apply(e,[t].concat(n))}),[])};exports.AppCommonsProvider=function(e){var t,r,p,v,y,j,O,h=e.children,C=e.app,S=c.default(e,d),A=(null==C||null===(t=C.package)||void 0===t||null===(r=t.manifest)||void 0===r||null===(p=r.application)||void 0===p?void 0:p.key)||"",P=(null==C?void 0:C.name)||(null==C||null===(v=C.package)||void 0===v||null===(y=v.manifest)||void 0===y||null===(j=y.application)||void 0===j?void 0:j.name)||"",k=l.getAssetKey(S.fracFleet,S.well,null===(O=S.appSettings)||void 0===O?void 0:O.padId),q=m(S.onHelpCenterClick),w=m(S.onAppRemove),_=m(S.reloadApp),x=b(S.onSettingsChange),D=b(S.onSettingChange),E=o.useMemo((function(){var e;if(!g)return S.appSettings;var t=function(e,t){if(!g)return{};var r="local_corva_pad_mode_".concat(e,"_").concat(t);try{var n=localStorage.getItem(r);if(!n)return{};var o=JSON.parse(n);return"object"!==s.default(o)||null===o||Array.isArray(o)||"string"!=typeof o.mode?{}:o}catch(e){return console.error("Error reading pad mode setting from localStorage",e),{}}}(A,k);return Object.keys(t).length?f(f({},S.appSettings),{},{settingsByAsset:f(f({},null===(e=S.appSettings)||void 0===e?void 0:e.settingsByAsset),{},u.default({},k,t))}):S.appSettings}),[S.appSettings,A,k]),N=a.useAppCommonsValue(f(f({},S),{},{app:C,appKey:A,appName:P,appSettings:E,onHelpCenterClick:q,onAppRemove:w,reloadApp:_,onSettingsChange:x,onSettingChange:D}));return n.jsx(i.AppCommonsContext.Provider,{value:N,children:h})};
//# sourceMappingURL=AppCommonsProvider.js.map
