/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{saveAs as e,save as r}from"./utils.js";import{createForItemWrite as t}from"../../portal/support/jsonContext.js";import{getWGS84ExtentForItem as a,removeTypeKeyword as s,typeKeyword as o}from"../../portal/support/portalItemUtils.js";import{saveResources as n}from"../../webdoc/support/resourceUtils.js";const i="Media Layer",u="media-layer-save",p="media-layer-save-as",l=["media-layer:unsupported-source"];function m(e){return{isValid:"media"===e.type,errorMessage:"Layer.type should be 'media'"}}function c(e){return t(e,"portal-item",!0)}function y(e){return Promise.resolve(e.layerJSON)}async function f(e,r){r.extent=e.fullExtent?await a(e.fullExtent):null}async function d(e,r){r.title||=e.title,await f(e,r),s(r,o.METADATA)}async function v(e,t){return r({layer:e,itemType:i,validateLayer:m,createJSONContext:e=>c(e),createItemData:y,errorNamePrefix:u,supplementalUnsupportedErrors:l,setItemProperties:f,saveResources:(r,t)=>n(e.resourceReferences,t)},t)}async function x(r,t,a){return e({layer:r,itemType:i,validateLayer:m,createJSONContext:e=>c(e),createItemData:y,errorNamePrefix:p,supplementalUnsupportedErrors:l,newItem:t,setItemProperties:d,saveResources:(e,t)=>n(r.resourceReferences,t)},a)}export{v as save,x as saveAs};
