var RunPrint_1;import{__decorate}from"tslib";import{ChannelProvider}from"../core/ChannelProvider.js";import{activateTwo}from"../../Hooks.js";import{validation}from"../../Validation.js";import{MapProvider}from"./MapProvider.js";import{checkResult,getMapControlNames,getServiceToken,runJob,getServiceUrl}from"./runUtils.js";import{getAuthenticationToken,getPortalDataUrl,getPortalItem,parsePortalItemUrl}from"./shared.js";import{ActivityInputError,ActivityNotImplementedError,GenericActivityError}from"../../Errors.js";let RunPrint=RunPrint_1=class{async execute(e,t,r,a){var n=validation.string("url",e.url,validation.never),i=validation.number("scale",e.scale,void 0),o=validation.string("resultFileName",e.resultFileName,"Print");if(i<=0)throw new ActivityInputError("scale","Scale must be greater than zero.");var l=parsePortalItemUrl(n);let s,c;if(l&&(c=this.getAuthenticationToken(l.portalUrl),s=getPortalDataUrl(l,c)),!l||!l.itemId)throw Error(`Unable to get item ID for print template '${n}.`);if(!s)throw Error(`Unable to get item URL for print template '${n}.`);const m=t.cancellationToken;n=await getPortalItem(s,r,m);const p=r.create();m.finally(function(){p.cancel()});r=getServiceUrl(n.url,"printing");let u;c&&"public"!==n.access&&(u=await getServiceToken(r,l.portalUrl,c,p));const v=[];if(e.parameters)for(const P of Object.keys(e.parameters)){var g,d=e.parameters[P];d&&(g=d instanceof Array,v.push({name:P,containsMultipleValues:g,value:g?void 0:d,values:g?d:void 0}))}n=await getMapControlNames(l,r,u,p,m);if(n&&n.length){n[0];t=await this.getWebmapParameters(a,n[0],i,e.extent,t.ambient.trivia);if(t&&t.length)for(const w of t)v.push(w)}o={template:{itemId:l.itemId,portalUrl:l.portalUrl,title:o},parameters:v},o=(await runJob(r,u,o,p)).response.ticket;return{href:await checkResult(r,u,o,1e3,p,m)}}getAuthenticationToken(e){return getAuthenticationToken(e)}async getWebmapParameters(e,t,r,a,n){const i=e.create();if(await i.load(),!i.map)throw new GenericActivityError("No map available. Unable to generate webmap parameters.");e=r||i.getScale(),a=a||i.getExtent(),n=await this.getWebmap(i,e,n),a=await this.getWgs84Extent(a);return this.prepareWebmapParameters(t,n,r||0,a)}async getWebmap(e,t,r){throw console.warn("getWebmap needs to be overridden by a client implementation."),new ActivityNotImplementedError(RunPrint_1.action)}async getWgs84Extent(e){throw console.warn("getWgs84Extent needs to be overridden by a client implementation."),new ActivityNotImplementedError(RunPrint_1.action)}prepareWebmapParameters(e,t,r,a){throw console.warn("prepareWebmapParameters needs to be overriden by a client implementation."),new ActivityNotImplementedError(RunPrint_1.action)}};RunPrint.action="gcx:wf:geocortex::RunPrint",RunPrint.suite="gcx:wf:builtin",RunPrint=RunPrint_1=__decorate([activateTwo(ChannelProvider,MapProvider)],RunPrint);export{RunPrint};