/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@bbp/react-nexus@1.3.15/lib/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),invariant=_interopDefault(require("ts-invariant"));const context=React.createContext(null),NexusProvider=({nexusClient:e,children:t})=>React.createElement(context.Provider,{value:e},t),warningMessage="No Nexus client found. To use react-nexus components, make sure you wrap your React app with the NexusProvider component like: <NexusProvider nexusClient={myClient)><App /></NexusProvider>. ";function useNexusContext(){const e=React.useContext(context);return invariant(e,warningMessage),e}function useNexus(e,t=[]){const n=useNexusContext(),[r,s]=React.useState({loading:!0,error:null,data:null});return React.useEffect((()=>{s(Object.assign(Object.assign({},r),{loading:!0}));const t=e(n);if(t instanceof Promise)return t.then((e=>s(Object.assign(Object.assign({},r),{data:e,loading:!1})))).catch((e=>s(Object.assign(Object.assign({},r),{error:e,loading:!1})))),()=>{};const o=t.subscribe({next:e=>{s(Object.assign(Object.assign({},r),{data:e,loading:!1}))},error:e=>{s(Object.assign(Object.assign({},r),{error:e,loading:!1}))},complete:()=>{o.unsubscribe()}});return()=>o.unsubscribe()}),t),r}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function __awaiter(e,t,n,r){return new(n||(n=Promise))((function(s,o){function c(e){try{i(r.next(e))}catch(e){o(e)}}function a(e){try{i(r.throw(e))}catch(e){o(e)}}function i(e){e.done?s(e.value):new n((function(t){t(e.value)})).then(c,a)}i((r=r.apply(e,t||[])).next())}))}const matchAnonymous=(e,t)=>"Anonymous"===e["@type"]&&t["@type"]===e["@type"],matchAuthenticated=(e,t)=>"Authenticated"===e["@type"]&&t["@type"]===e["@type"]&&t.realm===e.realm,matchUser=(e,t)=>"User"===e["@type"]&&t["@type"]===e["@type"]&&t.realm===e.realm&&t.subject===e.subject,matchGroup=(e,t)=>"Group"===e["@type"]&&t["@type"]===e["@type"]&&t.realm===e.realm&&t.group===e.group,matchIdentity=(e,t)=>!!e.find((e=>{if(e["@type"]===t["@type"])switch(e["@type"]){case"Anonymous":return matchAnonymous(e,t);case"User":return matchUser(e,t);case"Authenticated":return matchAuthenticated(e,t);case"Group":return matchGroup(e,t)}return!1}))&&t,checkPermissions=(e,t=["/"])=>n=>__awaiter(void 0,void 0,void 0,(function*(){const r=yield n.Identity.list(),s=(Array.isArray(t)?t:[t]).map((e=>n.ACL.list(e,{ancestors:!0,self:!0})));return Promise.all(s).then((t=>{const n=t.map((t=>t._results.reduce(((e,t)=>[...e,...t.acl.reduce(((e,t)=>matchIdentity(r.identities,t.identity)?[...e,t]:e),[])]),[]).reduce(((e,t)=>e.filter((e=>!t.permissions.includes(e)))),e))),s=[...new Set(n.flat())];return new Promise(((e,t)=>{0===s.length&&e(!0),t(s)}))}))})),AccessControl=e=>{const t=useNexus(checkPermissions(e.permissions,e.path));return t.loading?e.loadingComponent?React.createElement(React.Fragment,null,e.loadingComponent):null:t.error?e.noAccessComponent?"function"==typeof e.noAccessComponent?React.createElement(React.Fragment,null,e.noAccessComponent({missingPermissions:t.error})):React.createElement(React.Fragment,null,e.noAccessComponent):null:React.createElement(React.Fragment,null,e.children)};exports.AccessControl=AccessControl,exports.NexusProvider=NexusProvider,exports.useNexus=useNexus,exports.useNexusContext=useNexusContext;
//# sourceMappingURL=/sm/e30d4f4a82406b91138aec58768e71bd579de8b5e9d2f56a8debebd4147ad5b6.map