!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 a,W=e("tslib"),r=e("../core/ChannelProvider"),n=e("../../Hooks"),k=e("../../Validation"),i=e("./MapProvider"),I=e("./runUtils"),A=e("./shared"),N=e("../../Errors"),i=((a=o).prototype.execute=function(P,E,U,x){return W.__awaiter(this,void 0,void 0,function(){var t,r,n,a,i,o,s,l,c,u,p,m,d,f,v,g,h,b,w,y,_;return W.__generator(this,function(e){switch(e.label){case 0:if(s=k.validation.string("url",P.url,k.validation.never),t=k.validation.number("scale",P.scale,void 0),r=k.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=I.getServiceUrl(s.url,"printing"),i&&"public"!==s.access?[4,I.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++)f=d[m],(v=P.parameters[f])&&(g=v instanceof Array,p.push({name:f,containsMultipleValues:g,value:g?void 0:v,values:g?v:void 0}));return[4,I.getMapControlNames(n,c,u,l,o)];case 4:return(h=e.sent())&&h.length?(h[0],[4,this.getWebmapParameters(x,h[0],t,P.extent,E.ambient.trivia)]):[3,6];case 5:if((h=e.sent())&&h.length)for(b=0,w=h;b<w.length;b++)y=w[b],p.push(y);e.label=6;case 6:return _={template:{itemId:n.itemId,portalUrl:n.portalUrl,title:r},parameters:p},[4,I.runJob(c,u,_,l)];case 7:return _=e.sent(),_=_.response.ticket,[4,I.checkResult(c,u,_,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 W.__awaiter(this,void 0,void 0,function(){var t,r,n,a,i;return W.__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 W.__awaiter(this,void 0,void 0,function(){return W.__generator(this,function(e){throw console.warn("getWebmap needs to be overridden by a client implementation."),new N.ActivityNotImplementedError(a.action)})})},o.prototype.getWgs84Extent=function(e){return W.__awaiter(this,void 0,void 0,function(){return W.__generator(this,function(e){throw console.warn("getWgs84Extent needs to be overridden by a client implementation."),new N.ActivityNotImplementedError(a.action)})})},o.prototype.prepareWebmapParameters=function(e,t,r,n){throw console.warn("prepareWebmapParameters needs to be overriden by a client implementation."),new N.ActivityNotImplementedError(a.action)},o.action="gcx:wf:geocortex::RunPrint",o.suite="gcx:wf:builtin",a=W.__decorate([n.activateTwo(r.ChannelProvider,i.MapProvider)],o));function o(){}t.RunPrint=i});