import e from"@arcgis/core/geometry/Extent";import t from"@arcgis/core/portal/Portal";import r from"@arcgis/core/portal/PortalItem";import{isWebTileLayer as i,isWMTSLayer as o}from"../utilities/_layers.js";import{checkArg as a}from"../utilities/checkArg.js";import{deepClone as l}from"../utilities/object.js";import{TileInfo as s}from"./TileInfo.js";import{WMTSInfo as n}from"./WMTSInfo.js";import{ERR_LAYER_TYPE_MISMATCH as p,applyLayerBaseToEsriApiLayer as m,applyBasemapLayerToEsriApiLayer as y,applyOperationalLayerToEsriApiLayer as f,fromEsriApiLayerToLayerBase as u,fromEsriApiLayerToOperationalLayer as c}from"./_layerHelper.js";export var WebTileLayer;!function(T){async function I(u,c,T){a("layerJson",u).isNotMissing();const I=u.layerType||u.type;a("layerJson.layerType",I).satisfies((e=>!e||"WebTiledLayer"===e||"OpenStreetMap"===e),p),a("layer",c).isNotMissing().satisfies((e=>i(e)||o(e)),p),m(u,c),y(u,c),f(u,c),u.hasOwnProperty("copyright")&&null!=u.copyright&&(c.copyright=u.copyright),u.hasOwnProperty("fullExtent")&&(c.fullExtent=e.fromJSON(u.fullExtent)),u.hasOwnProperty("itemId")&&o(c)&&(c.portalItem?c.portalItem.id=u.itemId:c.portalItem=new r({id:u.itemId,portal:T||t.getDefault()})),i(c)?(u.hasOwnProperty("subDomains")&&(c.subDomains=l(u.subDomains)),u.hasOwnProperty("templateUrl")&&(c.urlTemplate=u.templateUrl),u.hasOwnProperty("tileInfo")&&null!=u.tileInfo&&(c.tileInfo=s.toEsriApiTileInfo(u.tileInfo))):(a("layerJson.layerType",I).satisfies((e=>"WebTiledLayer"===e),p),u.hasOwnProperty("templateUrl")&&null!=u.templateUrl&&(c.serviceMode=u.templateUrl.includes("?")?"KVP":"RESTful"),u.wmtsInfo&&await n.applyToEsriApiLayer(u.wmtsInfo,c))}function g(e){return void 0!==e.wmtsInfo}T.toEsriApiLayer=async function(e){a("layerJson",e).isNotMissing();const t=e.layerType||e.type;a("layerJson.layerType",t).satisfies((e=>!e||"WebTiledLayer"===e),p);const r=g(e)?new((await import("@arcgis/core/layers/WMTSLayer")).default):new((await import("@arcgis/core/layers/WebTileLayer")).default);return await I(e,r),r},T.applyToEsriApiLayer=I,T.fromEsriApiLayer=function(e){a("layer",e).isNotMissing();const t={...u(e),...c(e),layerType:"WebTiledLayer"};return delete t.showLegend,e.copyright&&(t.copyright=e.copyright),e.fullExtent&&(t.fullExtent=e.fullExtent.toJSON()),i(e)?(e.subDomains&&(t.subDomains=l(e.subDomains)),e.urlTemplate&&(t.templateUrl=e.urlTemplate),e.tileInfo&&(t.tileInfo=s.fromEsriApiTileInfo(e.tileInfo))):(t.wmtsInfo=n.fromEsriApiLayer(e),e.customParameters&&(t.wmtsInfo.customParameters=e.customParameters),e.portalItem&&(t.itemId=e.portalItem.id??void 0)),t},T.isTileLayerWMTS=g}(WebTileLayer||(WebTileLayer={}));