/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{saveAs as e,save as t}from"./utils.js";import{getWGS84ExtentForItem as r,removeTypeKeyword as a,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){return f(e,t),Promise.resolve()}async function y(e,t){const{parsedUrl:s,title:i,fullExtent:o}=e;t.url=s.path,t.title||=i,t.extent=o?await r(o):null,a(t,n.METADATA),f(e,t)}function f(e,t){s(t,n.DYNAMIC);const r=e.sublayers?.length??0;i(t,n.MULTI_LAYER,r>1),i(t,n.SINGLE_LAYER,1===r)}async function v(e,r){return t({layer:e,itemType:o,validateLayer:c,createItemData:p,errorNamePrefix:l,setItemProperties:u},r)}async function I(t,r,a){return e({layer:t,itemType:o,validateLayer:c,createItemData:p,errorNamePrefix:m,newItem:r,setItemProperties:y},a)}export{v as save,I as saveAs};
