"use strict";function a(b){"@babel/helpers - typeof";return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},a(b)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.useConfig=exports["default"]=exports.ConfigContext=void 0;var b=i(require("react")),c=g(require("prop-types")),d=g(require("./defaultOptions")),e=require("../../utils/common"),f=require("lodash");function g(a){return a&&a.__esModule?a:{default:a}}function h(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(h=function(a){return a?c:b})(a)}function i(b,c){if(!c&&b&&b.__esModule)return b;if(null===b||"object"!==a(b)&&"function"!=typeof b)return{default:b};var d=h(c);if(d&&d.has(b))return d.get(b);var e={},f=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var g in b)if("default"!=g&&Object.prototype.hasOwnProperty.call(b,g)){var i=f?Object.getOwnPropertyDescriptor(b,g):null;i&&(i.get||i.set)?Object.defineProperty(e,g,i):e[g]=b[g]}return e["default"]=b,d&&d.set(b,e),e}function j(a,b){return o(a)||n(a,b)||l(a,b)||k()}function k(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(a,b){if(a){if("string"==typeof a)return m(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?m(a,b):void 0}}function m(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function n(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f=[],g=!0,h=!1;try{for(c=c.call(a);!(g=(d=c.next()).done)&&(f.push(d.value),!(b&&f.length===b));g=!0);}catch(a){h=!0,e=a}finally{try{g||null==c["return"]||c["return"]()}finally{if(h)throw e}}return f}}function o(a){if(Array.isArray(a))return a}var p=b["default"].createContext({});exports.ConfigContext=p;var q=function(a){return a.encodedApis?a.encodedApis.map(function(a){return JSON.parse((0,e.b64DecodeUnicode)(a))}):a.apis},r=function(a,b,c,e,g){var h=window.apiConnectExplorer||{};return(0,f.has)(window,"drupalSettings.api.explorer")?h=window.drupalSettings.api.explorer:(0,f.has)(window,"Drupal.settings.api.explorer")&&(h=window.Drupal.settings.api.explorer),h.options=a?a:h.options,h.apps=b?b:h.apps,h.apis=c||e?q({apis:c,encodedApis:e}):q(h),h.docs=g?g:h.docs,h.constants={HASH_ROUTER:"hash",MEMORY_ROUTER:"memory"},h.options=Object.assign({},d["default"],h.options),h},s=function(a){var c=a.options,d=a.apps,e=a.apis,f=a.encodedApis,g=a.docs,h=a.children,i=(0,b.useState)(function(){return r(c,d,e,f,g)}),k=j(i,2),l=k[0],m=k[1],n=function(){m(Object.assign({},r(c,d,e,f,g)))};return(0,b.useEffect)(function(){m(r(c,d,e,f,g))},[c,d,e,f,g]),(0,b.useEffect)(function(){return window.addEventListener("apiConnectExplorerUpdate",n),function(){window.removeEventListener("apiConnectExplorerUpdate",n)}},[]),b["default"].createElement(p.Provider,{value:l},h)},t=function(){return(0,b.useContext)(p)};exports.useConfig=t,s.propTypes={options:c["default"].object,apps:c["default"].array,apis:c["default"].array,encodedApis:c["default"].array,docs:c["default"].array};var u=s;exports["default"]=u;