/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as de } from "../../chunks/runtime.js";
import { watch as he, when as ge, whenOnce as ue } from "@arcgis/core/core/reactiveUtils.js";
import * as pe from "@arcgis/core/intl.js";
import me from "@arcgis/core/views/3d/environment/SunLighting.js";
import fe from "@arcgis/core/views/3d/environment/VirtualLighting.js";
import { LitElement as _e, createEvent as B, safeStyleMap as V, nothing as J } from "@arcgis/lumina";
import { css as be, html as m } from "lit";
import { createRef as q, ref as G } from "lit/directives/ref.js";
import { u as ve } from "../../chunks/useT9n.js";
import { u as we } from "../../chunks/useView.js";
import { m as N } from "../../chunks/handle.js";
import { o as T, i as p, b as Y, d as P, g as ye } from "../../chunks/time-utils.js";
import { r as xe, b as Se, d as De } from "../../chunks/async-utils.js";
import { createTrackingTarget as Te, runTracked as Z, signal as ke } from "@arcgis/core/applications/Components/reactiveUtils.js";
import { C as W } from "../../chunks/component-wrapper.js";
import { V as D } from "../../chunks/visible-element.js";
function Pe(r, e) {
  return r / 15;
}
function Ce(r, e) {
  const t = r?.[0];
  if (t == null)
    return null;
  e || (e = { hours: 0, minutes: 0, seconds: 0 }), e.hours = Pe(t);
  const i = e.hours % 1;
  e.hours -= i, e.minutes = i * 60;
  const n = e.minutes % 1;
  return e.minutes -= n, e.seconds = Math.round(n * 60), e;
}
function K(r) {
  const e = Ce([r.longitude, r.latitude]);
  return e == null ? 0 : Math.round(e.hours + e.minutes / 60 + e.seconds / 3600);
}
function ne(r, e) {
  return (r % e + e) % e;
}
class $e {
  #e;
  #i;
  #r = Te(() => {
    this.#t();
  });
  constructor(e) {
    this.#i = e;
    let t;
    Z(this.#r, () => {
      t = e();
    }), this.#e = ke(t);
  }
  #t() {
    const e = this.#e.value;
    Z(this.#r, () => {
      this.#e.value = this.#i(e);
    });
  }
  mutate(e) {
    this.#e.value = e;
  }
  get value() {
    return this.#e.value;
  }
}
function A(r) {
  return new $e(r);
}
var L = Math.PI, u = Math.sin, k = Math.cos, ze = Math.asin, Oe = Math.acos, y = L / 180, se = 1e3 * 60 * 60 * 24, oe = 2440588, ae = 2451545;
function Me(r) {
  return r.valueOf() / se - 0.5 + oe;
}
function O(r) {
  return new Date((r + 0.5 - oe) * se);
}
function Ue(r) {
  return Me(r) - ae;
}
var Q = y * 23.4397;
function Le(r, e) {
  return ze(u(e) * k(Q) + k(e) * u(Q) * u(r));
}
function Ee(r) {
  return y * (357.5291 + 0.98560028 * r);
}
function He(r) {
  return y * (1.9148 * u(r) + 0.02 * u(2 * r) + 3e-4 * u(3 * r));
}
function Ae(r, e) {
  var t = y * 102.9372;
  return r + e + t + L;
}
var S = {};
S.PolarException = {
  NORMAL: 0,
  MIDNIGHT_SUN: 1,
  POLAR_NIGHT: 2
};
var I = [
  [-0.83, "sunrise", "sunset"]
  // none of the below are currently used -> disabled to avoid unnecessary calculations,
  // as all elements of 'times' are evaluated on every sunCalc.getTimes call.
  /*,
    [ -0.3, "sunriseEnd",  "sunsetStart" ],
    [   -6, "dawn",      "dusk"    ],
    [  -12, "nauticalDawn",  "nauticalDusk"],
    [  -18, "nightEnd",    "night"     ],
    [  6, "goldenHourEnd", "goldenHour"  ]
    */
], le = 9e-4;
function Ie(r, e) {
  return Math.round(r - le - e / (2 * L));
}
function X(r, e, t) {
  return le + (r + e) / (2 * L) + t;
}
function ee(r, e, t) {
  return ae + r + 53e-4 * u(e) - 69e-4 * u(2 * t);
}
function Ne(r, e, t) {
  return Oe((u(r) - u(e) * u(t)) / (k(e) * k(t)));
}
S.getTimes = function(r, e, t) {
  var i = y * -t, n = y * e, s = Ue(r), o = Ie(s, i), a = X(0, i, o), c = Ee(a), d = He(c), l = Ae(c, d), h = Le(l, 0), g = ee(a, c, l);
  function w(H) {
    var z = Ne(H, n, h), ce = X(z, i, o);
    return ee(ce, c, l);
  }
  function x(H) {
    var z = (u(H) - u(n) * u(h)) / (k(n) * k(h));
    return z < -1 ? S.PolarException.MIDNIGHT_SUN : z > 1 ? S.PolarException.POLAR_NIGHT : S.PolarException.NORMAL;
  }
  var _ = {
    solarNoon: O(g),
    nadir: O(g - 0.5),
    polarException: S.PolarException.NORMAL
  }, b, f, $, E, j;
  for (b = 0, f = I.length; b < f; b += 1)
    $ = I[b], E = w($[0] * y), j = g - (E - g), _[$[1]] = O(j), _[$[2]] = O(E);
  return _.polarException = x(I[0][0] * y), _;
};
const Fe = {
  spring: { dayOfMonth: 20, month: 2 },
  // Northern Spring equinox in 2014 - March 20
  summer: { dayOfMonth: 21, month: 5 },
  // Northern Summer solstice in 2014 - June 21
  fall: { dayOfMonth: 23, month: 8 },
  // Northern Fall equinox in 2014 - September 23
  winter: { dayOfMonth: 21, month: 11 }
  // Northern Winter solstice in 2014 - December 21
}, F = ["spring", "summer", "fall", "winter"];
function C(r, e, t) {
  const i = R(e, t), { dayOfMonth: n, month: s } = Fe[i], o = new Date(r.getTime());
  return o.setMonth(s, n), o;
}
function Je(r, e) {
  const t = Re(r);
  return R(t, e);
}
function Re(r) {
  const e = r.getTime(), t = C(r, "spring", "northern").getTime(), i = C(r, "summer", "northern").getTime(), n = C(r, "fall", "northern").getTime(), s = C(r, "winter", "northern").getTime();
  return e >= t && e < i ? "spring" : e >= i && e < n ? "summer" : e >= n && e < s ? "fall" : "winter";
}
function R(r, e) {
  return e === "northern" ? r : je(r);
}
function te(r) {
  return r >= 0 ? "northern" : "southern";
}
function je(r) {
  const e = F.indexOf(r);
  return F[(e + 2) % 4];
}
const Be = 1440, Ve = 864e5;
function qe(r, e, t, i) {
  const n = S.getTimes(r, e, t), s = n.sunrise, o = n.sunset, a = T(r, i), c = T(s, i), d = T(o, i);
  if (a.getUTCDate() !== c.getUTCDate() || a.getUTCDate() !== d.getUTCDate()) {
    const l = a.getTime() - c.getTime() > 0 ? 1 : -1;
    s.setUTCDate(s.getUTCDate() + l), o.setUTCDate(o.getUTCDate() + l);
  }
  return {
    sunrise: s,
    sunset: o
  };
}
const Ge = 100, Ye = 1e3, v = 12e5, M = 72e5;
function ie(r, e) {
  return ne(r + e, 24);
}
function Ze({
  mode: r,
  lighting: e,
  getPlaySpeed: t,
  onProgress: i,
  beforeProgress: n
}) {
  let s = -1;
  function o(a = Date.now()) {
    const c = e.date, d = Date.now() - (a ?? 0);
    if (r === "day") {
      a = Date.now();
      const h = t() / Ge * d;
      if (h > 0) {
        let g = new Date(c.getTime() + h);
        const w = e.displayUTCOffset ?? 0, x = ie(g.getUTCHours(), w), _ = ie(c.getUTCHours(), w);
        x < _ && (g = new Date(c.getTime() + h - Ve));
        const b = e.clone();
        n?.(), e.date = g, i?.(b, e);
      }
    } else if (d > Ye) {
      a = Date.now();
      const l = (c.getUTCMonth() + 1) % 12, h = new Date(c.getTime());
      h.setUTCMonth(l);
      const g = e.clone();
      n?.(), e.date = h, i?.(g, e);
    }
    s = requestAnimationFrame(() => o(a));
  }
  return o(), N(() => cancelAnimationFrame(s));
}
const U = v / 4;
function We(r, e, t, i) {
  const {
    day: n,
    night: s = n,
    twilight: o = n
  } = i, a = n * U, c = s * U, d = o * U;
  if (r == null || e == null || Number.isNaN(r.getTime()) && Number.isNaN(e.getTime()))
    return a;
  const l = t.getTime(), h = r.getTime(), g = e.getTime(), w = h - M / 2, x = h + M / 2, _ = g - M / 3 * 2, b = g + M / 3;
  let f = a;
  return l >= w && l <= x ? l - w <= v ? f = c - (l - w) / v * (c - d) : x - l <= v / 2 ? f = a - (x - l) / v * 2 * (a - d) : f = d : l >= _ && l <= b ? l - _ <= v / 2 ? f = a - (l - _) / v * 2 * (a - d) : b - l <= v ? f = c - (b - l) / v * (c - d) : f = d : (l < h || l > g) && (f = c), f;
}
const Ke = be`.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{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__heading{word-break:break-word}.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}@supports (-ms-ime-align: auto){.esri-slider__anchor:focus{outline:1px dotted var(--calcite-color-foreground-current)}}.esri-slider{-webkit-user-select:none;user-select:none;direction:ltr;width:100%;height:100%;display:flex}.esri-disabled{pointer-events:none}.esri-disabled .esri-slider__content,.esri-disabled .esri-slider__min,.esri-disabled .esri-slider__max{opacity:var(--calcite-opacity-light)}.esri-slider--reversed.esri-slider--horizontal{flex-direction:row-reverse}.esri-slider--reversed.esri-slider--vertical{flex-direction:column}.esri-slider--horizontal{flex-direction:row}.esri-slider--horizontal .esri-slider__content{height:auto}.esri-slider--horizontal .esri-slider__track{width:100%;height:2px}.esri-slider--horizontal .esri-slider__segment--interactive:hover{cursor:ew-resize}.esri-slider--horizontal .esri-slider__anchor{width:1px;height:100%}.esri-slider--horizontal .esri-slider__label{text-align:center;margin:0 11px;top:-30px;left:-50px}.esri-slider--horizontal .esri-slider__label-input{text-align:center}.esri-slider--horizontal .esri-slider__max,.esri-slider--horizontal .esri-slider__min{flex:none;width:50px;height:auto;margin:auto}.esri-slider--horizontal .esri-slider__ticks{width:100%;margin:9px 0 0;top:100%;left:0}.esri-slider--horizontal .esri-slider__tick{width:1px;height:5px}.esri-slider--horizontal .esri-slider__tick-label{margin-top:18px}.esri-slider--vertical{flex-direction:column-reverse}.esri-slider--vertical .esri-slider__content{flex-direction:column;width:auto}.esri-slider--vertical .esri-slider__track{flex-direction:column;flex:1 0 0;width:2px;height:100%}.esri-slider--vertical .esri-slider__segment--interactive:hover{cursor:ns-resize}.esri-slider--vertical .esri-slider__anchor{width:100%;height:1px}.esri-slider--vertical .esri-slider__label{text-align:left;top:-10px;left:20px}.esri-slider--vertical .esri-slider__max,.esri-slider--vertical .esri-slider__min{flex:0 0 22px;width:100%;margin:auto}.esri-slider--vertical .esri-slider__ticks{margin:0 0 0 11px;top:0;left:100%}.esri-slider--vertical .esri-slider__tick{width:5px;height:1px}.esri-slider--vertical .esri-slider__tick-label{margin-left:30px}.esri-slider__content{z-index:0;flex:1 0 auto;justify-content:center;align-items:center;margin:auto;line-height:0;display:flex;position:relative}.esri-slider__track{touch-action:none;background-color:var(--calcite-color-border-ghost);display:inline-block;position:relative}.esri-slider__segment{transform-origin:0 0;will-change:transform;touch-action:none;width:100%;height:100%;position:absolute;top:0;left:0}.esri-slider__segment:hover{cursor:pointer}.esri-slider__anchor{touch-action:none;-webkit-user-select:none;user-select:none;background-color:var(--calcite-color-brand);position:absolute}.esri-slider__anchor:focus .esri-slider__thumb,.esri-slider__anchor:focus .esri-slider__label{outline:inherit}.esri-slider__anchor--moving:focus .esri-slider__thumb{cursor:grabbing;border:3px solid var(--calcite-color-brand-press)}.esri-slider__anchor--moving .esri-slider__label:hover,.esri-slider__anchor--moving .esri-slider__label--interactive:hover{cursor:grabbing}.esri-slider__thumb{box-sizing:border-box;z-index:1;touch-action:none;background-color:var(--calcite-color-foreground-2);border:2px solid var(--calcite-color-brand);border-radius:16px;width:16px;height:16px;transition:all .125s ease-in-out;position:absolute;top:-7px;left:-7px}.esri-slider__thumb:hover{cursor:grab;border-width:3px;border-color:var(--calcite-color-brand-press);width:19.2px;height:19.2px;top:-8.6px;left:-8.6px}.esri-slider__label{min-width:80px;line-height:var(--calcite-font-line-height-fixed-xl);position:absolute}.esri-slider__label:hover{cursor:grab}.esri-slider__label--interactive:hover,.esri-slider__max--interactive:hover,.esri-slider__min--interactive:hover{cursor:pointer;text-decoration:underline}.esri-slider__label-input{z-index:1;width:100%;position:relative}.esri-slider__extra-content{display:inline-block}.esri-slider__max,.esri-slider__min{text-align:center;justify-content:center;align-items:center;height:22px;line-height:var(--calcite-font-line-height-fixed-xl);display:flex}.esri-slider__max--interactive:hover,.esri-slider__min--interactive:hover{background-color:var(--calcite-color-foreground-2)}.esri-slider__range-input{text-align:center;width:100%;padding:1px 0}.esri-slider__ticks{z-index:0;height:100%;display:inline-block;position:absolute}.esri-slider__tick{background:var(--calcite-color-foreground-1);position:absolute}.esri-slider__tick-label{width:max-content;position:absolute}:dir(rtl) .esri-slider__label,:dir(rtl) .esri-slider__max,:dir(rtl) .esri-slider__min,:dir(rtl) .esri-slider__tick-label{direction:rtl;unicode-bidi:plaintext}:dir(rtl) .esri-slider__range-input,:dir(rtl) .esri-slider__label-input{unicode-bidi:plaintext}:host{width:350px}.root{display:flex;flex-direction:column;overflow:visible;gap:var(--calcite-spacing-md);justify-content:space-between;padding:var(--arcgis-internal-padding);position:relative;calcite-label{--calcite-label-margin-bottom: 0}&.loading>*:not(calcite-scrim){opacity:0}}.unsupported{padding:0 var(--calcite-spacing-lg);animation:esri-fade-in .25s ease-in-out}.slider{margin-block-start:0rem}.time-configuration{--date-play-button-offset: 11px;--slider-play-button-offset: var(--calcite-spacing-md);display:grid;gap:var(--calcite-spacing-md);grid-template-columns:1fr min-content;.slider-container{grid-column:1;+calcite-button{grid-column:2;transform:translateY(var(--slider-play-button-offset))}}.timezone-input-container{grid-column:1;min-width:0;+span{grid-column:2}}.date-picker-container{grid-column:1;+calcite-button{grid-column:2;transform:translateY(var(--date-play-button-offset))}}calcite-button{place-self:center}}`, Qe = {
  day: 1,
  night: 6,
  twilight: 2 / 3
};
class Xe extends _e {
  constructor() {
    super(...arguments), this.messages = ve({ blocking: !0 }), this.#i = "none", this.#r = null, this.#l = q(), this.#g = q(), this.#u = 200, this.#p = 200, this.#c = !1, this.#o = {}, this._offset = A((e) => {
      const t = this._lighting, i = p(t) ? t.displayUTCOffset : void 0;
      return this.#t ? e : i ?? e;
    }), this._timesliderPosition = A((e) => {
      const t = this._lighting;
      if (!p(t))
        return e;
      const i = t.displayUTCOffset ?? this.utcOffset ?? 0, n = t.date;
      if (this.#t)
        return e;
      if (Y(n)) {
        const { minutesSinceMidnight: s } = P(n, i);
        return s;
      }
      return e;
    }), this._localDate = A((e) => {
      const t = ye(this._view, this.utcOffset);
      return this.#t ? e : t ?? e;
    }), this.view = we(this), this.autoDestroyDisabled = !1, this.dateOrSeason = "date", this.headingLevel = 2, this.hideDatePicker = !1, this.hideHeader = !1, this.hidePlayButtons = !1, this.hideShadowsToggle = !1, this.hideSunLightingToggle = !1, this.hideTimezone = !1, this.icon = "brightness", this.playSpeedMultiplier = 1, this.timeSliderSteps = 5, this.arcgisReady = B(), this.arcgisUserDateTimeChange = B(), this.#a = !1;
  }
  static {
    this.properties = { localDateAsString: 32, view: 0, _playingState: 16, _sunlightingDisabled: 16, autoDestroyDisabled: 5, currentSeason: 1, dateOrSeason: 3, dayPlaying: 5, _directShadowsDisabled: 16, headingLevel: 9, hideDatePicker: 5, hideHeader: 5, hidePlayButtons: 5, hideShadowsToggle: 5, hideSunLightingToggle: 5, hideTimezone: 5, icon: 3, label: 1, playSpeedMultiplier: 9, referenceElement: 1, timeSliderSteps: 9, utcOffset: 9, timeSliderPosition: 9, localDate: 1, yearPlaying: 5 };
  }
  static {
    this.styles = Ke;
  }
  get _view() {
    return this.view?.type === "3d" ? this.view : void 0;
  }
  #e;
  #i;
  #r;
  #t;
  #l;
  #g;
  #u;
  #p;
  #c;
  #n(e, t) {
    return this.#a || this.#c ? !1 : (this.#o[e] = t, !0);
  }
  #m() {
    const { utcOffset: e, timeSliderPosition: t, localDate: i, directShadowsDisabled: n, sunlightingDisabled: s } = this.#o;
    if (this.#c = !0, e != null)
      if (t == null && i == null) {
        const o = this._lighting;
        p(o) ? (o.displayUTCOffset = e, this.#h(e, o)) : this._offset.mutate(e);
      } else
        this.utcOffset = e;
    t != null && (this.timeSliderPosition = t), i && (this.localDate = i), n != null && (this._directShadowsDisabled = n), s != null && (this._sunlightingDisabled = s), this.#o = {}, this.#c = !1;
  }
  #d() {
    if (this.requestUpdate(), this.#t)
      return;
    const e = xe(() => {
      if (p(this._lighting)) {
        const t = this.utcOffset ?? 0, i = this.timeSliderPosition ?? 0, n = this.localDate, s = i - t * 60, o = T(n, s, "minutes");
        this._lighting.date = o, this._lighting.displayUTCOffset = t;
      }
      this.#t?.remove();
    }, { timeout: this.#u });
    this.#t = N(() => {
      De(e), this.#t = void 0;
    });
  }
  #f({ scale: e, disabled: t }) {
    const { messages: i } = this;
    return m`<calcite-label .scale=${e} class="date-picker-container">${i.date}${et({ disabled: t, scale: e, date: this.localDateAsString, onDateChange: (n) => {
      const s = n.currentTarget.value, o = Array.isArray(s) ? s[0] : s;
      this._stopPlaying(), this.localDate = o, this._emitUserDateTimeChangeEvent();
    } })}</calcite-label>${D({ hidden: this.hidePlayButtons, children: re({ playing: this.yearPlaying, disabled: t, label: i.playYear, onClick: () => {
      this._playingState === "year" ? this._playingState = "none" : this._playingState = "year";
    }, scale: e }) })}`;
  }
  #_({ scale: e, disabled: t }) {
    const { messages: i } = this;
    return m`<calcite-label .scale=${e} class="date-picker-container">${i.season}${tt({ scale: e, selectedSeason: this.currentSeason, disabled: t, messages: i, onSeasonChange: (n) => {
      this._stopPlaying(), this.currentSeason = n.currentTarget.value;
    } })}</calcite-label>`;
  }
  #o;
  get #b() {
    return this.#g?.value?.startTime;
  }
  get localDateAsString() {
    return this._localDate.value ?? void 0;
  }
  get _playingState() {
    return this.#i;
  }
  set _playingState(e) {
    this.#i = e, this.#s?.remove(), e === "none" ? this.#e?.remove() : (this._play(e), this._emitUserDateTimeChangeEvent());
  }
  get _lighting() {
    return this._view?.environment?.lighting;
  }
  get _sunlightingDisabled() {
    return !p(this._lighting);
  }
  set _sunlightingDisabled(e) {
    this.#n("sunlightingDisabled", e);
    const t = this._view?.environment;
    if (t == null)
      return;
    const i = t.lighting, n = this.#r;
    this.#r = i;
    const s = {
      directShadowsEnabled: i.directShadowsEnabled,
      glow: i.glow
    };
    p(i) && (s.cameraTrackingEnabled = i.cameraTrackingEnabled);
    const o = e ? "virtual" : "sun";
    let a;
    n?.type === o ? a = n : a = e ? new fe() : new me({
      date: T(
        T(this.localDate, this.timeSliderPosition ?? 0, "minutes"),
        // this.localDate already includes the UTC offset, so we need to remove the offset to get the correct UTC date for the SunLighting configuration
        this.utcOffset ?? 0
      ),
      displayUTCOffset: this.utcOffset
    }), a.set(s), t.lighting = a, e || (this._stopPlaying(), this.#l.value && (this.#l.value.open = !1));
  }
  get currentSeason() {
    const e = this._view?.camera?.position?.latitude ?? 0, t = te(e);
    return Je(this.localDate, t);
  }
  set currentSeason(e) {
    this._stopPlaying();
    const t = this._view?.camera?.position?.latitude ?? 0, i = te(t), n = R(e, i);
    this.localDate = C(this.localDate, n, "northern"), this._emitUserDateTimeChangeEvent();
  }
  get dayPlaying() {
    return this._playingState === "day";
  }
  set dayPlaying(e) {
    this._playingState = e ? "day" : "none";
  }
  get _directShadowsDisabled() {
    return !this._lighting?.directShadowsEnabled;
  }
  set _directShadowsDisabled(e) {
    this.#n("directShadowsDisabled", e), this._lighting && (this._lighting.directShadowsEnabled = !e);
  }
  get utcOffset() {
    return this._offset.value;
  }
  set utcOffset(e) {
    this._offset.mutate(e), !this.#n("utcOffset", e) && this.#d();
  }
  get timeSliderPosition() {
    return this._timesliderPosition.value;
  }
  set timeSliderPosition(e) {
    this._timesliderPosition.mutate(ne(e ?? 0, Be)), !this.#n("timeSliderPosition", e) && this.#d();
  }
  get localDate() {
    return this._localDate.value != null ? new Date(this._localDate.value) : /* @__PURE__ */ new Date();
  }
  set localDate(e) {
    if (typeof e == "string" && /^\d{4}-\d{2}-\d{2}$/u.test(e)) {
      if (this._localDate.mutate(e), this.#n("localDate", e))
        return;
      this.#d();
      return;
    }
    const t = new Date(e);
    if (Y(t)) {
      t.setUTCFullYear(t.getFullYear(), t.getMonth(), t.getDate());
      const i = t.toISOString().slice(0, 10);
      if (this._localDate.mutate(i), this.#n("localDate", i))
        return;
      this.#d();
    }
  }
  get yearPlaying() {
    return this._playingState === "year";
  }
  set yearPlaying(e) {
    this._playingState = e ? "year" : "none";
  }
  async destroy() {
    await this.manager.destroy();
  }
  async load() {
    this.manager.onLifecycle(() => [
      // When camera tracking is enabled, update the displayed timezone whenever the camera crosses into a new rounded
      // UTC offset.
      he(() => {
        const e = this._view?.camera?.position;
        return e ? K(e) : void 0;
      }, (e, t) => {
        this.#v(e, t);
      }, { sync: !0, initial: !0 }),
      ge(() => !p(this._lighting), () => {
        this._stopPlaying();
      }),
      pe.onLocaleChange(() => {
        this.requestUpdate();
      })
    ]), this.manager.onDisconnected(() => {
      this.#e?.remove(), this.#t?.remove(), this.#s?.remove();
    });
  }
  willUpdate(e) {
    if (super.willUpdate(e), !!this.#a && p(this._lighting) && e.has("utcOffset") && !e.has("localDate") && !e.has("timeSliderPosition")) {
      const t = this.utcOffset ?? 0, { minutesSinceMidnight: i, localDate: n } = P(this._lighting.date, t);
      this._timesliderPosition.mutate(i), this._localDate.mutate(n);
    }
  }
  #a;
  async loaded() {
    const e = new AbortController();
    this.manager.onDisconnected(() => ({
      remove: () => {
        e.abort();
      }
    })), await Se(ue(() => this._view?.ready, { signal: e.signal }).then(() => {
      const t = this._lighting, i = this._view?.camera?.position;
      if (this.#o.utcOffset == null && p(t) && t.displayUTCOffset == null && i) {
        const s = K(i);
        this.#h(s, t);
      }
      this.#a = !0, this.#m();
      const n = this._playingState;
      n !== "none" && this.#e == null && this._play(n);
    }));
  }
  #v(e, t) {
    const i = this._lighting;
    if (!(!this.#a || !p(i) || !i.cameraTrackingEnabled || e == null)) {
      if (t == null && i.displayUTCOffset == null) {
        this.#h(e, i);
        return;
      }
      i.displayUTCOffset != null && (i.displayUTCOffset = e), this.#h(e, i);
    }
  }
  #h(e, t) {
    this._offset.mutate(e);
    const { minutesSinceMidnight: i, localDate: n } = P(t.date, e);
    this._timesliderPosition.mutate(i), this._localDate.mutate(n), this.requestUpdate();
  }
  _emitUserDateTimeChangeEvent() {
    this.isConnected && this.arcgisUserDateTimeChange.emit();
  }
  _stopPlaying() {
    this._playingState = "none";
  }
  #s;
  #w(e) {
    if (this.#s)
      return;
    const t = setTimeout(() => {
      const i = e.displayUTCOffset ?? 0, n = e.date, { minutesSinceMidnight: s } = P(n, i);
      this._timesliderPosition.mutate(s), this.#s?.remove();
    }, this.#p);
    this.#s = N(() => {
      clearTimeout(t), this.#s = void 0;
      const i = this._lighting;
      if (p(i)) {
        const n = i.displayUTCOffset ?? 0, s = i.date, { minutesSinceMidnight: o } = P(s, n);
        this._timesliderPosition.mutate(o);
      }
    });
  }
  _play(e) {
    this.#e?.remove();
    const t = this._view;
    if (t == null || this._sunlightingDisabled)
      return;
    const i = t.environment.lighting;
    if (!p(i))
      return;
    let n = 0;
    this.#e = Ze({
      mode: e,
      lighting: i,
      beforeProgress: () => {
        n = this.#b ?? 0;
      },
      onProgress: (s, o) => {
        this._timesliderPosition.mutate(n), this.#w(o);
      },
      getPlaySpeed: () => {
        const s = this._view, o = this._view?.environment.lighting;
        if (s != null && p(o)) {
          const a = s.camera.position.latitude ?? 0, c = s.camera.position.longitude ?? 0, { sunrise: d, sunset: l } = qe(o.date, a, c, o.displayUTCOffset ?? 0);
          return We(d, l, o.date, Qe) * this.playSpeedMultiplier;
        } else
          return U * this.playSpeedMultiplier;
      }
    });
  }
  render() {
    const { messages: e, dateOrSeason: t } = this, i = this._sunlightingDisabled, n = "m";
    if (!(this._view?.type === "3d"))
      return W({ class: "root", label: e.componentLabel, title: e.title, hideHeader: this.hideHeader, headingLevel: this.headingLevel, children: m`<div class="unsupported"><p>${e.unsupported}</p></div>` });
    const o = (this.utcOffset ?? 0) * 60, a = this.view?.ready === !0, c = Array.isArray(this.timeSliderSteps) ? this.timeSliderSteps.at(0) : this.timeSliderSteps;
    return W({ class: { root: !0, loading: !a }, label: e.componentLabel, title: e.title, hideHeader: this.hideHeader, headingLevel: this.headingLevel, children: m`${a ? void 0 : m`<calcite-scrim loading></calcite-scrim>`}<div class="time-configuration" style=${V({ columnGap: this.hidePlayButtons ? "0" : void 0 })}><calcite-label class="slider-container" .scale=${n}>${e.timeSliderLabel}<arcgis-time-of-day-slider class="slider" .disabled=${this._sunlightingDisabled} mode=single .startTime=${this.timeSliderPosition ?? 0} .steps=${c} style=${V({ gridArea: "slider" })} @arcgisTimeChange=${({ currentTarget: d }) => {
      this._stopPlaying(), this._emitUserDateTimeChangeEvent(), this.timeSliderPosition = d.startTime;
    }} ${G(this.#g)}></arcgis-time-of-day-slider></calcite-label>${D({ hidden: this.hidePlayButtons, children: re({ disabled: this._sunlightingDisabled, playing: this.dayPlaying, label: e.playDay, onClick: () => {
      this._playingState === "day" ? this._stopPlaying() : this._playingState = "day";
    }, scale: n }) })}${D({ hidden: this.hideTimezone, children: m`<calcite-label .scale=${n} class="timezone-input-container">${e.timezone}<calcite-input-time-zone mode=offset overlay-positioning=fixed .scale=${n} .disabled=${this._sunlightingDisabled} .value=${`${o}`} .referenceDate=${this.localDateAsString} @calciteInputTimeZoneChange=${(d) => {
      const l = +d.target.value;
      this.utcOffset = l / 60, this._stopPlaying();
    }} ${G(this.#l)}></calcite-input-time-zone></calcite-label><span></span>` })}${D({ hidden: this.hideDatePicker, children: t === "date" ? this.#f({ scale: n, disabled: i }) : this.#_({ scale: n, disabled: i }) })}</div>${D({ hidden: this.hideSunLightingToggle, children: it({ scale: n, messages: e.sunLightingToggle, sunlightingEnabled: !this._sunlightingDisabled, onSunLightingToggle: (d) => {
      this._sunlightingDisabled = !d;
    } }) })}${D({ hidden: this.hideShadowsToggle, children: rt({ scale: n, messages: e.shadowsToggle, onShadowCheckboxChange: (d) => {
      this._directShadowsDisabled = !d;
    }, shadowEnabled: !this._directShadowsDisabled }) })}` });
  }
}
function re({ disabled: r, playing: e, onClick: t, label: i, scale: n = "m" }) {
  return m`<calcite-button appearance=solid .scale=${n} .disabled=${r} .iconStart=${e ? "pause-f" : "play-f"} .label=${i} @click=${t} round title=${i ?? J} type=button></calcite-button>`;
}
function et({ disabled: r, date: e, onDateChange: t, scale: i }) {
  return m`<calcite-input-date-picker data-testid=daylight-date-picker .disabled=${r} overlay-positioning=fixed placement=bottom .value=${e} .scale=${i} @calciteInputDatePickerChange=${t}></calcite-input-date-picker>`;
}
function tt({ messages: r, disabled: e, scale: t, selectedSeason: i, onSeasonChange: n }) {
  return m`<calcite-select .disabled=${e} .label=${r.season} .scale=${t} .value=${i} @calciteSelectChange=${(s) => {
    n(s);
  }}>${F.map((s) => m`<calcite-option .selected=${i === s} .value=${s}>${r[s]}</calcite-option>`)}</calcite-select>`;
}
function it({ messages: r, sunlightingEnabled: e, onSunLightingToggle: t, scale: i }) {
  return m`<calcite-label layout=inline .scale=${i} title=${r?.tooltip ?? J}><calcite-checkbox .scale=${i} .checked=${e} @calciteCheckboxChange=${(n) => t(n.target.checked)}></calcite-checkbox>${r?.label}</calcite-label>`;
}
function rt({ messages: r, shadowEnabled: e, onShadowCheckboxChange: t, scale: i }) {
  return m`<calcite-label layout=inline .scale=${i} title=${r?.tooltip ?? J}><calcite-checkbox .checked=${e} @calciteCheckboxChange=${(n) => t(n.target.checked)}></calcite-checkbox>${r.label}</calcite-label>`;
}
de("arcgis-daylight", Xe);
export {
  Xe as ArcgisDaylight
};
