text: /**
   * @license
   * Copyright (c) 2014, 2021, Oracle and/or its affiliates.
   * Licensed under The Universal Permissive License (UPL), Version 1.0
   * as shown at https://oss.oracle.com/licenses/upl/
   * @ignore
   */
  define(["ojs/ojcore-base","ojs/ojlogger"],function(e,t){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;
  /**
     * @license
     * Copyright (c) 2014, 2021, Oracle and/or its affiliates.
     * The Universal Permissive License (UPL), Version 1.0
     * as shown at https://oss.oracle.com/licenses/upl/
     * @ignore
     */
  var s=function e(t){this._description=t,this._addedWaitTs=e._getTs(),this._id=this._addedWaitTs.toString(36)+"_"+Math.random().toString(36)};e._registerLegacyNamespaceProp("BusyState",s),Object.defineProperties(s.prototype,{id:{get:function(){return this._id},enumerable:!0},description:{get:function(){if(this._description)return this._description instanceof Function?this._description():this._description.toString()},enumerable:!0}}),s.prototype.toString=function(){var e="Busy state: [description=",t=this.description;return null!==t&&(e+=t),e+=", elapsed="+(s._getTs()-this._addedWaitTs)+"]"},s._getTs=function(){return window.performance?window.performance.now():(new Date).getTime()};
  /**
     * @license
     * Copyright (c) 2014, 2021, Oracle and/or its affiliates.
     * The Universal Permissive License (UPL), Version 1.0
     * as shown at https://oss.oracle.com/licenses/upl/
     * @ignore
     */
  var o,n=function(e){this.Init(e)};function i(){return o||(o=new Promise(function(e){window.setImmediate(function(){o=null,e(!0)})})),o}e.Object.createSubclass(n,e.Object,"oj.BusyContext"),e._registerLegacyNamespaceProp("BusyContext",n),n._defaultTimeout=Number.NaN,n.setDefaultTimeout=function(e){isNaN(e)||(n._defaultTimeout=e)},n.prototype.Init=function(e){n.superclass.Init.call(this),this._hostNode=e,this._statesMap=new Map,this._mediator={getMasterWhenReadyPromise:function(){return this._masterWhenReadyPromise||(this._masterWhenReadyPromise=new Promise(this._captureWhenReadyPromiseResolver.bind(this))),this._masterWhenReadyPromise},resolveMasterWhenReadyPromise:function(){this._masterWhenReadyPromiseResolver&&this._masterWhenReadyPromiseResolver(!0),this._masterWhenReadyPromise=null,this._masterWhenReadyPromiseResolver=null,this._masterWhenReadyPromiseRejecter=null},rejectMasterWhenReadyPromise:function(e){this._masterWhenReadyPromiseRejecter&&this._masterWhenReadyPromiseRejecter(e),this._masterWhenReadyPromise=null,this._masterWhenReadyPromiseRejecter=null,this._masterWhenReadyPromiseResolver=null},getSlaveTimeoutPromise:function(e,t,s){var o,n=new Promise(function(e,n){o=window.setTimeout(function(){n(t())},s)});return this._slaveTimeoutPromiseTimers.push(o),Promise.race([e,n]).finally(this._clearAllSlaveTimeouts.bind(this))},_clearAllSlaveTimeouts:function(){var e=this._slaveTimeoutPromiseTimers;this._slaveTimeoutPromiseTimers=[];for(var t=0;t<e.length;t++)window.clearTimeout(e[t]);return!0},_captureWhenReadyPromiseResolver:function(e,t){this._masterWhenReadyPromiseResolver=e,this._masterWhenReadyPromiseRejecter=t},_slaveTimeoutPromiseTimers:[]}},n._log=function(e){if(t.option("level")===t.LEVEL_LOG){t.log(">> Busy states: %d",e.size);var s=n._values(e);s.length>0&&t.log(s.join("\n"))}},n._values=function(e){var t=[];return e.forEach(function(e){t.push(e)}),t},n.prototype.addBusyState=function(e){t.log("BusyContext.addBusyState: start scope='%s'",this._getDebugScope());var o=this._statesMap,i=new s(e[n._DESCRIPTION]);return t.log(">> "+i),o.set(i.id,i),this._addBusyStateToParent(),t.log("BusyContext.addBusyState: end scope='%s'",this._getDebugScope()),this._removeBusyState.bind(this,i)},n.prototype.dump=function(e){t.info("BusyContext.dump: start scope='%s' %s",this._getDebugScope(),e||"");var s=this._statesMap;t.info(">> Busy states: %d",s.size);var o=n._values(s);o.length>0&&t.info(o.join("\n")),t.info("BusyContext.dump: start scope='%s' %s",this._getDebugScope(),e||"")},n.prototype.getBusyStates=function(){var e=this._statesMap;return n._values(e)},n.prototype.clear=function(){t.log("BusyContext.clear: start scope='%s'",this._getDebugScope());for(var e=this._statesMap,s=n._values(e),o=0;o<s.length;o++){var i=s[o];try{this._removeBusyState(i)}catch(e){t.log("BusyContext.clear: %o",e)}Object.defineProperty(i,n._OJ_RIP,{value:!0,enumerable:!1})}t.log("BusyContext.clear: end scope='%s'",this._getDebugScope())},n.prototype.whenReady=function(e){var s=this._getDebugScope();t.log("BusyContext.whenReady: start, scope='%s', timeout=%d",s,e);var o=this._statesMap,r=this._mediator,a=i(),u=n._BOOTSTRAP_MEDIATOR.whenReady(),l=r.getMasterWhenReadyPromise(),_=Promise.all([a,u]).then(function(){t.log("BusyContext.whenReady: bootstrap mediator ready scope=%s",s);try{n._deliverThrottledUpdates()}catch(e){throw t.error("Fatal exception delivering binding updates: %o",e),e}return 0!==o.size||this._waitingOnNextTickBusynessEval||(t.log("BusyContext.whenReady: resolved no busy states scope=%s",s),r.resolveMasterWhenReadyPromise()),t.log("BusyContext.whenReady: busy states returning master scope=%s",s),l}.bind(this));return isNaN(e)&&!isNaN(n._defaultTimeout)&&(e=n._defaultTimeout),isNaN(e)||(_=r.getSlaveTimeoutPromise(_,function(){var i,r="whenReady timeout of "+e+"ms expired ";n._log(o);var a=n._values(o);return(i=n._BOOTSTRAP_MEDIATOR.isReady()?new Error(r+"with the following busy states: "+a.join(", ")):new Error(r+'while the application is loading. Busy state enabled by setting the "window.oj_whenReady = true;" global variable. Application bootstrap busy state is released by calling "oj.Context.getPageContext().getBusyContext().applicationBootstrapComplete();".')).busyStates=a,t.log("BusyContext.whenReady: rejected scope='%s'\n%s",s,i.message),i},e)),t.log("BusyContext.whenReady: end scope='%s'",this._getDebugScope()),_},n.prototype.isReady=function(){t.log("BusyContext.isReady: start scope='%s'",this._getDebugScope());var e=!1;if(n._BOOTSTRAP_MEDIATOR.isReady()&&!this._waitingOnNextTickBusynessEval){var s=this._statesMap;e=0===s.size,n._log(s)}return t.log("BusyContext.isReady: end scope='%s'",this._getDebugScope()),e},n.prototype._removeBusyState=function(e){var s=this._getDebugScope();t.log("BusyContext._removeBusyState: start scope='%s'",s);var o=this._statesMap;if(e[n._OJ_RIP])t.log("Busy state has been forcefully resolved via clear:\n"+e);else{if(!o.delete(e.id))throw new Error("Busy state has already been resolved:\n"+e);t.log("BusyContext._removeBusyState: resolving busy state:\n"+e),0!==o.size||this._waitingOnNextTickBusynessEval||(this._waitingOnNextTickBusynessEval=!0,i().then(this._evalBusyness.bind(this))),t.log("BusyContext._removeBusyState: end scope='%s'",s)}},n.prototype._evalBusyness=function(){var e=this._getDebugScope();t.log("BusyContext._evalBusyness: begin scope='%s'",e);try{n._deliverThrottledUpdates()}catch(e){return t.error("Fatal exception delivering binding updates: %o",e),this._waitingOnNextTickBusynessEval=!1,void this._rejectWhenReadyPromises(e)}var s=this._statesMap,o=this._mediator;this._waitingOnNextTickBusynessEval=!1,0===s.size?(t.log("BusyContext._evalBusyness: resolving whenReady promises"),o.resolveMasterWhenReadyPromise(),this._resolveBusyStateForParent()):n._log(s),t.log("BusyContext._evalBusyness: end scope='%s'",e)},n.prototype.applicationBootstrapComplete=function(){var e=this._getDebugScope();t.log("BusyContext.applicationBootstrapComplete: begin scope='%s'",e),n._BOOTSTRAP_MEDIATOR.notifyComplete(),t.log("BusyContext.applicationBootstrapComplete: end scope='%s'",e)},n.prototype._getParentBusyContext=function(){if(this._hostNode){var t=e.Context.getContext(e.Context.getParentElement(this._hostNode));if(t)return t.getBusyContext()}return null},n.prototype._addBusyStateToParent=function(){if(!this._parentNotified){this._parentNotified=!0;var e=this._getParentBusyContext();if(e){var t={};t[n._DESCRIPTION]=this.toString.bind(this),this._parentResolveCallback=e.addBusyState(t)}}},n.prototype._resolveBusyStateForParent=function(){this._parentNotified=!1,this._parentResolveCallback&&(this._parentResolveCallback(),this._parentResolveCallback=null)},n.prototype._rejectWhenReadyPromises=function(e){this._mediator.rejectMasterWhenReadyPromise(e);var t=this._getParentBusyContext();t&&(t._rejectWhenReadyPromises(e),this._resolveBusyStateForParent())},n.prototype._getCompoundDescription=function(){return"["+n._values(this._statesMap).join(", ")+"]"},n.prototype._getDebugScope=function(){function e(e){var t="undefined";if(e)if(e.id&&e.id.length>0)t="#"+e.id;else{t=e.nodeName,e.hasAttribute("data-oj-context")&&(t+="[data-oj-context]");var s=e.getAttribute("class");s&&(t+="."+s.split(" ").join("."))}return t}return this._debugScope||(this._hostNode?this._debugScope=e(this._hostNode.parentElement)+" > "+e(this._hostNode):this._debugScope="page"),this._debugScope},n.prototype.toString=function(){var e="Busy Context: [scope=";return e+=this._getDebugScope(),e+=" states="+this._getCompoundDescription()+"]"},n._deliverThrottledUpdates=function(){e.ComponentBinding&&e.ComponentBinding.deliverChanges()},n._DESCRIPTION="description",n._OJ_RIP="__ojRip",n._BOOTSTRAP_MEDIATOR=new function(){var e,t,s;"undefined"!=typeof window&&(e=window.oj_whenReady),this.whenReady=function(){return t||(t=e?new Promise(function(e){s=e}):Promise.resolve(!0))},this.isReady=function(){return!e},this.notifyComplete=function(){s?i().then(function(){e=!1,s(!0),s=null}):e=!1}};
  /**
     * @license
     * Copyright (c) 2014, 2021, Oracle and/or its affiliates.
     * The Universal Permissive License (UPL), Version 1.0
     * as shown at https://oss.oracle.com/licenses/upl/
     * @ignore
     */
  var r=function(e){this.Init(e)};return e.Object.createSubclass(r,e.Object,"oj.Context"),r.prototype.Init=function(e){r.superclass.Init.call(this),this._node=e},r.getContext=function(e){for(;e;){var t=e[r._OJ_CONTEXT_INSTANCE];if(t)return t;if(e.hasAttribute(r._OJ_CONTEXT_ATTRIBUTE))return t=new r(e),Object.defineProperty(e,r._OJ_CONTEXT_INSTANCE,{value:t}),t;e=r.getParentElement(e)}return r.getPageContext()},r.getPageContext=function(){return r._pageContext||(r._pageContext=new r),r._pageContext},r.prototype.getBusyContext=function(){return this._busyContext||(this._busyContext=new n(this._node)),this._busyContext},r.setBusyContextDefaultTimeout=function(e){n.setDefaultTimeout(e)},r._OJ_CONTEXT_ATTRIBUTE="data-oj-context",r._OJ_CONTEXT_INSTANCE="__ojContextInstance",r._OJ_SURROGATE_ATTR="data-oj-surrogate-id",r.getParentElement=function(e){if(e&&e.hasAttribute(r._OJ_SURROGATE_ATTR)){var t=document.getElementById(e.getAttribute(r._OJ_SURROGATE_ATTR));if(t)return t.parentElement}return e.parentElement},r});
  //# sourceMappingURL=ojcontext.js.map