/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import{JSONSupport as t}from"../../core/JSONSupport.js";import{property as i,subclass as n}from"../../core/accessorSupport/decorators.js";import{fixTimeInfoFields as r}from"../support/fieldUtils.js";import{cacheIsOutOfSync as s}from"../support/sceneLayerCacheUtils.js";import o from"../support/TimeInfo.js";import l from"../../time/TimeExtent.js";import m from"../../time/TimeInterval.js";const a=t=>{const a=t;let d=class extends a{constructor(){super(...arguments),this.serviceTimeInfo=null}get timeInfo(){const e=this.associatedLayer?.timeInfo;if(null==e)return null;const t=e.clone();return r(t,this.fieldsIndex),t}set timeInfo(e){r(e,this.fieldsIndex),this._override("timeInfo",e)}get timeExtent(){return this.associatedLayer?.timeExtent}set timeExtent(e){this._override("timeExtent",e)}get timeOffset(){return this.associatedLayer?.timeOffset}set timeOffset(e){this._override("timeOffset",e)}get datesInUnknownTimezone(){return this.associatedLayer?.datesInUnknownTimezone??!1}set datesInUnknownTimezone(e){this._override("datesInUnknownTimezone",e)}async loadTimeInfoFromService(e){const{serviceTimeInfo:t}=this;if(null==t)return;const{startTimeField:i,endTimeField:n}=t;if(null==i&&null==n)return;if(s({associatedLayer:this.associatedLayer,serviceUpdateTimeStamp:this.serviceUpdateTimeStamp}))return;const r=async t=>{let n=null;try{const i=await(this.fetchStatistics?.(t,e));n=i?.stats}catch{}if(null==n)return null;const{minTimeStr:r,min:s,maxTimeStr:o,max:l}=n,m=t===i?r??s:o??l;return null!=m?new Date(m):null},[m,a]=await Promise.all([r(i),r(n)]);if(null!=i&&null==m||null!=n&&null==a)return;const c=new l({start:m,end:a});this.setAtOrigin("timeInfo",new o({endField:n,startField:i,fullTimeExtent:c}),"service")}};return e([i({type:o,json:{read:!1,write:!1}})],d.prototype,"timeInfo",null),e([i({type:l,json:{read:!1,write:!1}})],d.prototype,"timeExtent",null),e([i({type:m,json:{read:!1,write:!1}})],d.prototype,"timeOffset",null),e([i({type:Boolean,nonNullable:!0,json:{read:!1,write:!1}})],d.prototype,"datesInUnknownTimezone",null),e([i({type:c,readOnly:!0,json:{read:{source:"timeInfo"}},clonable:!1})],d.prototype,"serviceTimeInfo",void 0),d=e([n("esri.layers.mixins.TemporalSceneLayer")],d),d};let c=class extends t{constructor(){super(...arguments),this.endTimeField=null,this.startTimeField=null}};e([i({type:String})],c.prototype,"endTimeField",void 0),e([i({type:String})],c.prototype,"startTimeField",void 0),c=e([n("esri.layers.mixins.TemporalSceneLayer.SceneServiceTimeInfo")],c);export{a as TemporalSceneLayer};
