import t,{createElement as e,PureComponent as n}from"react";
/*! *****************************************************************************
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.
***************************************************************************** */var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var a=function(){return(a=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function s(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function c(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var a=arguments[e],s=0,c=a.length;s<c;s++,o++)r[o]=a[s];return r}var i=function(t){void 0===t&&(t=12);for(var e=Math.pow(16,Math.min(t,8)-1),n=Math.pow(16,Math.min(t,8))-1,r=(Math.floor(Math.random()*(n-e+1))+e).toString(16);r.length<t;)r+=i(t-8);return r},f=function(t){function n(){var n=null!==t&&t.apply(this,arguments)||this;return n.defaultOptions={exitTimeout:500,enterTimeout:50},n.state={instances:{},hashStack:[]},n.factoryRef=function(t){n.factoryContainer=t},n.getInstanceChildren=function(){return Object.keys(n.state.instances).map((function(t){var r=n.state.instances[t],o=r.Component,s=r.props,c=r.resolve,i=Boolean(n.state.hashStack.find((function(e){return e===t})));return e(o,a({},s,{key:t,isOpen:i,onResolve:c,close:c,open:i}))}))},n.create=function(t,e){return void 0===e&&(e={}),function(r){return new Promise((function(o){var s,f,u=r&&r.instanceId||i(),p=a(a({},n.defaultOptions),e),l=n.props,v=l.isAppendIntances,h=l.onOpen,y=l.onResolve,m=a({Component:t,props:a(a({},p),r),resolve:function(t){n.remove(u),o(t),y&&y(t,u)}},p),d=v?a(a({},n.state.instances),((s={})[u]=m,s)):a(((f={})[u]=m,f),n.state.instances);n.setState({instances:d},(function(){setTimeout((function(){n.setState({hashStack:c(n.state.hashStack,[u])})}),p.enterTimeout)})),h&&h(u,m)}))}},n.omitState=function(t){var e=n.state.instances,r=t;e[r];var o=s(e,["symbol"==typeof r?r:r+""]);n.setState({instances:o},(function(){var e=n.props.onRemove;e&&e(t)}))},n.remove=function(t){var e=n.state,r=t,o=e.instances[r],a=o&&o.exitTimeout;n.setState({hashStack:n.state.hashStack.filter((function(e){return e!==t}))},(function(){setTimeout(n.omitState,a,t)}))},n.getInstance=function(t){return n.state.instances[t]},n.resolve=function(t,e){var r=n.state.instances[t];if(r)return r.resolve(e)},n.resolveAll=function(){Object.values(n.state.instances).forEach((function(t){return t.resolve()}))},n}return o(n,t),n.prototype.componentWillUnmount=function(){this.resolveAll()},n.prototype.render=function(){return e("div",{ref:this.factoryRef},this.getInstanceChildren())},n}(n),u={};"undefined"!=typeof window&&(window.factoryStack||(window.factoryStack={}),u=window.factoryStack);var p=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.getInstance=function(e){return t.factoryRef.getInstance(e)},t.hasInstance=function(e){return Boolean(t.getInstance(e))},t.resolveAll=function(){return t.factoryRef.resolveAll()},t.resolve=function(e,n){return t.factoryRef.resolve(e,n)},t.registerRef=function(e){var n=t.props.scope;e&&(u[void 0===n?"stack":n]=e,t.factoryRef=e)},t}return o(n,e),n.prototype.render=function(){var e=this.props;e.scope;var n=s(e,["scope"]);return t.createElement(f,a({},n,{ref:this.registerRef}))},n.defaultProps={scope:"stack"},n}(t.Component),l=function(t,e){return function(n){return u[e&&e.scope||"stack"].create(t,e)(n)}};export default p;export{l as createModal,i as hexGen};
//# sourceMappingURL=index.es.js.map
