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