!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require,exports):"function"==typeof define&&define.amd&&define(["require","exports","tslib","../core/ChannelProvider","../../Hooks","../../Validation","./MapProvider","./runUtils","./shared","../../Errors"],e)}(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n,T=e("tslib"),r=e("../core/ChannelProvider"),a=e("../../Hooks"),S=e("../../Validation"),o=e("./MapProvider"),j=e("./runUtils"),C=e("./shared"),i=e("../../Errors"),o=((n=s).prototype.execute=function(M,A,N,R){return T.__awaiter(this,void 0,void 0,function(){var t,r,a,n,o,i,s,l,c,u,p,d,m,f,v,h,b,g,w,y,_,P,U,W,x,I,k,E;return T.__generator(this,function(e){switch(e.label){case 0:if(l=S.validation.string("url",M.url,S.validation.never),t=S.validation.boolean("includeMap",M.includeMap,!1),r=C.parsePortalItemUrl(l),a=S.validation.array("webmapParameters",M.webmapParameters,[]),n=S.validation.string("resultFileName",M.resultFileName,"Report"),o=S.validation.array("dataSources",M.dataSources,void 0),r&&(s=this.getAuthenticationToken(r.portalUrl),i=C.getPortalDataUrl(r,s)),!r||!r.itemId)throw Error("Unable to get item ID for report '"+l+".");if(!i)throw Error("Unable to get item URL for report '"+l+".");return l=A.cancellationToken,[4,C.getPortalItem(i,N,l)];case 1:return U=e.sent(),c=N.create(),l.finally(function(){c.cancel()}),u=j.getServiceUrl(U.url,"reporting"),s&&"public"!==U.access?[4,j.getServiceToken(u,r.portalUrl,s,c)]:[3,3];case 2:p=e.sent(),e.label=3;case 3:if(d=[{name:"FeatureIds",containsMultipleValues:!0,value:void 0,values:M.featureIds||[]}],M.parameters)for(m=0,f=Object.keys(M.parameters);m<f.length;m++)v=f[m],(h=M.parameters[v])&&(b=h instanceof Array,d.push({name:v,containsMultipleValues:b,value:b?void 0:h,values:b?h:void 0}));if(!a.length)return[3,4];for(g=0,w=a;g<w.length;g++)for(y=w[g],W=this.prepareWebmapParameters(y.mapName,y.webmap,y.scale,y.extent),_=0,P=W;_<P.length;_++)k=P[_],d.push(k);return[3,7];case 4:return t?[4,j.getMapControlNames(r,u,p,c,l)]:[3,7];case 5:return(U=e.sent())&&U.length?[4,this.getWebmapParameters(R,U[0],A.ambient.trivia)]:[3,7];case 6:if((W=e.sent())&&W.length)for(x=0,I=W;x<I.length;x++)k=I[x],d.push(k);e.label=7;case 7:return E={template:{itemId:r.itemId,portalUrl:r.portalUrl,title:n},parameters:d,data:o},[4,j.runJob(u,p,E,c)];case 8:return E=e.sent(),E=E.response.ticket,[4,j.checkResult(u,p,E,1e3,c,l)];case 9:return[2,{href:e.sent()}]}})})},s.prototype.getAuthenticationToken=function(e){return C.getAuthenticationToken(e)},s.prototype.getWebmap=function(e,t,r){return T.__awaiter(this,void 0,void 0,function(){return T.__generator(this,function(e){throw console.warn("getWebmap needs to be overridden by a client implementation."),new i.ActivityNotImplementedError(n.action)})})},s.prototype.getWebmapExtent=function(e){return T.__awaiter(this,void 0,void 0,function(){return T.__generator(this,function(e){throw console.warn("getWebmapExtent needs to be overridden by a client implementation."),new i.ActivityNotImplementedError(n.action)})})},s.prototype.getWebmapParameters=function(n,o,i){return T.__awaiter(this,void 0,void 0,function(){var t,r,a;return T.__generator(this,function(e){switch(e.label){case 0:return[4,(t=n.create()).load()];case 1:return e.sent(),[4,this.getWebmap(t,t.getScale(),i)];case 2:return r=e.sent(),[4,this.getWebmapExtent(t)];case 3:return a=e.sent(),[2,this.prepareWebmapParameters(o,r,0,a)]}})})},s.prototype.prepareWebmapParameters=function(e,t,r,a){throw console.warn("prepareWebmapParameters needs to be overriden by a client implementation."),new i.ActivityNotImplementedError(n.action)},s.action="gcx:wf:geocortex::RunReport",s.suite="gcx:wf:builtin",n=T.__decorate([a.activateTwo(r.ChannelProvider,o.MapProvider)],s));function s(){}t.RunReport=o});