/*
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","../../Graphic","../../core/Error","../../core/maybe","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../../layers/support/commonProperties","../../layers/support/rasterFunctions/rasterProjectionHelper","./support/popupUtils"],(function(e,t,r,n,i,o,a,s,l,u,p,c,f){"use strict";const m=a=>{let s=function(t){function o(){var e;return(e=t.apply(this,arguments)||this)._rasterFieldPrefix="Raster.",e.layer=null,e.view=null,e.tileInfo=null,e}e._inheritsLoose(o,t);var a=o.prototype;return a._getfullExtent=function(){return this.projectFullExtent(this.view.spatialReference)},a.supportsSpatialReference=function(e){return!!this.projectFullExtent(e)},a.projectFullExtent=function(e){const t=i.unwrap(this.layer.fullExtent),r=c.getDefaultDatumTransformationForDataset(t,e,!1);return c.projectExtent(t,e,r)},a.fetchPopupFeatures=function(){var t=e._asyncToGenerator((function*(e,t){const{layer:o}=this;if(!e)throw new n("imageryTileLayerView:fetchPopupFeatures","Nothing to fetch without area",{layer:o});const{popupEnabled:a}=o,s=f.getFetchPopupTemplate(o,t);if(!a||i.isNone(s))throw new n("imageryTileLayerView:fetchPopupFeatures","Missing required popupTemplate or popupEnabled",{popupEnabled:a,popupTemplate:s});const l=[],{value:u,magdirValue:p}=yield o.identify(e,{timeExtent:this.timeExtent});let c="";if(u&&u.length){var m,y;c="imagery-tile"===o.type&&o.hasStandardTime()&&null!=u[0]?u.map((e=>o.getStandardTimeValue(e))).join(", "):u.join(", ");const e={ObjectId:0},t="Raster.ServicePixelValue";e[t]=this._formatAttributeValue(c,t);const n=null==(m=o.rasterInfo)||null==(y=m.attributeTable)?void 0:y.features;if(n&&n.length>0){const t=n.filter((e=>{const t=e.attributes.value||e.attributes.Value||e.attributes.VALUE;return String(t)===c}));if(t.length>0){const r=t[0];if(r)for(const t in r.attributes)if(r.attributes.hasOwnProperty(t)){const n=this._rasterFieldPrefix+t;e[n]=this._formatAttributeValue(r.attributes[t],n)}}}const i=o.rasterInfo.dataType;"vector-magdir"!==i&&"vector-uv"!==i||(e["Raster.Magnitude"]=null==p?void 0:p[0],e["Raster.Direction"]=null==p?void 0:p[1]);const a=new r(this.fullExtent.clone(),null,e);a.layer=o,a.sourceLayer=a.layer,l.push(a)}return l}));function o(e,r){return t.apply(this,arguments)}return o}(),a._formatAttributeValue=function(e,t){if("string"==typeof e){const r=this.layer.popupTemplate&&this.layer.popupTemplate.fieldInfos,n=this._getFieldInfo(r,t),i=n&&n.format;if(i){let t,r;return e.trim().includes(",")?(t=",",r=t+" ",this._formatDelimitedString(e,t,r,i)):e.trim().includes(" ")?(t=r=" ",this._formatDelimitedString(e,t,r,i)):this._formatNumberFromString(e,i)}}return e},a._getFieldInfo=function(e,t){if(!e||!e.length||!t)return;const r=t.toLowerCase();let n;return e.some((e=>!(!e.fieldName||e.fieldName.toLowerCase()!==r&&e.fieldName.toLowerCase()!==r.replace(/ /g,"_"))&&(n=e,!0))),n},a._formatDelimitedString=function(e,t,r,n){return e&&t&&r&&n?e.trim().split(t).map((e=>this._formatNumberFromString(e,n))).join(r):e},a._formatNumberFromString=function(e,t){if(!e||!t)return e;const r=Number(e);return isNaN(r)?e:t.format(r)},e._createClass(o,[{key:"fullExtent",get:function(){return this._getfullExtent()}},{key:"hasTilingEffects",get:function(){return this.layer.renderer&&"dynamicRangeAdjustment"in this.layer.renderer&&this.layer.renderer.dynamicRangeAdjustment}},{key:"datumTransformation",get:function(){return c.getDefaultDatumTransformationForDataset(i.unwrap(this.layer.fullExtent),this.view.spatialReference,!0)}}]),o}(a);return t.__decorate([o.property()],s.prototype,"layer",void 0),t.__decorate([o.property(p.combinedViewLayerTimeExtentProperty)],s.prototype,"timeExtent",void 0),t.__decorate([o.property()],s.prototype,"view",void 0),t.__decorate([o.property()],s.prototype,"fullExtent",null),t.__decorate([o.property()],s.prototype,"tileInfo",void 0),t.__decorate([o.property({readOnly:!0})],s.prototype,"hasTilingEffects",null),s=t.__decorate([u.subclass("esri.views.layers.ImageryTileLayerView")],s),s};return m}));
