define(["require","exports","tslib","../core/ChannelProvider","../../Hooks","../../Validation","./MapProvider","./runUtils","./shared","../../Errors"],function(e,t,x,r,n,I,a,k,A,N){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,a=((i=o).prototype.execute=function(P,E,U,W){return x.__awaiter(this,void 0,void 0,function(){var t,r,n,a,i,o,s,l,c,u,p,m,d,g,v,h,f,b,w,_,y;return x.__generator(this,function(e){switch(e.label){case 0:if(s=I.validation.string("url",P.url,I.validation.never),t=I.validation.number("scale",P.scale,void 0),r=I.validation.string("resultFileName",P.resultFileName,"Print"),t<=0)throw new N.ActivityInputError("scale","Scale must be greater than zero.");if((n=A.parsePortalItemUrl(s))&&(i=this.getAuthenticationToken(n.portalUrl),a=A.getPortalDataUrl(n,i)),!n||!n.itemId)throw Error("Unable to get item ID for print template '"+s+".");if(!a)throw Error("Unable to get item URL for print template '"+s+".");return o=E.cancellationToken,[4,A.getPortalItem(a,U,o)];case 1:return s=e.sent(),l=U.create(),o.finally(function(){l.cancel()}),c=k.getServiceUrl(s.url,"printing"),i&&"public"!==s.access?[4,k.getServiceToken(c,n.portalUrl,i,l)]:[3,3];case 2:u=e.sent(),e.label=3;case 3:if(p=[],P.parameters)for(m=0,d=Object.keys(P.parameters);m<d.length;m++)g=d[m],(v=P.parameters[g])&&(h=v instanceof Array,p.push({name:g,containsMultipleValues:h,value:h?void 0:v,values:h?v:void 0}));return[4,k.getMapControlNames(n,c,u,l,o)];case 4:return(f=e.sent())&&f.length?(f[0],[4,this.getWebmapParameters(W,f[0],t,P.extent,E.ambient.trivia)]):[3,6];case 5:if((f=e.sent())&&f.length)for(b=0,w=f;b<w.length;b++)_=w[b],p.push(_);e.label=6;case 6:return y={template:{itemId:n.itemId,portalUrl:n.portalUrl,title:r},parameters:p},[4,k.runJob(c,u,y,l)];case 7:return y=e.sent(),y=y.response.ticket,[4,k.checkResult(c,u,y,1e3,l,o)];case 8:return[2,{href:e.sent()}]}})})},o.prototype.getAuthenticationToken=function(e){return A.getAuthenticationToken(e)},o.prototype.getWebmapParameters=function(o,s,l,c,u){return x.__awaiter(this,void 0,void 0,function(){var t,r,n,a,i;return x.__generator(this,function(e){switch(e.label){case 0:return[4,(t=o.create()).load()];case 1:if(e.sent(),!t.map)throw new N.GenericActivityError("No map available. Unable to generate webmap parameters.");return i=l||t.getScale(),r=c||t.getExtent(),[4,this.getWebmap(t,i,u)];case 2:return n=e.sent(),[4,this.getWgs84Extent(r)];case 3:return a=e.sent(),i=l||0,[2,this.prepareWebmapParameters(s,n,i,a)]}})})},o.prototype.getWebmap=function(e,t,r){return x.__awaiter(this,void 0,void 0,function(){return x.__generator(this,function(e){throw console.warn("getWebmap needs to be overridden by a client implementation."),new N.ActivityNotImplementedError(i.action)})})},o.prototype.getWgs84Extent=function(e){return x.__awaiter(this,void 0,void 0,function(){return x.__generator(this,function(e){throw console.warn("getWgs84Extent needs to be overridden by a client implementation."),new N.ActivityNotImplementedError(i.action)})})},o.prototype.prepareWebmapParameters=function(e,t,r,n){throw console.warn("prepareWebmapParameters needs to be overriden by a client implementation."),new N.ActivityNotImplementedError(i.action)},o.action="gcx:wf:geocortex::RunPrint",o.suite="gcx:wf:builtin",i=x.__decorate([n.activateTwo(r.ChannelProvider,a.MapProvider)],o));function o(){}t.RunPrint=a});