define(["require","exports","tslib","./deps/bluebird_fork","esri/request","./activities/arcgis/ArcGisApiVersion","./definition/ProgramInspector","./Collections"],function(e,t,r,a,o,n,i,c){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),a=r.__importDefault(a),o=r.__importDefault(o);s.prototype.resolveInspector=function(o,n,i){var c=this;return void 0===n&&(n=!0),a.default.attempt(function(){if(!o)return c.downloadAndResolveInspector(void 0,i);var e="string"==typeof o?o:o.program||o.url;if(n){var t="string"==typeof o?o:o.id||o.url;if(null!=t){var r=c._cache.find(t);return void 0!==r?r:(c._cache.assign(t,c.downloadAndResolveInspector(e,i).catch(function(e){return c._cache.remove(t),a.default.reject(e)})),c._cache.find(t))}}return c.downloadAndResolveInspector(e,i)})},s.prototype.downloadAndResolveInspector=function(e,t){return e instanceof i.ProgramInspector?a.default.resolve(e):"object"==typeof e?this.createInspector(e):(t||this.loadWorkflow)(e).then(this.createInspector).catch(function(e){return a.default.reject(e)})},s.prototype.loadWorkflow=function(e){var t=e.match(/^(.*?)\/home\/item\.html\?id=(.*?)(\#.*)?$/);return null!=t&&(e=t[1]+"/sharing/rest/content/items/"+t[2]+"/data?f=json"),n.isArcGisApiVersion3x?a.default.resolve(o.default({url:e})):a.default.resolve(o.default(e)).then(function(e){return a.default.resolve(e.data)})},s.prototype.createInspector=function(t){return a.default.attempt(function(){if(t instanceof i.ProgramInspector)return t;var e=new i.ProgramInspector;return e.import(t),e})},r=s;function s(){this._cache=new c.Dictionary}t.ProgramInspectorFacility=r});