/*
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/Accessor","../../core/Handles","../../core/Logger","../../core/maybe","../../core/reactiveUtils","../../core/accessorSupport/decorators/property","../../core/accessorSupport/decorators/subclass","../../views/3d/environment/CloudyWeather","../../views/3d/environment/FoggyWeather","../../views/3d/environment/RainyWeather","../../views/3d/environment/SnowyWeather","../../views/3d/environment/SunnyWeather","../../views/3d/environment/weather","./enums"],(function(e,t,r,n,o,i,s,a,h,c,y,l,u,p,d,w){"use strict";const v=o.getLogger("esri.widgets.Weather.WeatherViewModel");let _=function(t){function r(e){var r;return(r=t.call(this,e)||this).view=null,r._handles=new n,r._settingWeather=!1,r._weatherByType={sunny:new p,cloudy:new c,rainy:new l,snowy:new u,foggy:new y},r}e._inheritsLoose(r,t);var o=r.prototype;return o.initialize=function(){this._handles.add([s.watch((()=>this.current),(e=>{this._settingWeather||i.isNone(e)||(this._weatherByType={...this._weatherByType,[e.type]:e})}),s.syncAndInitial)])},o.destroy=function(){this._handles=i.destroyMaybe(this._handles)},o.setWeatherByType=function(e){if(!d.validateWeatherType(e,v))return;const t=this._environment;i.isSome(t)&&(this._settingWeather=!0,t.weather=this._weatherByType[e],this._settingWeather=!1)},o.setSnowCoverEnabled=function(e){const t=this.current;"snowCover"in t&&(t.snowCover=e?"enabled":"disabled")},e._createClass(r,[{key:"state",get:function(){const e=this.view;return i.isNone(e)||!e.ready?w.WeatherState.Disabled:i.isSome(this.error)?this.error===w.WeatherError.NotVisible?w.WeatherState.Ready:w.WeatherState.Error:w.WeatherState.Ready}},{key:"error",get:function(){const e=this.view;return i.isNone(e)||!e.ready?null:"3d"!==e.type?w.WeatherError.UnsupportedView:"local"===e.viewingMode?w.WeatherError.LocalScene:e.environment.atmosphereEnabled?e.environmentManager.weatherVisible?null:w.WeatherError.NotVisible:w.WeatherError.NoAtmosphere}},{key:"current",get:function(){const e=i.applySome(this._environment,(e=>e.weather));return i.unwrapOr(e,this._weatherByType.sunny)},set:function(e){i.applySome(this._environment,(t=>t.weather=e))}},{key:"test",get:function(){return{...this._weatherByType}}},{key:"_environment",get:function(){const e=this.view;return i.isSome(e)&&"3d"===e.type?e.environment:null}}]),r}(r);t.__decorate([a.property()],_.prototype,"view",void 0),t.__decorate([a.property()],_.prototype,"state",null),t.__decorate([a.property()],_.prototype,"error",null),t.__decorate([a.property()],_.prototype,"current",null),t.__decorate([a.property()],_.prototype,"_environment",null),_=t.__decorate([h.subclass("esri.widgets.Weather.WeatherViewModel")],_);return _}));
