import { c as M } from "../../chunks/runtime.js";
import { css as T, html as s } from "lit";
import { usePropertyChange as z } from "@arcgis/lumina/controllers";
import { classes as m } from "@arcgis/toolkit/dom";
import { LitElement as W, createEvent as O, nothing as _, safeClassMap as u } from "@arcgis/lumina";
import { u as E } from "../../chunks/useT9n.js";
import { m as S } from "../../chunks/useViewModel.js";
import { H as B } from "../../chunks/heading.js";
import { g as w } from "../../chunks/globalCss.js";
import H from "@arcgis/core/core/Accessor.js";
import { property as p, subclass as j } from "@arcgis/core/core/accessorSupport/decorators.js";
import { watch as L } from "@arcgis/core/core/reactiveUtils.js";
import b from "@arcgis/core/views/3d/environment/CloudyWeather.js";
import f from "@arcgis/core/views/3d/environment/FoggyWeather.js";
import y from "@arcgis/core/views/3d/environment/RainyWeather.js";
import x from "@arcgis/core/views/3d/environment/SnowyWeather.js";
import $ from "@arcgis/core/views/3d/environment/SunnyWeather.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
v4.34.7 */
const d = "arcgis-weather", g = {
  base: d,
  content: `${d}__content`,
  hasError: `${d}__content--has-error`,
  selector: `${d}__selector`,
  options: `${d}__options`,
  optionsHidden: `${d}__options--hidden`,
  error: `${d}__error`,
  warningTitle: `${d}__warning-title`
}, A = T`.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.esri-widget{--esri-widget-padding-x: 15px;--esri-widget-padding-y: var(--calcite-spacing-md);--esri-widget-padding: var(--esri-widget-padding-y) var(--esri-widget-padding-x);box-sizing:border-box;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget *,.esri-widget :before,.esri-widget :after{box-sizing:inherit}.esri-widget.esri-widget--disabled>*{opacity:.4;pointer-events:none}.esri-widget.esri-widget--compact{--esri-widget-padding-y: 0;--esri-widget-padding-x: 0}.esri-widget__anchor{color:var(--calcite-color-text-2)}.esri-widget__anchor:hover{color:var(--calcite-color-text-3)}.esri-widget__anchor:hover,.esri-widget__anchor:focus{text-decoration:underline}.esri-widget__anchor--disabled{opacity:.4;pointer-events:none}.esri-widget__header{background-color:var(--calcite-color-foreground-1);flex:1 0 100%;justify-content:space-between;align-items:center;width:100%;min-height:48px;padding:12px 0 12px 15px;display:flex}.esri-widget__header .esri-widget__heading{width:calc(100% - 48px);text-align:initial;color:var(--calcite-color-text-1);align-items:center;margin:0;padding:0;display:flex}.esri-widget__header-button{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);border:none;flex:0 0 48px;justify-content:center;align-self:stretch;align-items:center;width:48px;padding:0;display:flex}.esri-widget__footer{background-color:var(--calcite-color-foreground-1);justify-content:center;align-items:center;width:100%;min-height:48px;display:flex}.esri-widget__footer-pagination{color:var(--calcite-color-text-2);justify-content:space-between;align-items:center;display:flex}.esri-widget__footer-pagination-previous-button,.esri-widget__footer-pagination-next-button{cursor:pointer;background-color:var(--calcite-color-foreground-1);border:0;margin:0 7px;padding:12px 15px;transition:background-color .125s ease-in-out}.esri-widget__footer-pagination-previous-button:hover,.esri-widget__footer-pagination-previous-button:focus,.esri-widget__footer-pagination-next-button:hover,.esri-widget__footer-pagination-next-button:focus{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1)}.esri-menu{visibility:hidden;z-index:1;background-clip:padding;background-color:var(--calcite-color-foreground-1);background-clip:padding-box;width:100%;max-height:0;margin:2px 0 0;padding:0;font-size:var(--calcite-font-size);line-height:var(--calcite-spacing-xl);position:absolute;top:100%;left:0;overflow:hidden;box-shadow:0 1px 2px #0000004d}.esri-menu .esri-menu__header{color:var(--calcite-color-text-inverse);background-color:var(--calcite-color-inverse);padding:6px 12px}.esri-menu__list{margin:0;padding:0;list-style:none}.esri-menu__list-item{cursor:pointer;border-top:1px solid #adadad4d;border-left:3px solid #0000;padding:.8em 1em}.esri-menu__list-item [class^=esri-icon-],.esri-menu__list-item [class*=" esri-icon-"]{padding-right:2.8px}.esri-menu__list-item:first-child{border-top:none}.esri-menu__list-item--focus,.esri-menu__list-item:hover,.esri-menu__list-item:focus{background-color:var(--calcite-color-foreground-1)}.esri-menu__list-item:active{background-color:var(--calcite-color-foreground-current)}.esri-menu__list-item--active,.esri-menu__list-item--active:hover,.esri-menu__list-item--active:focus{background-color:var(--calcite-color-foreground-1);border-left-color:var(--calcite-color-brand)}.esri-widget__table{border-collapse:collapse;color:var(--calcite-color-text-1);border:none;width:100%;line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget__table tr:nth-child(odd){background-color:var(--calcite-color-transparent)}.esri-widget__table tr:nth-child(2n){background-color:var(--calcite-color-transparent-press)}.esri-widget__table tr a{color:var(--calcite-color-text-2)}.esri-widget__table tr a:hover,.esri-widget__table tr a:focus{color:var(--calcite-color-text-1)}.esri-widget__table tr td,.esri-widget__table tr th{vertical-align:top;word-break:break-word;padding:.5em .7em;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular)}.esri-widget__table tr th{text-align:left;border-right:3px solid #0000000d;width:50%}.esri-widget__table tr td{width:50%}.esri-input{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1);border:1px solid #959595;font-size:var(--calcite-font-size)}.esri-input::-ms-clear{display:none}.esri-input::placeholder{opacity:1;color:var(--calcite-color-text-2)}.esri-input:placeholder-shown{text-overflow:ellipsis}.esri-input[type=text],.esri-input[type=password],.esri-input[type=number]{height:32px;padding:0 .5em}calcite-combobox.esri-input{border:none}.esri-widget__content--empty{text-align:center;color:var(--calcite-color-border-input);flex-flow:column wrap;align-items:center;padding:18px 22px;display:flex}.esri-widget__content--empty h1.esri-widget__heading,.esri-widget__content--empty h2.esri-widget__heading,.esri-widget__content--empty h3.esri-widget__heading,.esri-widget__content--empty h4.esri-widget__heading,.esri-widget__content--empty h5.esri-widget__heading{font-weight:var(--calcite-font-weight-regular)}.esri-widget__content-illustration--empty{width:128px;padding:1rem 0}.esri-widget__content-icon--empty{width:32px;padding:.5rem 0}.esri-select{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background:var(--calcite-color-foreground-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 32 32' width='32' height='32'%3E%3Cpath d='M8 11.207l-4-4V5.793l4 4 4-4v1.414z' fill='%23adadad' fillrule='nonzero'/%3E%3C/svg%3E") 100% no-repeat;border:1px solid #959595;border-radius:0;width:100%;height:32px;margin:0;padding:0 .5em;font-family:inherit;font-size:.85em;display:block}.esri-select[disabled]{cursor:auto}.esri-select::-ms-expand{display:none}.esri-disabled a,.esri-disabled [role=menu],.esri-disabled [role=checkbox],.esri-disabled [class^=esri-icon-],.esri-disabled [class*=" esri-icon-"]{color:var(--calcite-color-text-3)}.keynav-mode .esri-widget:focus,.keynav-mode .esri-widget :focus{z-index:1;outline-offset:2px;outline:2px solid #adadad}.esri-widget__loader-animation{border:.15em solid #adadad4d;border-top-color:var(--calcite-color-border-input);border-radius:100%;width:1em;height:1em;font-size:var(--calcite-font-size-md);animation:1.25s linear infinite esri-rotate;display:block;transform:translateZ(0)}:dir(rtl) .esri-widget__table th{text-align:right;border-left:3px solid #0000000d;border-right:none}:dir(rtl) .esri-select{background-position:0}:dir(rtl) .esri-menu__list-item{border-left:none;border-right:3px solid #0000}:dir(rtl) .esri-menu__list-item [class^=esri-icon-],:dir(rtl) .esri-menu__list-item [class*=" esri-icon-"]{padding-left:2px;padding-right:0}:dir(rtl) .esri-menu__list-item--active{border-right-color:var(--calcite-color-brand)}.esri-icon-font-fallback-text{clip:rect(0 0 0 0);width:1px;height:1px;position:absolute;overflow:hidden}.esri-rotating{animation:1.25s linear infinite esri-rotate;transform:translateZ(0)}.esri-clearfix:before,.esri-clearfix:after{content:" ";display:table}.esri-clearfix:after{clear:both}.esri-interactive{cursor:pointer}.esri-hidden{display:none!important}.esri-invisible{visibility:hidden!important}.esri-offscreen{position:absolute;top:-999em;left:-999em}.esri-match-height{flex-direction:column;flex:auto;display:flex;overflow:hidden}.arcgis-weather{position:relative;padding:var(--esri-widget-padding);width:fit-content}.arcgis-weather__content{display:flex;flex-direction:column;gap:var(--calcite-spacing-md);width:min-content}.arcgis-weather__content--has-error{visibility:hidden;height:0;overflow:hidden;pointer-events:none}.arcgis-weather__selector{display:flex;flex-direction:row;gap:var(--calcite-spacing-sm);align-items:center}.arcgis-weather__options{display:flex;flex-direction:column;gap:var(--calcite-spacing-sm);calcite-label:last-child{--calcite-label-margin-bottom: 0}}.arcgis-weather__options--hidden{display:none}.arcgis-weather__warning-title{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}`;
var D = Object.defineProperty, P = Object.getOwnPropertyDescriptor, a = (t, e, r, o) => {
  for (var i = o > 1 ? void 0 : o ? P(e, r) : e, l = t.length - 1, c; l >= 0; l--)
    (c = t[l]) && (i = (o ? c(e, r, i) : c(i)) || i);
  return o && i && D(e, r, i), i;
};
const V = {
  sunny: $,
  cloudy: b,
  rainy: y,
  snowy: x,
  foggy: f
}, C = Object.keys(V);
let n = class extends H {
  //#region Lifecycle
  constructor(t) {
    super(t), this._settingWeather = !1, this._weatherByType = {
      sunny: new $(),
      cloudy: new b(),
      rainy: new y(),
      snowy: new x(),
      foggy: new f()
    };
  }
  initialize() {
    this.addHandles([
      // When the weather is changed directly in the environment (not in the VM),
      // we need to update the corresponding weather instance in the view model.
      L(
        () => this.current,
        (t) => {
          this._settingWeather || t == null || (this._weatherByType = {
            ...this._weatherByType,
            [t.type]: t
          });
        },
        { sync: !0, initial: !0 }
      )
    ]);
  }
  get state() {
    if (!this.view?.ready)
      return "disabled";
    if (this.error != null)
      switch (this.error) {
        // When the weather is not visible because of camera position, we don't
        // consider it to be a fatal error so we still want to display the full
        // UI, just with a warning at the bottom.
        case "not-visible":
          return "ready";
        // Other errors make the widget unusable, so we consider them to be fatal
        // and show only the error message.
        default:
          return "error";
      }
    return "ready";
  }
  get disabled() {
    return this.state === "disabled";
  }
  get weatherByType() {
    return this._weatherByType;
  }
  get error() {
    const t = this.view;
    return t?.ready ? t.type !== "3d" ? "unsupported-view" : t.viewingMode === "local" ? "local-scene" : t.environment.atmosphereEnabled ? t.environment.weatherAvailable ? null : "not-visible" : "no-atmosphere" : null;
  }
  get current() {
    return this._environment?.weather ?? this._weatherByType.sunny;
  }
  set current(t) {
    const e = this._environment;
    e && (e.weather = t);
  }
  get _environment() {
    const t = this.view;
    return t != null && t.type === "3d" ? t.environment : null;
  }
  //#endregion
  //#region Public Methods
  setWeatherByType(t) {
    if (!C.includes(t)) {
      console.warn(`arcgis-weather - "${t}" is not a valid weather type`);
      return;
    }
    const e = this._environment;
    e != null && (this._settingWeather = !0, e.weather = this._weatherByType[t], this._settingWeather = !1);
  }
  setSnowCoverEnabled(t) {
    const e = this.current;
    "snowCover" in e && (e.snowCover = t ? "enabled" : "disabled");
  }
  //#endregion
};
a([
  p()
], n.prototype, "view", 2);
a([
  p()
], n.prototype, "state", 1);
a([
  p()
], n.prototype, "disabled", 1);
a([
  p()
], n.prototype, "weatherByType", 1);
a([
  p()
], n.prototype, "error", 1);
a([
  p()
], n.prototype, "current", 1);
a([
  p()
], n.prototype, "_weatherByType", 2);
a([
  p()
], n.prototype, "_environment", 1);
n = a([
  j("components.weather.WeatherViewModel")
], n);
function h({ label: t, value: e, disabled: r, onChange: o }) {
  const i = (v) => {
    const k = v.currentTarget.value;
    o?.((k ?? 0) / 100);
  }, l = "s", c = Math.round((e ?? 0) * 100);
  return s`<calcite-label .scale=${l}>${t}<calcite-slider .disabled=${r} label-handles label-ticks max=100 max-label=100 min=0 min-label=0 .scale=${l} step=1 ticks=100 .value=${c} @calciteSliderChange=${i} @calciteSliderInput=${i}></calcite-slider></calcite-label>`;
}
const R = S(n), F = {
  sunny: "brightness",
  cloudy: "partly-cloudy",
  rainy: "rain",
  snowy: "snow",
  foggy: "fog"
};
class Z extends W {
  constructor() {
    super(...arguments), this.viewModel = R(this), this.messages = E(), this.view = this.viewModel.view, this.autoDestroyDisabled = !1, this.headingLevel = 4, this.hideHeader = !1, this.icon = "partly-cloudy", this.label = this.messages.componentLabel, this.state = this.viewModel.state, this.arcgisPropertyChange = z()("state"), this.arcgisReady = O();
  }
  static {
    this.properties = { view: 0, autoDestroyDisabled: 5, headingLevel: 9, hideHeader: 5, icon: 1, label: 1, messageOverrides: 0, position: 1, referenceElement: 1, state: 35 };
  }
  static {
    this.styles = A;
  }
  async destroy() {
    await this.manager.destroy();
  }
  _getWarningMessage() {
    switch (this.viewModel.error) {
      case "not-visible": {
        const { view: e } = this.viewModel;
        return e?.type === "3d" && e.environment.atmosphereEnabled ? this.messages.error?.notVisible : void 0;
      }
      default:
        return;
    }
  }
  _getErrorMessage() {
    const e = this.messages.error;
    if (e)
      switch (this.viewModel.error) {
        case "local-scene":
          return e.localScene;
        case "no-atmosphere":
          return e.noAtmosphere;
        case "unsupported-view":
          return e.unsupported;
        default:
          return;
      }
  }
  render() {
    return s`<div aria-label=${this.messages.componentLabelAccessible ?? _} class=${u(m(g.base, w.widget, this.viewModel.disabled && w.widgetDisabled))} role=region>${this._renderContent()}</div>`;
  }
  _renderContent() {
    const { headingLevel: e, messages: r, viewModel: o } = this, i = this._getWarningMessage(), l = o.current, c = o.state === "error";
    return s`${this.hideHeader ? void 0 : B({ level: e, children: r.componentLabel })}${c ? s`<div class=${u(g.error)}>${this._getErrorMessage()}</div>` : void 0}<div class=${u(m({ [g.content]: !0, [g.hasError]: c }))}><div aria-label=${r.weatherType ?? _} class=${u(g.selector)} role=radiogroup>${C.map(this._renderWeatherTypeButton, this)}</div>${Object.values(o.weatherByType).map((v) => s`<div class=${u(m({
      [g.options]: !0,
      [g.optionsHidden]: v.type !== l?.type
    }))}>${this._renderOptions(v)}</div>`)}${i ? this._renderWarning(i) : void 0}</div>`;
  }
  _renderWeatherTypeButton(e) {
    const r = this.messages[e]?.label ?? "", { disabled: o } = this.viewModel, i = !o && this.viewModel.current.type === e;
    return s`<calcite-button .appearance=${i ? "solid" : "outline"} aria-checked=${i ? "true" : "false"} .disabled=${o} .iconStart=${F[e]} .kind=${i ? "brand" : "neutral"} .label=${r} @click=${() => {
      i || this.viewModel.setWeatherByType(e);
    }} scale=l title=${r ?? _}></calcite-button>`;
  }
  _renderOptions(e) {
    switch (e.type) {
      case "sunny":
        return this._renderSunnyOptions(e);
      case "cloudy":
        return this._renderCloudyOptions(e);
      case "rainy":
        return this._renderRainyOptions(e);
      case "snowy":
        return this._renderSnowyOptions(e);
      case "foggy":
        return this._renderFoggyOptions(e);
    }
  }
  _renderSunnyOptions(e) {
    return h({ disabled: this.viewModel.disabled, label: this.messages.sunny?.cloudCover, value: e.cloudCover, onChange: (r) => {
      e.cloudCover = r;
    } });
  }
  _renderCloudyOptions(e) {
    return h({ disabled: this.viewModel.disabled, label: this.messages.cloudy?.cloudCover, value: e.cloudCover, onChange: (r) => {
      e.cloudCover = r;
    } });
  }
  _renderRainyOptions(e) {
    const { disabled: r } = this.viewModel, o = this.messages.rainy;
    return s`${h({ disabled: r, label: o?.cloudCover, value: e.cloudCover, onChange: (i) => {
      e.cloudCover = i;
    } })}${h({ disabled: r, label: o?.precipitation, value: e.precipitation, onChange: (i) => {
      e.precipitation = i;
    } })}`;
  }
  _renderSnowyOptions(e) {
    const { disabled: r } = this.viewModel, o = this.messages.snowy;
    return s`${h({ disabled: r, label: o?.cloudCover, value: e.cloudCover, onChange: (i) => {
      e.cloudCover = i;
    } })}${h({ disabled: r, label: o?.precipitation, value: e.precipitation, onChange: (i) => {
      e.precipitation = i;
    } })}<calcite-label layout=inline scale=s title=${o?.snowCoverTooltip ?? _}><calcite-checkbox .checked=${e.snowCover === "enabled"} .disabled=${r} @calciteCheckboxChange=${(i) => {
      this.viewModel.setSnowCoverEnabled(i.currentTarget.checked);
    }}></calcite-checkbox>${o?.snowCover}</calcite-label>`;
  }
  _renderFoggyOptions(e) {
    return h({ disabled: this.viewModel.disabled, label: this.messages.foggy?.fogStrength, value: e.fogStrength, onChange: (r) => {
      e.fogStrength = r;
    } });
  }
  _renderWarning(e) {
    return s`<calcite-notice aria-live=polite open icon=exclamation-mark-triangle-f kind=warning scale=s><div slot=title class=${u(g.warningTitle)}>${this.messages.warningTitle}</div><div slot=message>${e}</div></calcite-notice>`;
  }
}
M("arcgis-weather", Z);
export {
  Z as ArcgisWeather
};
