define(["require","exports","tslib","../../deps/bluebird_fork","./FormElementMap","./FormRenderer","../../Hooks"],function(e,t,r,s,o,n,u){"use strict";function a(r,o){var n=s.default.defer(),e=n.promise,u=r();return function e(){for(;u.isFulfilled();){var t;if(void 0===(t=u.value()))break;if(void 0!==(t=o(t))){n.resolve(t);break}u=r()}u.isPending()&&u.then(e),u.isRejected()&&n.reject(u.reason())}(),e}Object.defineProperty(t,"__esModule",{value:!0}),s=r.__importDefault(s);var l,n=((l=i).createRenderer=function(e,t,r){var o=t.luid,n=!1!==e.reset,u=e.name;"string"==typeof u&&(o=":"+u);var i=this.renderers,s=i[o];void 0===s&&(n=!0,u=function(){delete i[o],s.dispose()},((s=i[o]=r.create()).state=t.ambient).completion.then(u,u)),n?s.load(e.form,e.template):s.load();n="string"==typeof e.container?e.container:"default",e="string"==typeof e.region?e.region:void 0;return s.form.defaults.container=void 0!==e||"default"!==n&&"modal"!==n?{name:n,region:e}:n,s},i.prototype.execute=function(e,u,t){var i=u.state;if(void 0!==i){var r=i.outputs,o=u.caught;if(void 0!==o){var n=r.event,n=n?"Error in "+n.name+" element's "+n.type+" event in":"Error in a subworkflow of";return console.error(n+" a Display Form activity: "+o.message+"\n"+o.stack),u.fork("catch"),i.busy(),i.outputs={actor:i,state:i.form.elements,event:r.event,route:!1,error:o},l.updateElementMap(i.outputs),i.outputs}o=r.result;if("string"==typeof o)return i.spinNoBlock(),i.outputs={actor:i,state:i.form.elements,event:r.event,route:!1,result:o,status:o},l.updateElementMap(i.outputs),i.outputs;if("object"==typeof o&&null!==o)return i.spinNoBlock(),s.default.reject(o);r.route&&i.route(r.event)}else i=l.createRenderer(e,u,t),u.persist(i);return i.outputs=void 0,a(function(){var e=i.observe();return e.isFulfilled()&&void 0===e.value()&&i.dispose(),e},function(e){var t,r=e.value,o=("submit"===e.type||"end"===e.type)&&"string"==typeof r?r:void 0;function n(){return t=i.outputs={actor:i,state:i.form.elements,event:e,route:!1,result:o,status:o},l.updateElementMap(i.outputs),i.outputs}if(!i.trap(e)&&u.hasBranch(e.routingKey)){r=e.cancellationToken;if(null!=r){if(s.default.resolve(r).isFulfilled())return void i.route(e);r.then(function(){i.outputs===t&&u.goto()})}else i.busy();return u.fork(e.routingKey),u.registerForErrors(),n()}if(void 0!==o)return i.spinNoBlock(),n();i.route(e)})},i.updateElementMap=function(e){if(e&&e.state)for(var t in e.state)o.setFormForElement(e.state[t],e)},i.renderers={},i.action="gcx:wf:forms:form:DisplayForm",i.suite="gcx:wf:builtin",l=r.__decorate([u.activate(n.FormRenderer)],i));function i(){}t.DisplayForm=n});