define(["require","exports","tslib","../core/ChannelProvider","../../Hooks","../../Validation","./MapProvider","./runUtils","./shared","../../Errors"],function(e,t,T,r,a,S,n,C,F,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,n=((i=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,m,d,v,h,f,g,b,w,_,y,P,W,I,U,k,x,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=F.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=F.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,F.getPortalItem(i,N,l)];case 1:return W=e.sent(),c=N.create(),l.finally(function(){c.cancel()}),u=C.getServiceUrl(W.url,"reporting"),s&&"public"!==W.access?[4,C.getServiceToken(u,r.portalUrl,s,c)]:[3,3];case 2:p=e.sent(),e.label=3;case 3:if(m=[{name:"FeatureIds",containsMultipleValues:!0,value:void 0,values:M.featureIds||[]}],M.parameters)for(d=0,v=Object.keys(M.parameters);d<v.length;d++)h=v[d],(f=M.parameters[h])&&(g=f instanceof Array,m.push({name:h,containsMultipleValues:g,value:g?void 0:f,values:g?f:void 0}));if(!a.length)return[3,4];for(b=0,w=a;b<w.length;b++)for(_=w[b],I=this.prepareWebmapParameters(_.mapName,_.webmap,_.scale,_.extent),y=0,P=I;y<P.length;y++)x=P[y],m.push(x);return[3,7];case 4:return t?[4,C.getMapControlNames(r,u,p,c,l)]:[3,7];case 5:return(W=e.sent())&&W.length?[4,this.getWebmapParameters(R,W[0],A.ambient.trivia)]:[3,7];case 6:if((I=e.sent())&&I.length)for(U=0,k=I;U<k.length;U++)x=k[U],m.push(x);e.label=7;case 7:return E={template:{itemId:r.itemId,portalUrl:r.portalUrl,title:n},parameters:m,data:o},[4,C.runJob(u,p,E,c)];case 8:return E=e.sent(),E=E.response.ticket,[4,C.checkResult(u,p,E,1e3,c,l)];case 9:return[2,{href:e.sent()}]}})})},s.prototype.getAuthenticationToken=function(e){return F.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 o.ActivityNotImplementedError(i.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 o.ActivityNotImplementedError(i.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 o.ActivityNotImplementedError(i.action)},s.action="gcx:wf:geocortex::RunReport",s.suite="gcx:wf:builtin",i=T.__decorate([a.activateTwo(r.ChannelProvider,n.MapProvider)],s));function s(){}t.RunReport=n});