/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{getPrimaryRasters as e}from"../raster/datasets/datasetUtils.js";import{saveAs as t,save as r}from"./utils.js";import{toggleTypeKeyword as a,typeKeyword as s,getWGS84ExtentForItem as i,removeTypeKeyword as l}from"../../portal/support/portalItemUtils.js";const y="Image Service",n="imagery-layer-save",o="imagery-layer-save-as",m="imagery-tile-layer-save",c="imagery-tile-layer-save-as",p="WCS",g="wcs-layer-save",u="wcs-layer-save-as";function v(t){if("imagery"===t.type||"wcs"===t.type)return{isValid:!0};const{raster:r}=t,a=e(r)[0];return{isValid:"RasterTileServer"===a?.datasetFormat&&("Raster"===a.tileType||"Map"===a.tileType),errorMessage:"imagery tile layer should be created from a tiled image service."}}function f(e){const t=e.layerJSON;return Promise.resolve(t&&Object.keys(t).length?t:null)}function d(e,t){a(t,s.CHARTS,!!e.charts?.length)}async function T(e,t){const{parsedUrl:r,title:y,fullExtent:n}=e;t.url=r.path,t.title||=y;try{t.extent=await i(n)}catch{t.extent=void 0}l(t,s.METADATA),a(t,s.TILED_IMAGERY,"imagery-tile"===e.type),a(t,s.CHARTS,!!e.charts?.length)}async function I(e,t){const a="imagery"===e.type?n:"imagery-tile"===e.type?m:g,s="wcs"===e.type?p:y;return r({layer:e,itemType:s,validateLayer:v,createItemData:f,errorNamePrefix:a,setItemProperties:d},t)}async function h(e,r,a){const s="imagery"===e.type?o:"imagery-tile"===e.type?c:u,i="wcs"===e.type?p:y;return t({layer:e,itemType:i,validateLayer:v,createItemData:f,errorNamePrefix:s,newItem:r,setItemProperties:T},a)}export{I as save,h as saveAs};
