/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../core/Error","../../../core/maybe","../../../core/promiseUtils","../../../layers/support/layerUtils","../../../views/ViewingMode","../../../views/3d/terrain/terrainUtils","../../../views/3d/terrain/TilingScheme","../../../views/support/spatialReferenceSupport"],(function(e,t,i,a,n,r,o,l,s,p){"use strict";function c(e){return u.apply(this,arguments)}function u(){return(u=t._asyncToGenerator((function*(e,t={}){yield d(e,t),n.throwIfAborted(t)}))).apply(this,arguments)}function f(e){return m.apply(this,arguments)}function m(){return(m=t._asyncToGenerator((function*(e,t={}){const{basemap:i,view:a}=e;if(n.throwIfAborted(t),"spatialReferenceLocked"in a&&!a.spatialReferenceLocked)return;if(yield i.load(t),n.throwIfAborted(t),0===i.baseLayers.length)return;const o=i.baseLayers.getItemAt(0);if(!r.isTiledLayer(o))return;if(i.spatialReference){if(a.spatialReference.equals(i.spatialReference))return;y()}yield o.load(t),n.throwIfAborted(t);const l=(("supportedSpatialReferences"in o?o.supportedSpatialReferences:null)||["tileInfo"in o?o.tileInfo.spatialReference:null]).filter(Boolean);0!==l.length&&l.every((e=>!a.spatialReference.equals(e)))&&y()}))).apply(this,arguments)}function y(){throw new i("basemap-compatibility:incompatible-spatial-reference","Basemap spatial reference is not compatible with the view")}function d(e,t){return b.apply(this,arguments)}function b(){return(b=t._asyncToGenerator((function*(e,t){const{basemap:a,view:n}=e;if(yield a.load(t),0===a.baseLayers.length)return;const o=a.baseLayers.concat(a.referenceLayers).toArray().filter((e=>!r.isBasemapSupportedLayer(e))).map((e=>new i("basemap-compatibility:unsupported-basemap-layer-type","Unsupported basemap layer type ${operationalLayerType}",{layer:e,operationalLayerType:e.operationalLayerType||"unknown"})));if(o.length)throw o[0];const l=a.baseLayers.getItemAt(0);if(r.isBasemapSupportedLayer(l)){try{yield l.load(t)}catch(s){const e="basemap-compatibility:unknown-error",t="Unknown basemap compatibility error",{name:a=e,message:n=t,details:r}=s;throw new i(a,n,r)}h(l,n)}}))).apply(this,arguments)}function h(e,t){const n=t.state.viewingMode;if(!n)return;let r,c;if("wmts"===(null==e?void 0:e.type)){const o=l.getTileInfoAndExtentFromWMTSLayer(e,t.spatialReference,n);if(a.isNone(o.tileInfo))throw new i("basemapgalleryitem:tiling-scheme-incompatible","Basemap tiling scheme is incompatible with the view");r=o.tileInfo,c=o.fullExtent}else r=e.tileInfo,c=e.fullExtent;if(a.isNone(r))return;if(!p.isSpatialReferenceSupported(r.spatialReference,n))throw new i(`basemapgalleryitem:spatial-reference-unsupported-${o.stringFromViewingMode(n)}`,`Basemap spatial reference is unsupported in ${o.stringFromViewingMode(n)} mode`);const u=r.spatialReference.isGeographic,f="vector-tile"===(null==e?void 0:e.type)?r.getOrCreateCompatible(256,u?1:2):null;if(n===o.ViewingMode.Global){let t=l.checkIfTileInfoSupportedForView(r,c,null,n);if(t&&"vector-tile"===(null==e?void 0:e.type)&&a.isSome(c)&&f&&!l.checkIfTileInfoSupportedForView(f,c,null,n)&&(t=null),t){const e=r.spatialReference.isWebMercator?"web-mercator":"wgs84";throw new i(`basemapgalleryitem:tiling-scheme-unsupported-${e}-global`,"Basemap tiling scheme is unsupported in global mode",{error:t})}}else if(s.TilingScheme.checkUnsupported(r))throw new i("basemapgalleryitem:tiling-scheme-unsupported-local","Basemap tiling scheme is unsupported in local mode");const m=t.get("basemapTerrain.tilingScheme");if(m&&!m.compatibleWith(r)&&("vector-tile"!==(null==e?void 0:e.type)||!f||!m.compatibleWith(f)))throw new i("basemapgalleryitem:tiling-scheme-incompatible","Basemap tiling scheme is incompatible with the view")}e.default2DCompatibility=f,e.default3DCompatibility=c,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
