/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{saveAs as e,save as t}from"./utils.js";import{getWGS84ExtentForItem as a,removeTypeKeyword as r,typeKeyword as n,addTypeKeyword as s,toggleTypeKeyword as i}from"../../portal/support/portalItemUtils.js";const o="Map Service",l="map-image-layer-save",m="map-image-layer-save-as";function c(e){return{isValid:"map-image"===e.type&&!e.sourceJSON?.tileInfo,errorMessage:"Layer.type should be 'map-image' and reference a dynamic (non-cached) map service"}}function p(e){const t=e.layerJSON;return Promise.resolve(t&&Object.keys(t).length?t:null)}function u(e,t){f(e,t)}async function y(e,t){const{parsedUrl:s,title:i,fullExtent:o}=e;t.url=s.path,t.title||=i,t.extent=o?await a(o):null,r(t,n.METADATA),f(e,t)}function f(e,t){s(t,n.DYNAMIC);const a=e.sublayers?.length??0;i(t,n.MULTI_LAYER,a>1),i(t,n.SINGLE_LAYER,1===a)}async function I(e,a){return t({layer:e,itemType:o,validateLayer:c,createItemData:p,errorNamePrefix:l,setItemProperties:u},a)}async function v(t,a,r){return e({layer:t,itemType:o,validateLayer:c,createItemData:p,errorNamePrefix:m,newItem:a,setItemProperties:y},r)}export{I as save,v as saveAs};
