/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../chunks/_rollupPluginBabelHelpers","../../../chunks/tslib.es6","../../../core/Collection","../../../core/Logger","../../../core/maybe","../../../core/reactiveUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../../../layers/support/layerUtils","./LayerView3D","./TiledLayerView3D","../../layers/LayerView","../../layers/RefreshableLayerView"],(function(e,t,i,r,o,s,n,a,l,c,h,u,d,p,y,f){"use strict";const m=r.getLogger("esri.views.3d.layers.WMTSLayerView3d");let g=function(t){function r(){var e;return(e=t.apply(this,arguments)||this).type="wmts-3d",e}e._inheritsLoose(r,t);var n=r.prototype;return n._getCompatibleTileInfoMatrixSet=function(e,t=!1){const r=u.getTileMaxtrixSetFromActiveLayer(this.layer);if(o.isSome(r)){if(i.isCollection(r)){const i=r.find((i=>{const r=e(i);return o.isSome(r)&&(t?m.error("The selected tile matrix set is not compatible with the view",r):this.addResolvingPromise(Promise.reject(r))),null==r}));return i}const s=e(r);return o.isSome(s)&&(t?m.error("The selected tile matrix set is not compatible with the view",s):this.addResolvingPromise(Promise.reject(s))),r}return null},n.initialize=function(){this._getCompatibleTileInfoMatrixSet((e=>this._getTileInfoSupportError(e.tileInfo,e.fullExtent)));const e=s.whenOnce((()=>{var e,t;return null==(e=this.view)||null==(t=e.basemapTerrain)?void 0:t.tilingSchemeLocked})).then((()=>{const e=this._getCompatibleTileInfoMatrixSet((e=>this._getTileInfoSupportError(e.tileInfo,e.fullExtent)||this._getTileInfoCompatibilityError(e.tileInfo,this.view.basemapTerrain.tilingScheme)));o.isNone(e)||(this.layer.activeLayer.tileMatrixSetId!==e.id&&(this.layer.activeLayer.tileMatrixSetId=e.id),this.tileInfo=e.tileInfo,this.layer.fullExtent=e.fullExtent)}));this.addResolvingPromise(e),this.when((()=>this._initialized()))},n.refresh=function(){this.emit("data-changed")},n.canResume=function(){if(!t.prototype.canResume.call(this))return!1;const e=this.layer.activeLayer.tileMatrixSet;return e&&!this._getTileInfoError(e.tileInfo,e.fullExtent)},n.doRefresh=function(){var t=e._asyncToGenerator((function*(){this.suspended||this.emit("data-changed")}));function i(){return t.apply(this,arguments)}return i}(),n._initialized=function(){this.updatingHandles.add((()=>{var e,t;return null==(e=this.layer)||null==(t=e.activeLayer)?void 0:t.styleId}),(()=>this.refresh())),this.updatingHandles.add((()=>{var e;return null==(e=this.layer)?void 0:e.activeLayer}),(e=>{const t=this._getCompatibleTileInfoMatrixSet((e=>this._getTileInfoSupportError(e.tileInfo,e.fullExtent)||this._getTileInfoCompatibilityError(e.tileInfo,this.view.basemapTerrain.tilingScheme)),!0);o.isSome(t)&&e.tileMatrixSetId!==t.id&&(this.layer.activeLayer.tileMatrixSetId=t.id),this.notifyChange("suspended"),this.canResume()&&this.refresh()}))},n._getTileInfoError=function(e,t){return this._getTileInfoSupportError(e,t)||this._getTileInfoCompatibilityError(e,this.view.basemapTerrain.tilingScheme)},e._createClass(r,[{key:"hasMixedImageFormats",get:function(){return!0}}]),r}(f(p.TiledLayerView3D(d.LayerView3D(y))));t.__decorate([n.property({readOnly:!0})],g.prototype,"hasMixedImageFormats",null),t.__decorate([n.property()],g.prototype,"layer",void 0),t.__decorate([n.property()],g.prototype,"suspended",void 0),g=t.__decorate([h.subclass("esri.views.3d.layers.WMTSLayerView3D")],g);return g}));
