import { c as _e } from "../../chunks/runtime.js";
import { safeStyleMap as ce, nothing as H, safeClassMap as be, LitElement as ve, createEvent as q } from "@arcgis/lumina";
import { css as we, html as u } from "lit";
import { u as ye } from "../../chunks/useT9n.js";
import xe from "@arcgis/core/views/3d/environment/SunLighting.js";
import { m as J } from "../../chunks/handle.js";
import Se from "@arcgis/core/views/3d/environment/VirtualLighting.js";
import { ref as de, createRef as W } from "lit/directives/ref.js";
import * as K from "@arcgis/core/intl.js";
import { formatDate as V } from "@arcgis/core/intl.js";
import { u as De } from "../../chunks/useView.js";
import { g as Q } from "../../chunks/globalCss.js";
import { H as Te } from "../../chunks/heading.js";
import { createTrackingTarget as ke, runTracked as X, signal as Pe } from "@arcgis/core/applications/Components/reactiveUtils.js";
import { watch as ee, when as $e, whenOnce as Ce } from "@arcgis/core/core/reactiveUtils.js";
import { r as ze, b as Oe, d as Me } from "../../chunks/async-utils.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 Le = we`.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}@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}.wrapper{display:flex;flex-direction:column;overflow:hidden;gap:var(--calcite-spacing-md);justify-content:space-between;padding:var(--esri-widget-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{padding-block-end:var(--label-wrap-padding, 0)}.time-configuration{--date-play-button-offset: 11px;--slider-play-button-offset: 8px;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}}`;
Intl.DateTimeFormat().resolvedOptions().timeZone;
const te = {
  milliseconds: 1,
  seconds: 1e3,
  minutes: 6e4,
  hours: 36e5,
  days: 864e5,
  weeks: 6048e5,
  months: 26784e5,
  // 31 days
  years: 31536e6,
  // 365 days
  decades: 31536e7,
  centuries: 31536e8
};
function E(t, e, i) {
  return t === 0 ? 0 : t * te[e] / te[i];
}
function O(t) {
  return t instanceof Date && !Number.isNaN(t.getTime());
}
function $(t, e, i = "hours") {
  const r = new Date(t.getTime()), n = E(e, i, "milliseconds");
  return r.setTime(r.getTime() + n), r;
}
function T(t, e) {
  const i = E(e, "hours", "milliseconds"), r = new Date(t.getTime() + i), n = r.toISOString().slice(0, 10), s = r.getUTCHours() * 60 + r.getUTCMinutes();
  return { localDate: n, minutesSinceMidnight: s };
}
var I = Math.PI, p = Math.sin, k = Math.cos, Ue = Math.asin, Ee = Math.acos, y = I / 180, he = 1e3 * 60 * 60 * 24, ge = 2440588, ue = 2451545;
function Ae(t) {
  return t.valueOf() / he - 0.5 + ge;
}
function M(t) {
  return new Date((t + 0.5 - ge) * he);
}
function He(t) {
  return Ae(t) - ue;
}
var ie = y * 23.4397;
function Ie(t, e) {
  return Ue(p(e) * k(ie) + k(e) * p(ie) * p(t));
}
function Ne(t) {
  return y * (357.5291 + 0.98560028 * t);
}
function Fe(t) {
  return y * (1.9148 * p(t) + 0.02 * p(2 * t) + 3e-4 * p(3 * t));
}
function Re(t, e) {
  var i = y * 102.9372;
  return t + e + i + I;
}
var D = {};
D.PolarException = {
  NORMAL: 0,
  MIDNIGHT_SUN: 1,
  POLAR_NIGHT: 2
};
var R = [
  [-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"  ]
    */
], pe = 9e-4;
function je(t, e) {
  return Math.round(t - pe - e / (2 * I));
}
function re(t, e, i) {
  return pe + (t + e) / (2 * I) + i;
}
function ne(t, e, i) {
  return ue + t + 53e-4 * p(e) - 69e-4 * p(2 * i);
}
function Je(t, e, i) {
  return Ee((p(t) - p(e) * p(i)) / (k(e) * k(i)));
}
D.getTimes = function(t, e, i) {
  var r = y * -i, n = y * e, s = He(t), a = je(s, r), o = re(0, r, a), c = Ne(o), d = Fe(c), l = Re(c, d), h = Ie(l, 0), g = ne(o, c, l);
  function w(F) {
    var z = Je(F, n, h), fe = re(z, r, a);
    return ne(fe, c, l);
  }
  function x(F) {
    var z = (p(F) - p(n) * p(h)) / (k(n) * k(h));
    return z < -1 ? D.PolarException.MIDNIGHT_SUN : z > 1 ? D.PolarException.POLAR_NIGHT : D.PolarException.NORMAL;
  }
  var _ = {
    solarNoon: M(g),
    nadir: M(g - 0.5),
    polarException: D.PolarException.NORMAL
  }, b, f, C, N, Y;
  for (b = 0, f = R.length; b < f; b += 1)
    C = R[b], N = w(C[0] * y), Y = g - (N - g), _[C[1]] = M(Y), _[C[2]] = M(N);
  return _.polarException = x(R[0][0] * y), _;
};
const Ve = {
  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
}, Z = ["spring", "summer", "fall", "winter"];
function P(t, e, i) {
  const r = B(e, i), { dayOfMonth: n, month: s } = Ve[r], a = new Date(t.getTime());
  return a.setMonth(s, n), a;
}
function Ze(t, e) {
  const i = Be(t);
  return B(i, e);
}
function Be(t) {
  const e = t.getTime(), i = P(t, "spring", "northern").getTime(), r = P(t, "summer", "northern").getTime(), n = P(t, "fall", "northern").getTime(), s = P(t, "winter", "northern").getTime();
  return e >= i && e < r ? "spring" : e >= r && e < n ? "summer" : e >= n && e < s ? "fall" : "winter";
}
function B(t, e) {
  return e === "northern" ? t : Ge(t);
}
function se(t) {
  return t >= 0 ? "northern" : "southern";
}
function Ge(t) {
  const e = Z.indexOf(t);
  return Z[(e + 2) % 4];
}
const A = 1440, Ye = 864e5;
function qe(t, e, i, r) {
  const n = D.getTimes(t, e, i), s = n.sunrise, a = n.sunset, o = $(t, r), c = $(s, r), d = $(a, r);
  if (o.getUTCDate() !== c.getUTCDate() || o.getUTCDate() !== d.getUTCDate()) {
    const l = o.getTime() - c.getTime() > 0 ? 1 : -1;
    s.setUTCDate(s.getUTCDate() + l), a.setUTCDate(a.getUTCDate() + l);
  }
  return {
    sunrise: s,
    sunset: a
  };
}
function m(t) {
  return t?.type === "sun";
}
function G(t, e) {
  return (t % e + e) % e;
}
const me = {
  hour: "numeric",
  minute: "numeric",
  timeZone: "UTC"
}, We = {
  hour: "numeric",
  timeZone: "UTC"
};
function Ke(t) {
  const e = Math.round(E(t, "minutes", "hours"));
  return new Date(E(e, "hours", "milliseconds"));
}
function Qe(t) {
  return new Date(t * 6e4);
}
function Xe(t) {
  const e = Ke(t);
  let i = V(e, me);
  if (i.includes(" ")) {
    i = V(e, We), i = i.replace(":00", "");
    const r = "⁠";
    i = i.split(" ").map((n) => Array.from(n).join(r)).join(" ");
  }
  return i;
}
function et(t) {
  const e = Qe(t);
  let i = V(e, me);
  return t !== 0 && i === "00:00" && (i = "24:00"), i;
}
const tt = (t, e) => {
  switch (e) {
    case "tick":
      return Xe(t);
    case "max":
    case "min":
    case "value":
      return et(t);
  }
}, it = A - 1, rt = it / 4;
function nt(t) {
  return u`<calcite-slider class="slider" .disabled=${t.disabled} fill-placement=none label-ticks label-handles .labelFormatter=${tt} min=0 .max=${A - 1} @calciteSliderInput=${(e) => {
    const i = Array.isArray(e.target.value) ? e.target.value[0] : e.target.value;
    i != null && t.onTimeChanged(i);
  }} .scale=${t.scale} .step=${t.steps} snap style=${ce({ gridArea: "slider" })} .ticks=${rt} .value=${G(t.value ?? 0, A)} ${de(t.ref)}></calcite-slider>`;
}
function st(t, e) {
  return t / 15;
}
function at(t, e) {
  const i = t?.[0];
  if (i == null)
    return null;
  e || (e = { hours: 0, minutes: 0, seconds: 0 }), e.hours = st(i);
  const r = e.hours % 1;
  e.hours -= r, e.minutes = r * 60;
  const n = e.minutes % 1;
  return e.minutes -= n, e.seconds = Math.round(n * 60), e;
}
function ot(t) {
  const e = at([t.longitude, t.latitude]);
  return e == null ? 0 : Math.round(e.hours + e.minutes / 60 + e.seconds / 3600);
}
const lt = 100, ct = 1e3, v = 12e5, L = 72e5;
function ae(t, e) {
  return G(t + e, 24);
}
function dt({
  mode: t,
  lighting: e,
  getPlaySpeed: i,
  onProgress: r,
  beforeProgress: n
}) {
  let s = -1;
  function a(o = Date.now()) {
    const c = e.date, d = Date.now() - (o ?? 0);
    if (t === "day") {
      o = Date.now();
      const h = i() / lt * d;
      if (h > 0) {
        let g = new Date(c.getTime() + h);
        const w = e.displayUTCOffset ?? 0, x = ae(g.getUTCHours(), w), _ = ae(c.getUTCHours(), w);
        x < _ && (g = new Date(c.getTime() + h - Ye));
        const b = e.clone();
        n?.(), e.date = g, r?.(b, e);
      }
    } else if (d > ct) {
      o = Date.now();
      const l = (c.getUTCMonth() + 1) % 12, h = new Date(c.getTime());
      h.setUTCMonth(l);
      const g = e.clone();
      n?.(), e.date = h, r?.(g, e);
    }
    s = requestAnimationFrame(() => a(o));
  }
  return a(), J(() => cancelAnimationFrame(s));
}
const U = v / 4;
function ht(t, e, i, r) {
  const {
    day: n,
    night: s = n,
    twilight: a = n
  } = r, o = n * U, c = s * U, d = a * U;
  if (t == null || e == null || Number.isNaN(t.getTime()) && Number.isNaN(e.getTime()))
    return o;
  const l = i.getTime(), h = t.getTime(), g = e.getTime(), w = h - L / 2, x = h + L / 2, _ = g - L / 3 * 2, b = g + L / 3;
  let f = o;
  return l >= w && l <= x ? l - w <= v ? f = c - (l - w) / v * (c - d) : x - l <= v / 2 ? f = o - (x - l) / v * 2 * (o - d) : f = d : l >= _ && l <= b ? l - _ <= v / 2 ? f = o - (l - _) / v * 2 * (o - d) : b - l <= v ? f = c - (b - l) / v * (c - d) : f = d : (l < h || l > g) && (f = c), f;
}
function S(t) {
  return t.hidden ? null : t.children;
}
function oe(t) {
  const { children: e, hideHeader: i, headingLevel: r = 2, label: n, title: s } = t;
  return u`<div aria-label=${n ?? H} class=${be({
    ...typeof t.class == "string" ? { [t.class]: !0 } : t.class,
    [Q.widget]: !0,
    [Q.panel]: !0
  })} role=presentation>${S({ hidden: i || !s, children: Te({ level: r, children: s }) })}${e}</div>`;
}
class gt {
  #t;
  #r;
  #n = ke(() => {
    this.#i();
  });
  constructor(e) {
    this.#r = e;
    let i;
    X(this.#n, () => {
      i = e();
    }), this.#t = Pe(i);
  }
  #i() {
    const e = this.#t.value;
    X(this.#n, () => {
      this.#t.value = this.#r(e);
    });
  }
  mutate(e) {
    this.#t.value = e;
  }
  get value() {
    return this.#t.value;
  }
}
function j(t) {
  return new gt(t);
}
const ut = {
  day: 1,
  night: 6,
  twilight: 2 / 3
};
class pt extends ve {
  constructor() {
    super(...arguments), this.messages = ye({ blocking: !0 }), this.#r = "none", this.#n = null, this.#o = W(), this.#s = W(), this.#d = 200, this.#h = 200, this.#e = {}, this._offset = j((e) => m(this._lighting) ? this._lighting.displayUTCOffset ?? e : e), this._timesliderPosition = j((e) => {
      if (m(this._lighting)) {
        const i = this._lighting.displayUTCOffset ?? 0, r = this._lighting.date;
        if (O(r)) {
          const { minutesSinceMidnight: n } = T(r, i);
          return n;
        } else
          return e;
      }
      return e;
    }), this._localDate = j((e) => {
      if (m(this._lighting)) {
        const i = this._lighting.displayUTCOffset ?? 0, r = this._lighting.date;
        if (O(r)) {
          const { localDate: n } = T(r, i);
          return n;
        } else
          return e;
      }
      return e;
    }), this.view = De(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 = q(), this.arcgisUserDateTimeChange = q(), this.#c = !1;
  }
  static {
    this.properties = { 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, position: 1, referenceElement: 1, timeSliderSteps: 9, utcOffset: 9, timeSliderPosition: 9, localDate: 1, yearPlaying: 5 };
  }
  static {
    this.styles = Le;
  }
  get _view() {
    return this.view?.type === "3d" ? this.view : void 0;
  }
  #t;
  #r;
  #n;
  #i;
  #o;
  #s;
  #d;
  #h;
  #l() {
    if (this.#i)
      return;
    const e = ze(() => {
      if (this.#i?.remove(), m(this._lighting)) {
        const i = this.utcOffset ?? 0, r = this.timeSliderPosition ?? 0, n = this.localDate, s = r - i * 60, a = $(n, s, "minutes");
        this._lighting.date = a, this._lighting.displayUTCOffset = i;
      }
    }, { timeout: this.#d });
    this.#i = J(() => {
      Me(e), this.#i = void 0;
    });
  }
  #u({ scale: e, disabled: i }) {
    const { messages: r } = this;
    return u`<calcite-label .scale=${e} class="date-picker-container">${r.date}${mt({ disabled: i, scale: e, date: this.localDateAsString, onDateChange: (n) => {
      const s = n.currentTarget.value, a = Array.isArray(s) ? s[0] : s;
      this._stopPlaying(), this.localDate = a, this._emitUserDateTimeChangeEvent();
    } })}</calcite-label>${S({ hidden: this.hidePlayButtons, children: le({ playing: this.yearPlaying, disabled: i, label: r.playYear, onClick: () => {
      this._playingState === "year" ? this._playingState = "none" : this._playingState = "year";
    }, scale: e }) })}`;
  }
  #p({ scale: e, disabled: i }) {
    const { messages: r } = this;
    return u`<calcite-label .scale=${e} class="date-picker-container">${r.season}${ft({ scale: e, selectedSeason: this.currentSeason, disabled: i, messages: r, onSeasonChange: (n) => {
      this._stopPlaying(), this.currentSeason = n.currentTarget.value;
    } })}</calcite-label>`;
  }
  #e;
  get #g() {
    return Array.isArray(this.#s?.value?.value) ? this.#s?.value?.value[0] : this.#s?.value?.value;
  }
  get localDateAsString() {
    return this._localDate.value ?? "";
  }
  get _playingState() {
    return this.#r;
  }
  set _playingState(e) {
    this.#r = e, this.#a?.remove(), e === "none" ? this.#t?.remove() : (this._play(e), this._emitUserDateTimeChangeEvent());
  }
  get _lighting() {
    return this._view?.environment?.lighting;
  }
  get _sunlightingDisabled() {
    return !m(this._lighting);
  }
  set _sunlightingDisabled(e) {
    this.#e.sunlightingDisabled = e;
    const i = this._view?.environment;
    if (i == null)
      return;
    const r = i.lighting, n = this.#n;
    this.#n = r;
    const s = {
      directShadowsEnabled: r.directShadowsEnabled
    };
    m(r) && (s.cameraTrackingEnabled = r.cameraTrackingEnabled);
    const a = e ? "virtual" : "sun";
    let o;
    n != null && n.type === a ? o = n : o = e ? new Se() : new xe(), o.set(s), i.lighting = o, e || (this._stopPlaying(), this.#o.value && (this.#o.value.open = !1));
  }
  get currentSeason() {
    const e = this._view?.camera?.position?.latitude ?? 0, i = se(e);
    return Ze(this.localDate, i);
  }
  set currentSeason(e) {
    this._stopPlaying();
    const i = this._view?.camera?.position?.latitude ?? 0, r = se(i), n = B(e, r);
    this.localDate = P(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.#e.directShadowsDisabled = e, this._lighting && (this._lighting.directShadowsEnabled = !e);
  }
  get utcOffset() {
    return this._offset.value;
  }
  set utcOffset(e) {
    this._offset.mutate(e), this.#l();
  }
  get timeSliderPosition() {
    return this._timesliderPosition.value;
  }
  set timeSliderPosition(e) {
    this._timesliderPosition.mutate(G(e ?? 0, A)), this.#l();
  }
  get localDate() {
    return this._localDate.value != null ? new Date(this._localDate.value) : /* @__PURE__ */ new Date();
  }
  set localDate(e) {
    const i = new Date(e);
    if (O(i)) {
      i.setUTCFullYear(i.getFullYear(), i.getMonth(), i.getDate());
      const r = i.toISOString().slice(0, 10);
      this._localDate.mutate(r), this.#l();
    }
  }
  get yearPlaying() {
    return this._playingState === "year";
  }
  set yearPlaying(e) {
    this._playingState = e ? "year" : "none";
  }
  async destroy() {
    await this.manager.destroy();
  }
  async load() {
    this.#e.utcOffset = this.utcOffset, this.#e.timeSliderPosition = this.timeSliderPosition, this.#e.localDate = this.localDateAsString, this.manager.onLifecycle(() => [
      ee(() => {
        let e = null;
        if (m(this._lighting)) {
          const i = this._lighting.displayUTCOffset ?? 0, r = this._lighting.date;
          if (O(r)) {
            const { minutesSinceMidnight: n } = T(r, i);
            e = n;
          }
        }
        return e;
      }, (e) => {
        const i = this.#g;
        e != null && i !== e && this._emitUserDateTimeChangeEvent();
      }, { sync: !0 }),
      ee(() => {
        const e = this._view?.camera?.position;
        return e ? ot(e) : void 0;
      }, (e) => {
        const i = this._lighting;
        m(i) && i.cameraTrackingEnabled && (i.displayUTCOffset = e);
      }, { sync: !0, initial: !0 }),
      $e(() => !m(this._lighting), () => {
        this._stopPlaying();
      }),
      K.onLocaleChange(() => {
        this.requestUpdate();
      })
    ]), this.manager.onDisconnected(() => {
      this.#t?.remove(), this.#i?.remove(), this.#a?.remove();
    });
  }
  willUpdate(e) {
    if (super.willUpdate(e), !!this.#c && m(this._lighting) && e.has("utcOffset")) {
      const i = this.utcOffset ?? 0, r = this._lighting.displayUTCOffset ?? 0, n = this.timeSliderPosition ?? 0, s = this.localDate, a = n - r * 60, o = $(s, a, "minutes"), { minutesSinceMidnight: c, localDate: d } = T(o, i);
      this._timesliderPosition.mutate(c), this._localDate.mutate(d);
    }
  }
  updated(e) {
    super.updated(e), this._adjustTimeSliderLabels();
  }
  #c;
  async loaded() {
    const e = new AbortController();
    this.manager.onDisconnected(() => ({
      remove: () => {
        e.abort();
      }
    })), await Oe(Ce(() => this._view?.ready, { signal: e.signal }).then(() => {
      this.utcOffset = this.#e.utcOffset ?? this.utcOffset, this.timeSliderPosition = this.#e.timeSliderPosition ?? this.timeSliderPosition, this.localDate = this.#e.localDate ?? this.localDate, this.#e.directShadowsDisabled != null && (this._directShadowsDisabled = this.#e.directShadowsDisabled), this.#e.sunlightingDisabled != null && (this._sunlightingDisabled = this.#e.sunlightingDisabled), this.#e = {};
    })), this.#c = !0;
  }
  _adjustTimeSliderLabels() {
    const e = this.#s.value;
    e && vt(e, K.getLocale());
  }
  _emitUserDateTimeChangeEvent() {
    this.isConnected && this.arcgisUserDateTimeChange.emit();
  }
  _stopPlaying() {
    this._playingState = "none";
  }
  #a;
  #m(e) {
    if (this.#a)
      return;
    const i = setTimeout(() => {
      const r = e.displayUTCOffset ?? 0, n = e.date, { minutesSinceMidnight: s } = T(n, r);
      this._timesliderPosition.mutate(s), this.#a?.remove();
    }, this.#h);
    this.#a = J(() => {
      clearTimeout(i), this.#a = void 0;
      const r = this._lighting;
      if (m(r)) {
        const n = r.displayUTCOffset ?? 0, s = r.date, { minutesSinceMidnight: a } = T(s, n);
        this._timesliderPosition.mutate(a);
      }
    });
  }
  _play(e) {
    this.#t?.remove();
    const i = this._view;
    if (i == null || this._sunlightingDisabled)
      return;
    const r = i.environment.lighting;
    if (!m(r))
      return;
    let n = 0;
    this.#t = dt({
      mode: e,
      lighting: r,
      beforeProgress: () => {
        n = this.#g ?? 0;
      },
      onProgress: (s, a) => {
        this._timesliderPosition.mutate(n), this.#m(a);
      },
      getPlaySpeed: () => {
        const s = this._view, a = this._view?.environment.lighting;
        if (s != null && m(a)) {
          const o = s.camera.position.latitude ?? 0, c = s.camera.position.longitude ?? 0, { sunrise: d, sunset: l } = qe(a.date, o, c, a.displayUTCOffset ?? 0);
          return ht(d, l, a.date, ut) * this.playSpeedMultiplier;
        } else
          return U * this.playSpeedMultiplier;
      }
    });
  }
  render() {
    const { messages: e, dateOrSeason: i } = this, r = this._sunlightingDisabled, n = "m";
    if (!(this._view?.type === "3d"))
      return oe({ class: "wrapper", label: e.componentLabel, title: e.title, hideHeader: this.hideHeader, headingLevel: this.headingLevel, children: u`<div class="unsupported"><p>${e.unsupported}</p></div>` });
    const a = (this.utcOffset ?? 0) * 60, o = this.view?.ready === !0, c = Array.isArray(this.timeSliderSteps) ? this.timeSliderSteps.at(0) : this.timeSliderSteps;
    return oe({ class: { wrapper: !0, loading: !o }, label: e.componentLabel, title: e.title, hideHeader: this.hideHeader, headingLevel: this.headingLevel, children: u`${o ? void 0 : u`<calcite-scrim loading></calcite-scrim>`}<div class="time-configuration" style=${ce({ columnGap: this.hidePlayButtons ? "0" : void 0 })}><calcite-label class="slider-container" .scale=${n}>${e.timeSliderLabel}${nt({ ref: this.#s, disabled: this._sunlightingDisabled, scale: n, value: this.timeSliderPosition ?? 0, steps: c, onTimeChanged: (d) => {
      this._stopPlaying(), this._emitUserDateTimeChangeEvent(), this.timeSliderPosition = d;
    } })}</calcite-label>${S({ hidden: this.hidePlayButtons, children: le({ disabled: this._sunlightingDisabled, playing: this.dayPlaying, label: e.playDay, onClick: () => {
      this._playingState === "day" ? this._stopPlaying() : this._playingState = "day";
    }, scale: n }) })}${S({ hidden: this.hideTimezone, children: u`<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=${`${a}`} .referenceDate=${this.localDateAsString} @calciteInputTimeZoneChange=${(d) => {
      const l = +d.target.value;
      this.utcOffset = l / 60, this._stopPlaying();
    }} ${de(this.#o)}></calcite-input-time-zone></calcite-label><span></span>` })}${S({ hidden: this.hideDatePicker, children: i === "date" ? this.#u({ scale: n, disabled: r }) : this.#p({ scale: n, disabled: r }) })}</div>${S({ hidden: this.hideSunLightingToggle, children: _t({ scale: n, messages: e.sunLightingToggle, sunlightingEnabled: !this._sunlightingDisabled, onSunLightingToggle: (d) => {
      this._sunlightingDisabled = !d;
    } }) })}${S({ hidden: this.hideShadowsToggle, children: bt({ scale: n, messages: e.shadowsToggle, onShadowCheckboxChange: (d) => {
      this._directShadowsDisabled = !d;
    }, shadowEnabled: !this._directShadowsDisabled }) })}` });
  }
}
function le({ disabled: t, playing: e, onClick: i, label: r, scale: n = "m" }) {
  return u`<calcite-button appearance=solid .scale=${n} .disabled=${t} .iconStart=${e ? "pause-f" : "play-f"} .label=${r} @click=${i} round title=${r ?? H} type=button></calcite-button>`;
}
function mt({ disabled: t, date: e, onDateChange: i, scale: r }) {
  return u`<calcite-input-date-picker data-testid=daylight-date-picker .disabled=${t} overlay-positioning=fixed placement=bottom .value=${e} .scale=${r} @calciteInputDatePickerChange=${i}></calcite-input-date-picker>`;
}
function ft({ messages: t, disabled: e, scale: i, selectedSeason: r, onSeasonChange: n }) {
  return u`<calcite-select .disabled=${e} .label=${t.season} .scale=${i} .value=${r} @calciteSelectChange=${(s) => {
    n(s);
  }}>${Z.map((s) => u`<calcite-option .selected=${r === s} .value=${s}>${t[s]}</calcite-option>`)}</calcite-select>`;
}
function _t({ messages: t, sunlightingEnabled: e, onSunLightingToggle: i, scale: r }) {
  return u`<calcite-label layout=inline .scale=${r} title=${t?.tooltip ?? H}><calcite-checkbox .scale=${r} .checked=${e} @calciteCheckboxChange=${(n) => i(n.target.checked)}></calcite-checkbox>${t?.label}</calcite-label>`;
}
function bt({ messages: t, shadowEnabled: e, onShadowCheckboxChange: i, scale: r }) {
  return u`<calcite-label layout=inline .scale=${r} title=${t?.tooltip ?? H}><calcite-checkbox .checked=${e} @calciteCheckboxChange=${(n) => i(n.target.checked)}></calcite-checkbox>${t.label}</calcite-label>`;
}
function vt(t, e) {
  const i = yt(e), r = i?.language ?? "", n = i?.region ?? "", s = ["ar", "bg", "el", "en", "ko"].includes(r) || r === "zh" && ["HK", "TW"].includes(n);
  if (t.style.setProperty("--label-wrap-padding", s ? "5px" : "0"), t.style.setProperty("--label-wrapping", s ? "normal" : "nowrap"), !t.hasAttribute("data-slider-label-stylesheet-attatched") && t.shadowRoot) {
    const a = t.shadowRoot.adoptedStyleSheets, o = new CSSStyleSheet();
    o.replaceSync(`
      .tick__label {
        text-align: center;
        white-space: var(--label-wrapping, normal);
      }
    `), t.shadowRoot.adoptedStyleSheets = [...a, o], t.toggleAttribute("data-slider-label-stylesheet-attatched", !0);
  }
}
const wt = /^(?<language>[a-z]{2,3})(?:-(?<extlang>[a-z]{3}))?(?:-[A-Z][a-z]{3})?(?:-(?<region>[A-Z]{2}|\d{3}))?(?:-.*)?$/u;
function yt(t) {
  return wt.exec(t)?.groups;
}
_e("arcgis-daylight", pt);
export {
  pt as ArcgisDaylight
};
