import { c as q } from "../../chunks/runtime.js";
import { keyed as K } from "lit/directives/keyed.js";
import { LitElement as j, createEvent as T, safeClassMap as C, safeStyleMap as z, nothing as D } from "@arcgis/lumina";
import { makeAccessorController as G } from "@arcgis/lumina/controllers/accessor";
import { slotChangeHasAssignedElement as L, classes as W, getClosestElement as Y } from "@arcgis/toolkit/dom";
import { css as J, html as b } from "lit";
import { map as Q } from "lit/directives/map.js";
import { createRef as A, ref as S } from "lit/directives/ref.js";
import { u as Z } from "../../chunks/useT9n.js";
import ee from "@arcgis/core/core/Accessor.js";
import { property as k, subclass as te } from "@arcgis/core/core/accessorSupport/decorators.js";
import { watch as F } from "@arcgis/core/core/reactiveUtils.js";
import { generateGuid as O } from "@arcgis/toolkit/string";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
v5.0.0-next.137 */
const ae = J`:host{display:flex;width:100%;height:100%;font-family:Avenir Next,Helvetica Neue,helvetica,arial,sans-serif;font-size:var(--calcite-font-size--2);font-variant-numeric:tabular-nums;--arcgis-slider-dash-length: 5px;--arcgis-slider-handle-size: .875rem;--arcgis-slider-track-background-color: var(--calcite-color-border-2);--arcgis-slider-internal-show-range-labels: 0;--arcgis-slider-internal-show-value-labels: 0;--arcgis-slider-internal-value-labels-placement-leading: 0;--arcgis-slider-internal-value-labels-placement-trailing: 0;--arcgis-slider-internal-range-labels-placement-center: 0;--arcgis-slider-internal-range-labels-placement-trailing: 0;--arcgis-slider-internal-handle-offset: calc(var(--arcgis-slider-handle-size) / 2);--arcgis-slider-internal-label-input-margin: calc(var(--arcgis-slider-internal-handle-offset) + 4px);--arcgis-slider-internal-label-input-height: var(--calcite-input-number-height, 1.5rem);--arcgis-slider-internal-track-size: 2px}:host([show-range-labels]){--arcgis-slider-internal-show-range-labels: 1}:host(:not([value-labels-display="hidden"])){--arcgis-slider-internal-show-value-labels: 1}:host([value-labels-placement="leading"]){--arcgis-slider-internal-value-labels-placement-leading: var(--arcgis-slider-internal-show-value-labels)}:host([value-labels-placement="trailing"]){--arcgis-slider-internal-value-labels-placement-trailing: var(--arcgis-slider-internal-show-value-labels)}:host([range-labels-placement="center"]){--arcgis-slider-internal-range-labels-placement-center: var(--arcgis-slider-internal-show-range-labels)}:host([range-labels-placement="trailing"]){--arcgis-slider-internal-range-labels-placement-trailing: var(--arcgis-slider-internal-show-range-labels)}:host([disabled]){cursor:default;opacity:var(--calcite-opacity-disabled);pointer-events:none}.content{direction:ltr;flex:1;touch-action:none;user-select:none;display:grid;word-wrap:normal;word-break:normal;padding-block:var(--arcgis-slider-internal-handle-offset)}.track-container{grid-area:track-container;position:relative;display:flex;justify-content:center;align-items:center}.track{touch-action:none;position:relative}.track-bounds{background-color:var(--calcite-color-border-2)}.track-fill{--arcgis-slider-track-background-color: var(--calcite-color-brand)}:host([layout="vertical"]){.track-effective-leading{background:repeating-linear-gradient(to bottom,var(--arcgis-slider-track-background-color) 0 var(--arcgis-slider-dash-length),color-mix(in srgb,transparent 75%,var(--arcgis-slider-track-background-color) 25%) var(--arcgis-slider-dash-length) calc(var(--arcgis-slider-dash-length) * 2))}.track-effective-trailing{background:repeating-linear-gradient(to top,var(--arcgis-slider-track-background-color) 0 var(--arcgis-slider-dash-length),color-mix(in srgb,transparent 75%,var(--arcgis-slider-track-background-color) 25%) var(--arcgis-slider-dash-length) calc(var(--arcgis-slider-dash-length) * 2))}}:host([layout="horizontal"]){.track-effective-leading{background:repeating-linear-gradient(to right,var(--arcgis-slider-track-background-color) 0 var(--arcgis-slider-dash-length),color-mix(in srgb,transparent 75%,var(--arcgis-slider-track-background-color) 25%) var(--arcgis-slider-dash-length) calc(var(--arcgis-slider-dash-length) * 2))}.track-effective-trailing{background:repeating-linear-gradient(to left,var(--arcgis-slider-track-background-color) 0 var(--arcgis-slider-dash-length),color-mix(in srgb,transparent 75%,var(--arcgis-slider-track-background-color) 25%) var(--arcgis-slider-dash-length) calc(var(--arcgis-slider-dash-length) * 2))}}.track-range{background-color:var(--calcite-color-brand);&.active{box-shadow:0 0 8px #00000029;outline:1px solid var(--calcite-color-focus, var(--calcite-color-focus, var(--calcite-color-brand)))}}:host([disabled]) .track-range{background-color:var(--calcite-color-text-3)}:host([layout="horizontal"]){.track-range.interactive{&:after{all:initial;cursor:ew-resize;position:absolute;inline-size:100%;content:"";inset-block-start:calc(-1 * var(--arcgis-slider-internal-handle-offset));block-size:var(--arcgis-slider-handle-size);margin-top:1px}}}:host([layout="vertical"]){.track-range.interactive{&:after{all:initial;cursor:ns-resize;position:absolute;inline-size:100%;content:"";inset-block-start:var(--arcgis-slider-internal-handle-offset);block-size:var(--arcgis-slider-handle-size);margin-left:1px}}}.segment{transform-origin:0 0;inset-block-start:0px;block-size:.125rem;position:absolute;top:0;left:0}.thumb{-webkit-user-select:none;user-select:none;background-color:#4c4c4c;position:absolute}.thumb:focus,.thumb.active{.handle{background-color:var(--calcite-color-brand);box-shadow:0 0 8px #00000029;outline:2px solid var(--calcite-color-focus, var(--calcite-color-focus, var(--calcite-color-brand)));outline-offset:calc(2px*(1 - (2*clamp(0,var(--calcite-offset-invert-focus),1))))}}.handle{cursor:pointer;box-sizing:border-box;z-index:1;touch-action:none;background-color:var(--calcite-color-foreground-1);box-shadow:0 0 0 2px var(--calcite-color-text-3) inset;border-radius:var(--arcgis-slider-handle-size);width:var(--arcgis-slider-handle-size);height:var(--arcgis-slider-handle-size);transition:all .125s ease-in-out;position:absolute;top:calc(var(--arcgis-slider-internal-handle-offset) * -1);left:calc(var(--arcgis-slider-internal-handle-offset) * -1)}.handle:hover{box-shadow:0 0 0 3px var(--calcite-color-brand) inset}.label{position:absolute;will-change:transform}.label[hidden]{display:block;opacity:0;pointer-events:none}.min{grid-area:range-start}.max{grid-area:range-end}:host([layout="horizontal"][mirrored][range-labels-placement="center"]),:host([layout="vertical"]:not([mirrored])){.min{grid-area:range-end}.max{grid-area:range-start}}.content-start{grid-area:content-start;display:flex}.content-end{grid-area:content-end;display:flex}:host([layout="vertical"]){.content{grid-template:". range-start range-start range-start ." "content-start content-start track-container content-end content-end" ". range-end range-end range-end .";grid-template-rows:auto 1fr auto;grid-template-columns:1fr auto auto auto 1fr;row-gap:var(--arcgis-slider-internal-handle-offset)}.track-container{flex-direction:column}.track{flex:1;width:var(--arcgis-slider-internal-track-size)}.segment{writing-mode:vertical-lr}.label{top:calc(var(--arcgis-slider-internal-label-input-height) * -.5)}&:host([value-labels-placement="leading"]){.label{right:var(--arcgis-slider-internal-label-input-margin)}}&:host([value-labels-placement="trailing"]){.label{left:var(--arcgis-slider-internal-label-input-margin)}}}:host([layout="horizontal"][range-labels-placement="center"]){.content{--arcgis-slider-internal-content-start-min-height: calc( ((1 - var(--arcgis-slider-internal-show-range-labels)) * var(--arcgis-slider-internal-handle-offset)) + ( var(--arcgis-slider-internal-value-labels-placement-leading) * var(--arcgis-slider-internal-label-input-height) ) );--arcgis-slider-internal-content-end-min-height: calc( ((1 - var(--arcgis-slider-internal-show-range-labels)) * var(--arcgis-slider-internal-handle-offset)) + ( var(--arcgis-slider-internal-value-labels-placement-trailing) * var(--arcgis-slider-internal-label-input-height) ) );column-gap:calc(var(--arcgis-slider-internal-show-range-labels) * var(--arcgis-slider-internal-handle-offset) / 2);padding-inline:calc((1 - var(--arcgis-slider-internal-show-range-labels)) * var(--arcgis-slider-internal-handle-offset));grid-template:". content-start ." "range-start content-start range-end" "range-start track-container range-end" "range-start content-end range-end" ". content-end .";grid-template-columns:auto 1fr auto;grid-template-rows:minmax(var(--arcgis-slider-internal-content-start-min-height),auto) calc(var(--arcgis-slider-internal-show-range-labels) * calc(calc(var(--arcgis-slider-internal-label-input-height) / 2) - calc(var(--arcgis-slider-internal-track-size) / 2))) var(--arcgis-slider-internal-track-size) calc(var(--arcgis-slider-internal-show-range-labels) * calc(calc(var(--arcgis-slider-internal-label-input-height) / 2) - calc(var(--arcgis-slider-internal-track-size) / 2))) minmax(var(--arcgis-slider-internal-content-end-min-height),auto)}.track{flex:1;height:var(--arcgis-slider-internal-track-size)}&:host([value-labels-placement="leading"]){.label{bottom:var(--arcgis-slider-internal-label-input-margin)}}&:host([value-labels-placement="trailing"]){.label{top:var(--arcgis-slider-internal-label-input-margin)}}}:host([layout="horizontal"][range-labels-placement="trailing"]){.content{--arcgis-slider-internal-content-start-min-height: calc( var(--arcgis-slider-internal-handle-offset) + var(--arcgis-slider-internal-value-labels-placement-leading) * var(--arcgis-slider-internal-label-input-height) );--arcgis-slider-internal-content-end-min-height: calc( var(--arcgis-slider-internal-value-labels-placement-trailing) * var(--arcgis-slider-internal-label-input-height) );padding-inline:var(--arcgis-slider-internal-handle-offset);grid-template:"content-start content-start content-start" "track-container track-container track-container" "content-end content-end content-end" "content-end content-end content-end" "content-end content-end content-end";grid-template-columns:auto;grid-template-rows:minmax(var(--arcgis-slider-internal-content-start-min-height),auto) var(--arcgis-slider-internal-track-size) var(--arcgis-slider-internal-handle-offset) calc(var(--arcgis-slider-internal-range-labels-placement-trailing) * var(--arcgis-slider-internal-label-input-height)) minmax(var(--arcgis-slider-internal-content-end-min-height),auto);column-gap:var(--arcgis-slider-internal-handle-offset)}.track{flex:1;height:var(--arcgis-slider-internal-track-size)}&:host([value-labels-placement="leading"]){.label{bottom:var(--arcgis-slider-internal-label-input-margin)}}&:host([value-labels-placement="trailing"]){.label{top:calc(var(--arcgis-slider-internal-label-input-margin) + var(--arcgis-slider-internal-range-labels-placement-trailing) * (var(--arcgis-slider-internal-label-input-height)))}}.min,.max{--arcgis-slider-internal-range-translation: calc(var(--arcgis-slider-internal-handle-offset) + .5rem + 1px);grid-area:unset;grid-row:-3}&:host(:not([mirrored])){.min{grid-column:1;transform:translate(calc(var(--arcgis-slider-internal-range-translation) * -1))}.max{grid-column:3;transform:translate(var(--arcgis-slider-internal-range-translation))}}&:host([mirrored]){.min{grid-column:3;transform:translate(var(--arcgis-slider-internal-range-translation))}.max{grid-column:1;transform:translate(calc(var(--arcgis-slider-internal-range-translation) * -1))}}}`;
var re = Object.defineProperty, ne = Object.getOwnPropertyDescriptor, w = (n, e, t, a) => {
  for (var i = a > 1 ? void 0 : a ? ne(e, t) : e, r = n.length - 1, l; r >= 0; r--)
    (l = n[r]) && (i = (a ? l(e, t, i) : l(i)) || i);
  return a && i && re(e, t, i), i;
};
function ie() {
  return {
    min: 0,
    max: 100,
    values: []
  };
}
let _ = class extends ee {
  //--------------------------------------------------------------------------
  //
  //  Lifecycle
  //
  //--------------------------------------------------------------------------
  constructor(n = {}) {
    super({ ...ie(), properties: n }), this._entries = /* @__PURE__ */ new Map(), this.precision = 4, this.ready = !1;
  }
  startup() {
    const { precision: n } = this;
    let { min: e, max: t, values: a } = this;
    t = v(t, n), e = v(e, n), a = a?.map((r) => E(v(r, n), e, t)), this._set("min", e), this._set("max", t), this._set("values", a);
    const i = new Map(a?.map((r) => [O(), r]));
    this._entries = i, F(
      () => this.min,
      (r) => {
        const l = this.values;
        r != null && l?.length && l.some((s) => s < r) && (this._entries.forEach((s, o) => {
          s < r && this._entries.set(o, r);
        }), this._updatesValues());
      },
      { sync: !0 }
    ), F(
      () => this.max,
      (r) => {
        const l = this.values;
        r != null && l?.length && l.some((s) => s > r) && (this._entries.forEach((s, o) => {
          s > r && this._entries.set(o, r);
        }), this._updatesValues());
      },
      { sync: !0 }
    ), F(
      () => this.precision,
      (r) => {
        const { min: l, max: s, values: o } = this;
        this._set("min", v(l, r)), this._set("max", v(s, r)), o?.length && (this._entries.forEach((c, d) => {
          this._entries.set(d, v(c, r));
        }), this._updatesValues());
      },
      { sync: !0 }
    ), this._set("ready", !0);
  }
  get entries() {
    return this._entries;
  }
  set max(n) {
    if (!this.ready) {
      this._set("max", n);
      return;
    }
    const e = this._get("max"), t = v(n, this.precision);
    e !== t && this._set("max", t);
  }
  set min(n) {
    if (!this.ready) {
      this._set("min", n);
      return;
    }
    const e = this._get("min"), t = v(n, this.precision);
    e !== t && this._set("min", t);
  }
  set values(n) {
    if (!this.ready) {
      this._set("values", n);
      return;
    }
    const e = this._get("values");
    if (n = n?.map((a) => E(v(a, this.precision), this.min, this.max)).sort((a, i) => a - i), e && n && e.length === n.length && e.every((a, i) => a === n[i]))
      return;
    const t = new Map(n?.map((a) => [O(), a]));
    this._entries = t, this._set("values", n);
  }
  //--------------------------------------------------------------------------
  //
  //  Public Methods
  //
  //--------------------------------------------------------------------------
  getValue(n) {
    return this._entries.get(n);
  }
  /**
   * Updates a thumb [value](#values) based on the provided index. The provided value
   * must differ from the previous value.
   * The provided value must also be between the [min](#min) and [max](#max).
   *
   * @returns `true` if the value was changed, otherwise `false`.
   */
  setValue(n, e) {
    if (this.values == null)
      return !1;
    const { min: t, max: a } = this, i = this._entries.get(n), r = E(v(e, this.precision), t, a);
    return i === r ? !1 : (this._entries.set(n, r), this._updatesValues(), !0);
  }
  setValues(n) {
    if (this.values == null)
      return !1;
    let e = !1;
    const { min: t, max: a } = this;
    for (const [i, r] of n) {
      const l = this._entries.get(i), s = E(v(r, this.precision), t, a);
      l !== s && (e = !0, this._entries.set(i, s));
    }
    return e ? (this._updatesValues(), !0) : !1;
  }
  _updatesValues() {
    const n = Array.from(this._entries.values()).sort((e, t) => e - t);
    this._set("values", n);
  }
};
w([
  k()
], _.prototype, "_entries", 2);
w([
  k({ readOnly: !0 })
], _.prototype, "entries", 1);
w([
  k()
], _.prototype, "max", 1);
w([
  k()
], _.prototype, "min", 1);
w([
  k({ cast: (n) => E(n, 0, 20) })
], _.prototype, "precision", 2);
w([
  k({ readOnly: !0 })
], _.prototype, "ready", 2);
w([
  k()
], _.prototype, "values", 1);
_ = w([
  te("esri.widgets.Slider.SliderData")
], _);
function E(n, e, t) {
  return Math.min(Math.max(n, e), t);
}
function v(n, e) {
  return Number.parseFloat(n.toFixed(e));
}
class se {
  constructor(e) {
    this.steps = e, this.minIndex = 0, this.maxIndex = this.steps.length - 1;
  }
  indexToValue(e) {
    return this.steps[I(e, this.minIndex, this.maxIndex)];
  }
  valueToIndex(e) {
    const t = this.steps.indexOf(e);
    return t !== -1 ? t : this.steps.reduce(
      (a, i, r, l) => Math.abs(i - e) < Math.abs(l[a] - e) ? r : a
    );
  }
}
class le {
  constructor(e, t, a) {
    this.min = e, this.max = t, this.stepSize = a, this.minIndex = 0, this.maxIndex = Math.round((this.max - this.min) / this.stepSize);
  }
  indexToValue(e) {
    return this.min + I(e, this.minIndex, this.maxIndex) * this.stepSize;
  }
  valueToIndex(e) {
    return e = I(e, this.min, this.max), Math.round((e - this.min) / this.stepSize);
  }
}
function oe(n) {
  if (n.steps == null)
    return null;
  const e = n.steps;
  return Array.isArray(e) ? e.length === 0 ? null : new se(e) : new le(n.min, n.max, e);
}
function ce(n, e, t) {
  if (n == null) {
    const s = /* @__PURE__ */ new Map();
    for (const [o, c] of e.entries())
      s.set(o, c + t);
    return s;
  }
  const a = e.size, i = Array.from(e.entries()).map(([s, o]) => {
    const c = o + t, d = [];
    for (let u = n.minIndex; u <= n.maxIndex; u++) {
      const h = n.indexToValue(u), m = Math.abs(h - c);
      let f = !1;
      for (let p = 0; p < d.length; p++)
        if (m < d[p].dist) {
          d.splice(p, 0, { idx: u, value: h, dist: m }), f = !0;
          break;
        }
      !f && d.length < a && d.push({ idx: u, value: h, dist: m }), d.length > a && (d.length = a);
    }
    return { uuid: s, stepDistances: d };
  }), r = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map();
  i.sort((s, o) => s.stepDistances[0].dist - o.stepDistances[0].dist);
  for (const s of i) {
    const o = s.stepDistances.find((c) => !r.has(c.idx));
    o ? (r.add(o.idx), l.set(s.uuid, o.value)) : l.set(s.uuid, e.get(s.uuid));
  }
  return l;
}
function B(n, e, t, a, i) {
  const r = e.get(t) ?? 0;
  if (!n)
    return r + a;
  const l = r + a, s = /* @__PURE__ */ new Set();
  if (!i)
    for (const [d, u] of e.entries())
      d !== t && s.add(n.valueToIndex(u));
  let o = null, c = 1 / 0;
  for (let d = n.minIndex; d <= n.maxIndex; d++) {
    if (s.has(d))
      continue;
    const u = n.indexToValue(d), h = Math.abs(u - l);
    h < c && (c = h, o = d);
  }
  return o == null ? r : n.indexToValue(o);
}
function de(n, e, t) {
  const a = /* @__PURE__ */ new Map(), i = t > 0 ? ge : X, r = Array.from(e).sort((o, c) => i(o[1], c[1]));
  let l = !1, s = !0;
  for (const [o, c] of r)
    if (a.set(o, c), s) {
      const d = N(n, a, o, t);
      c === d && (s = !1), l ||= s, a.set(o, d);
    }
  return { changed: l, entries: a };
}
function N(n, e, t, a) {
  const { allowValuesOverlap: i, stepsProvider: r, resolution: l, min: s, max: o } = n, c = e.get(t);
  if (a = a > 0 ? 1 : -1, !r) {
    let g = I(c + a * l, s, o);
    if (i)
      return g;
    const x = /* @__PURE__ */ new Set();
    for (const [P, $] of e)
      P !== t && x.add($);
    for (; x.has(g) && g <= o && g >= s; )
      g = I(g + a * l, s, o);
    return x.has(g) || g > o || g < s ? c : g;
  }
  const d = r.valueToIndex(c);
  if (d === -1)
    return c;
  if (i) {
    const g = I(d + a, r.minIndex, r.maxIndex);
    return r.indexToValue(g);
  }
  const u = /* @__PURE__ */ new Set();
  for (const [g, x] of e)
    g !== t && u.add(r.valueToIndex(x));
  let h = d, m = !1;
  const f = r.minIndex, p = r.maxIndex;
  let y = 0;
  for (; y < Math.abs(p - f) && (h += a, !(h < f || h > p)); ) {
    if (!u.has(h)) {
      m = !0;
      break;
    }
    y++;
  }
  return m ? r.indexToValue(h) : c;
}
function he(n, e, t, a) {
  const { allowValuesOverlap: i, stepsProvider: r, resolution: l, min: s, max: o } = n, c = e.get(t);
  if (a = a > 0 ? 1 : -1, !r) {
    const m = new Set(
      Array.from(e).filter(([p]) => p !== t).map(([, p]) => p)
    );
    let f = a > 0 ? o : s;
    if (i)
      return f;
    for (; m.has(f); )
      if (f -= a * l, a > 0 && f > o || a < 0 && f < s) {
        f = c;
        break;
      }
    return f;
  }
  if (i)
    return a > 0 ? r.indexToValue(r.maxIndex) : r.indexToValue(r.minIndex);
  const d = r.valueToIndex(c);
  if (d === -1)
    return c;
  const u = new Set(
    Array.from(e).filter(([m]) => m !== t).map(([, m]) => r.valueToIndex(m))
  );
  let h = a > 0 ? r.maxIndex : r.minIndex;
  for (; u.has(h); )
    if (h -= a, a > 0 && h > o || a < 0 && h < s) {
      h = d;
      break;
    }
  return r.indexToValue(h);
}
function ue(n, e, t) {
  const { stepsProvider: a, min: i, max: r } = n, l = /* @__PURE__ */ new Map(), s = Array.from(e).sort((c, d) => X(c[1], d[1]));
  if (a) {
    let c = 0;
    if (t > 0) {
      const d = s[s.length - 1], u = a.valueToIndex(d[1]);
      c = a.maxIndex - u;
    } else {
      const d = s[0], u = a.valueToIndex(d[1]);
      c = a.minIndex - u;
    }
    if (c === 0)
      for (const [d, u] of s)
        l.set(d, u);
    for (const [d, u] of s) {
      const h = a.indexToValue(a.valueToIndex(u) + c);
      l.set(d, h);
    }
    return l;
  }
  let o = 0;
  if (t > 0) {
    const c = s[s.length - 1];
    o = r - c[1];
  } else {
    const c = s[0];
    o = i - c[1];
  }
  for (const [c, d] of s)
    l.set(c, d + o);
  return l;
}
function X(n, e) {
  return n - e;
}
function ge(n, e) {
  return e - n;
}
function I(n, e, t) {
  return Math.max(e, Math.min(t, n));
}
const me = G(_);
class fe extends j {
  constructor() {
    super(...arguments), this._popoverElement = A(), this._trackElement = A(), this.messages = Z({}), this._onPointerMoveDragUpdate = (e) => {
      this._updateDrag(this._mapEventToRange(e));
    }, this._onPointerUpDragEnd = (e) => {
      R(e) && this._endDrag();
    }, this._onPointerCancelDragEnd = () => {
      this._endDrag();
    }, this._minFormatter = (e) => this._formatLabel(e, "min"), this._maxFormatter = (e) => this._formatLabel(e, "max"), this._valueFormatter = (e) => this._formatLabel(e, "value"), this._formatLabel = (e, t) => {
      const a = this.labelFormatter;
      if (!a)
        return this._defaultFormatter(e);
      const i = a(e, t, this._defaultFormatter);
      return i ?? this._defaultFormatter(e);
    }, this._defaultFormatter = (e) => this._numberFormatter.format(e), this._numberFormatter = new Intl.NumberFormat(this.messages._lang), this._resizeObserver = new ResizeObserver(() => {
      this._layoutLabelInputs();
    }), this._labelInputsUpdateComplete = null, this._dragInfo = null, this._hasPopoverContent = !1, this._hasContentStart = !1, this._hasContentEnd = !1, this._sliderData = me(this), this.allowValuesOverlap = !1, this.autoDestroyDisabled = !1, this.disabled = !1, this.fillPlacement = "start", this.layout = "horizontal", this.max = this._sliderData.max, this.min = this._sliderData.min, this.mirrored = !1, this.popoverLabel = "", this.popoverPlacement = "leading", this.precision = this._sliderData.precision, this.rangeLabelsEditingEnabled = !1, this.rangeLabelsPlacement = "center", this.segmentsDraggingDisabled = !1, this.showRangeLabels = !1, this.valueLabelsDisplay = "hidden", this.valueLabelsPlacement = "leading", this.valueLabelsEditingEnabled = !1, this.values = this._sliderData.values, this.arcgisActiveValueChange = T({ cancelable: !1 }), this.arcgisChange = T({ cancelable: !1 }), this.arcgisInput = T({ cancelable: !1 }), this.arcgisRangeChange = T({ cancelable: !1 });
  }
  static {
    this.properties = { _dragInfo: 16, _hasPopoverContent: 16, _hasContentStart: 16, _hasContentEnd: 16, _activePart: 16, _sliderData: 16, activeValue: 32, allowValuesOverlap: 5, autoDestroyDisabled: 5, disabled: [7, { useDefault: !0 }], fullRangeMax: 11, fullRangeMin: 11, fillPlacement: 1, labelFormatter: 0, layout: 3, max: 11, min: 11, mirrored: [7, { useDefault: !0 }], popoverLabel: 1, popoverPlacement: 3, precision: 11, rangeLabelsEditingEnabled: 5, rangeLabelsPlacement: 3, segmentsDraggingDisabled: 5, showRangeLabels: 7, steps: [9, { converter: {
      fromAttribute(e) {
        if (e.includes(","))
          return e.split(",").filter((a) => a.trim() !== "").map(parseFloat).filter((a) => Number.isFinite(a));
        const t = parseFloat(e);
        return Number.isFinite(t) ? t : void 0;
      }
    } }], valueLabelsDisplay: 3, valueLabelsPlacement: 3, valueLabelsEditingEnabled: 5, values: [1, { converter: {
      fromAttribute(e) {
        return e.includes(",") ? e.split(",").filter((t) => t.trim() !== "").map(parseFloat).filter((t) => Number.isFinite(t)) : [parseFloat(e)].filter((t) => Number.isFinite(t));
      }
    } }], messageOverrides: 0 };
  }
  static {
    this.styles = ae;
  }
  static {
    this.shadowRootOptions = { mode: "open", delegatesFocus: !0 };
  }
  get _fullMin() {
    return this.fullRangeMin ?? this.min;
  }
  get _fullMax() {
    return this.fullRangeMax ?? this.max;
  }
  get _fullRange() {
    return this._fullMax - this._fullMin;
  }
  get isHorizontal() {
    return this.layout === "horizontal";
  }
  get _trackWidthOrHeight() {
    const e = this._trackElement.value?.getBoundingClientRect();
    return e ? this.isHorizontal ? e.width : e.height : 0;
  }
  get _disabledOrInvalid() {
    return this.disabled || this.values.length === 0 || this._invalid;
  }
  get _invalid() {
    const e = this.fullRangeMin == null || this.fullRangeMax == null || this.fullRangeMin < this.fullRangeMax, t = this.fullRangeMin == null || this.fullRangeMin <= this.min, a = this.fullRangeMax == null || this.fullRangeMax >= this.max;
    return this.min >= this.max || !e || !t || !a;
  }
  get resolution() {
    const e = (this._sliderData.max - this._sliderData.min) / this._trackWidthOrHeight;
    return Math.max(e, 1 / Math.pow(10, this.precision));
  }
  get activeValue() {
    if (this._activePart)
      return this._activePart === "range" ? "all" : this._sliderData.getValue(this._activePart);
  }
  async destroy() {
    await this.manager.destroy();
  }
  load() {
    this._sliderData.startup();
  }
  willUpdate(e) {
    if ((e.has("steps") || e.has("min") || e.has("max")) && (this._stepsProvider = oe(this)), e.has("messages") || e.has("min") || e.has("max") || e.has("precision")) {
      const t = this.max != null && this.min != null && this.max - this.min > 10 ? 2 : this.precision;
      this._numberFormatter = new Intl.NumberFormat(this.messages._lang, {
        maximumFractionDigits: t
      });
    }
  }
  updated(e) {
    this._layoutLabelInputs();
    const t = this._popoverElement.value;
    t && (e.has("values") || e.has("min") || e.has("max")) && t.reposition();
  }
  loaded() {
    this._resizeObserver.observe(this.el);
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this._removeDragListeners();
  }
  _makeResizeRef() {
    let e = null;
    return (t) => {
      t ? (e = t, this._resizeObserver.observe(t)) : e && (this._resizeObserver.unobserve(e), e = null);
    };
  }
  async _layoutLabelInputs() {
    if (this.layout !== "horizontal" || !this._trackElement.value || this.valueLabelsDisplay === "hidden")
      return;
    const e = this.renderRoot.querySelectorAll("arcgis-label-input"), t = this.componentOnReady().then(() => Promise.all(Array.from(e, (r) => r.updateComplete)));
    if (this._labelInputsUpdateComplete = t, await t, t !== this._labelInputsUpdateComplete)
      return;
    this._labelInputsUpdateComplete = null;
    const { _trackElement: { value: a } } = this, i = a.getBoundingClientRect();
    for (const r of this._sliderData.entries.keys()) {
      const l = this._activePart === "range" || this._activePart === r;
      if (this.valueLabelsDisplay === "always" || l) {
        const o = _e(this, r), c = H(this, r);
        if (!o || !c)
          continue;
        const d = o.getBoundingClientRect(), u = c.getBoundingClientRect(), h = c.getLabelBoundingClientRect(), m = d.width / 2, f = Math.round(d.left + m), p = Math.round(h.width / 2);
        let y = u.width / 2;
        const g = i.left - m, x = i.right + m, P = f - p, $ = f + p;
        P < g ? y += P - g : $ > x && (y += $ - x), c.style.transform = `translateX(${-Math.round(y)}px)`;
      }
    }
  }
  _onTrackFocus() {
    this._setActivePart("range");
  }
  _onTrackBlur() {
    this._setActivePart(null);
  }
  _onTrackRangePointerDown(e) {
    this._disabledOrInvalid || !R(e) || this._startDrag("range", this._mapEventToRange(e));
  }
  async _onPointerDown(e) {
    if (this._disabledOrInvalid || !R(e))
      return;
    const t = this.renderRoot.querySelector("arcgis-label-input[editing]");
    if (e.target === t)
      return;
    if (t) {
      t.blur(), this._focusEntry(V(t));
      return;
    }
    if (pe(e.target) || this.values?.length > 1)
      return;
    const a = this._mapEventToRange(e), [i, r] = this._sliderData.entries.entries().next().value, l = a * this._fullRange + this._fullMin - r, s = M(this._fullMin, this._fullMax, r) / 100;
    this._startDrag(i, s);
    const o = B(this._stepsProvider, this._sliderData.entries, i, l, this.allowValuesOverlap);
    this._setValue(i, o), this._focusEntry(i);
  }
  _onThumbPointerDown(e) {
    const t = V(e.currentTarget);
    if (!R(e) || this._disabledOrInvalid || !t)
      return;
    const a = H(this, t);
    e.target === a && a?.editing || (e.stopPropagation(), this._startDrag(t, this._mapEventToRange(e)));
  }
  _endDrag() {
    if (this._disabledOrInvalid)
      return;
    this._removeDragListeners();
    let e = !1;
    if (this._dragInfo) {
      const { entries: t } = this._dragInfo;
      for (const [a, i] of t)
        if (this._sliderData.getValue(a) !== i) {
          e = !0;
          break;
        }
    }
    this._dragInfo = null, e && this.arcgisChange.emit();
  }
  _startDrag(e, t) {
    if (this._disabledOrInvalid)
      return;
    const { min: a, max: i, values: r } = this;
    let l = a, s = i;
    if (this._setActivePart(e), e === "range") {
      if (this.segmentsDraggingDisabled)
        return;
      l = a - r[0], s = i - r[r.length - 1];
    }
    this._dragInfo = {
      position: t,
      entries: new Map(this._sliderData.entries.entries()),
      minDiff: l,
      maxDiff: s
    }, this._addDragListeners();
  }
  _updateDrag(e) {
    if (!this._dragInfo || !this._activePart)
      return;
    const { _activePart: t, _dragInfo: { position: a, entries: i, minDiff: r, maxDiff: l } } = this;
    if (a === e)
      return;
    let s = (e - a) * this._fullRange;
    if (t === "range") {
      s = Math.min(l, Math.max(r, s));
      const o = ce(this._stepsProvider, i, s);
      this._setValues(o);
    } else {
      const o = B(this._stepsProvider, i, t, s, this.allowValuesOverlap);
      this._setValue(t, o);
    }
  }
  _focusEntry(e) {
    e && be(this, e)?.focus();
  }
  _addDragListeners() {
    document.addEventListener("pointerup", this._onPointerUpDragEnd), document.addEventListener("pointermove", this._onPointerMoveDragUpdate), document.addEventListener("pointercancel", this._onPointerCancelDragEnd);
  }
  _removeDragListeners() {
    document.removeEventListener("pointerup", this._onPointerUpDragEnd), document.removeEventListener("pointermove", this._onPointerMoveDragUpdate), document.removeEventListener("pointercancel", this._onPointerCancelDragEnd);
  }
  _setValues(e) {
    this._sliderData.setValues(e) && (this._dragInfo || this.arcgisChange.emit(), this.arcgisInput.emit());
  }
  _setValue(e, t) {
    this._sliderData.setValue(e, t) && (this._dragInfo || this.arcgisChange.emit(), this.arcgisInput.emit());
  }
  _onThumbFocus(e) {
    const t = V(e.currentTarget);
    this._setActivePart(t);
  }
  _onThumbBlur() {
    this._setActivePart(null);
  }
  _onRangeInputChange(e) {
    const t = e.currentTarget, a = t.value, i = t.dataset.type;
    let r = !1;
    switch (e.stopPropagation(), i) {
      case "min": {
        a < this.max ? (this.min = a, r = !0) : t.value = this.min;
        break;
      }
      case "max": {
        a > this.min ? (this.max = a, r = !0) : t.value = this.max;
        break;
      }
    }
    r && this.arcgisRangeChange.emit();
  }
  _onValueInputChange(e) {
    const t = e.currentTarget, a = V(t), i = t.value;
    a && (e.stopPropagation(), this._setValue(a, i), t.value = this._sliderData.getValue(a));
  }
  _mapEventToRange(e) {
    const t = this._trackElement.value?.getBoundingClientRect();
    if (!t)
      return 0;
    const a = this.isHorizontal ? (e.clientX - t.left) / t.width : 1 - (e.clientY - t.top) / t.height;
    return this.mirrored ? 1 - a : a;
  }
  _getPositionStyleForElement(e) {
    const t = M(this._fullMin, this._fullMax, e);
    return {
      [this.isHorizontal ? this.mirrored ? "right" : "left" : this.mirrored ? "top" : "bottom"]: `${t}%`
    };
  }
  _popoverSlotChange(e) {
    this._hasPopoverContent = L(e);
  }
  _onContentStartSlotChange(e) {
    this._hasContentStart = L(e);
  }
  _onContentEndSlotChange(e) {
    this._hasContentEnd = L(e);
  }
  _onThumbKeyDown(e) {
    const t = V(e.currentTarget);
    if (!t)
      return;
    const a = e.currentTarget.querySelector("arcgis-label-input");
    if (!a || a.editing)
      return;
    const i = e.key;
    switch (i) {
      case "Enter": {
        a.edit();
        break;
      }
      // Shortcuts taken from:
      // https://w3c.github.io/aria-practices/#slider_kbd_interaction
      // --
      // Move target anchor in increments of 1 pixel or 1 step
      case "ArrowUp":
      case "ArrowDown":
      case "ArrowLeft":
      case "ArrowRight": {
        e.preventDefault();
        let r = i === "ArrowUp" || i === "ArrowRight" ? 1 : -1;
        r = this.mirrored ? r * -1 : r;
        const l = N({
          allowValuesOverlap: this.allowValuesOverlap,
          stepsProvider: this._stepsProvider,
          resolution: this.resolution,
          min: this.min,
          max: this.max
        }, this._sliderData.entries, t, r);
        this._setValue(t, l);
        break;
      }
      case "End":
      case "Home": {
        e.preventDefault();
        const l = this.isHorizontal && this.mirrored || this.layout === "vertical" ? i === "End" ? -1 : 1 : i === "Home" ? -1 : 1, s = he({
          allowValuesOverlap: this.allowValuesOverlap,
          stepsProvider: this._stepsProvider,
          resolution: this.resolution,
          min: this.min,
          max: this.max
        }, this._sliderData.entries, t, l);
        this._setValue(t, s);
        break;
      }
    }
  }
  _onTrackRangeKeyDown(e) {
    const t = e.key;
    switch (t) {
      // Shortcuts taken from:
      // https://w3c.github.io/aria-practices/#slider_kbd_interaction
      // --
      // Move target anchor in increments of 1 pixel or 1 step
      case "ArrowUp":
      case "ArrowDown":
      case "ArrowLeft":
      case "ArrowRight": {
        e.preventDefault();
        let a = t === "ArrowUp" || t === "ArrowRight" ? 1 : -1;
        a = this.mirrored ? a * -1 : a;
        const { entries: i } = de({
          allowValuesOverlap: this.allowValuesOverlap,
          stepsProvider: this._stepsProvider,
          resolution: this.resolution,
          min: this.min,
          max: this.max
        }, this._sliderData.entries, a);
        this._setValues(i);
        break;
      }
      case "End":
      case "Home": {
        e.preventDefault();
        const i = this.isHorizontal && this.mirrored || this.layout === "vertical" ? t === "End" ? -1 : 1 : t === "Home" ? -1 : 1, r = ue({
          allowValuesOverlap: this.allowValuesOverlap,
          stepsProvider: this._stepsProvider,
          resolution: this.resolution,
          min: this.min,
          max: this.max
        }, this._sliderData.entries, i);
        this._setValues(r);
        break;
      }
    }
  }
  _setActivePart(e) {
    this._activePart !== e && (this._activePart = e, this.arcgisActiveValueChange.emit());
  }
  render() {
    return b`<div class=${C({
      content: !0,
      disabled: this._disabledOrInvalid
    })} @pointerdown=${this._onPointerDown}>${this._renderContentStart()}${this._renderContentEnd()}${this._renderRangeLabel("min")}${this._renderTrackRange()}${this._renderRangeLabel("max")}${this._renderPopover()}</div>`;
  }
  _renderPopover() {
    const { _activePart: e, layout: t, popoverPlacement: a, valueLabelsPlacement: i, valueLabelsDisplay: r, popoverLabel: l } = this, s = e ? ve(e) ? e : "track-range" : "", o = this._hasPopoverContent && !!s, c = t === "horizontal" ? a === "leading" ? "top" : "bottom" : a === "leading" ? "left" : "right";
    let d = 14;
    return r !== "hidden" && a === i && (d += 24), b`<calcite-popover flip-disabled focus-trap-disabled .label=${l} .open=${o} .offsetDistance=${d} .placement=${c} pointer-disabled .referenceElement=${s} scale=s trigger-disabled ${S(this._popoverElement)}><slot name=popover @slotchange=${this._popoverSlotChange}></slot></calcite-popover>`;
  }
  _renderContentStart() {
    return b`<div class="content-start" .hidden=${!this._hasContentStart}><slot name=content-start @slotchange=${this._onContentStartSlotChange}></slot></div>`;
  }
  _renderContentEnd() {
    return b`<div class="content-end" .hidden=${!this._hasContentEnd}><slot name=content-end @slotchange=${this._onContentEndSlotChange}></slot></div>`;
  }
  _renderTrackRange() {
    return b`<div class="track-container">${this._renderTrack()}${this._renderThumbs()}</div>`;
  }
  _renderTrack() {
    return b`<div class="track" ${S(this._trackElement)}>${this._renderTrackBackground()}${this._renderFillSegment()}</div>`;
  }
  _renderTrackBackground() {
    const { max: e, min: t, fillPlacement: a, values: i } = this, r = i.length > 1;
    let l = this._fullMin, s = this._fullMax;
    const o = [];
    return this._invalid ? b`<div class="segment track-bounds" style=${z({ left: "0%", right: "0%", top: "0%", bottom: "0%" })}></div>` : (l < t && (o.push(this._renderSegment(l, t, [
      this.mirrored ? "track-effective-trailing" : "track-effective-leading",
      !r && a === "start" ? "track-fill" : null
    ])), l = t), s > e && (o.push(this._renderSegment(e, s, [
      this.mirrored ? "track-effective-leading" : "track-effective-trailing",
      !r && a === "end" ? "track-fill" : null
    ])), s = e), o.push(this._renderSegment(l, s, ["track-bounds"])), o);
  }
  _renderFillSegment() {
    const { values: e, fillPlacement: t, min: a, max: i } = this;
    if (!e?.length || this._invalid)
      return;
    const r = [...e].sort((l, s) => l - s);
    if (r.length === 1)
      switch (t) {
        case "start":
          if (a < r[0])
            return this._renderSegment(a, r[0], ["track-range"]);
          break;
        case "end":
          if (i > r[0])
            return this._renderSegment(r[0], i, ["track-range"]);
          break;
      }
    return this._renderSegment(r[0], r[r.length - 1], [
      "track-range",
      this.segmentsDraggingDisabled ? null : "interactive",
      this._activePart === "range" ? "active" : null
    ], {
      id: "track-range",
      onFocus: this.segmentsDraggingDisabled ? void 0 : this._onTrackFocus,
      onBlur: this.segmentsDraggingDisabled ? void 0 : this._onTrackBlur,
      onPointerDown: this.segmentsDraggingDisabled ? void 0 : this._onTrackRangePointerDown,
      onKeyDown: this.segmentsDraggingDisabled ? void 0 : this._onTrackRangeKeyDown
    });
  }
  _renderSegment(e, t, a, i) {
    const { _fullMin: r, _fullMax: l, mirrored: s } = this, o = [
      M(r, l, U(e, r, l)),
      100 - M(r, l, U(t, r, l))
    ];
    s && o.reverse();
    const c = this.isHorizontal ? {
      left: `${o[0]}%`,
      right: `${o[1]}%`
    } : {
      top: `${o[1]}%`,
      bottom: `${o[0]}%`
    }, d = W("segment", ...a);
    return b`<div id=${i?.id ?? D} class=${C(d)} style=${z(c)} .tabIndex=${i?.onPointerDown ? 0 : -1} @focus=${i?.onFocus} @blur=${i?.onBlur} @pointerdown=${i?.onPointerDown} @keydown=${i?.onKeyDown}></div>`;
  }
  _renderThumbs() {
    const { _sliderData: e } = this, t = Array.from(e.entries).filter(([, a]) => a >= this._fullMin && a <= this._fullMax);
    return Q(t, ([a, i]) => this._renderThumb(a, i));
  }
  _renderThumb(e, t) {
    const { valueLabelsDisplay: a } = this, i = this._activePart === e || this._activePart === "range", r = this._activePart === "range" || this._activePart === e, l = a === "always" || a === "auto" && r, s = this.isHorizontal, o = s ? "horizontal" : "vertical", c = `label-${e}`, d = s ? "center" : this.valueLabelsPlacement === "leading" ? "end" : "start";
    return K(e, b`<div id=${e ?? D} .ariaLabel=${this.messages.sliderValue} aria-labelledby=${(a ? c : void 0) ?? D} .ariaOrientation=${o} .ariaValueMin=${this._minFormatter(this.min)} .ariaValueMax=${this._maxFormatter(this.max)} .ariaValueNow=${t} .ariaValueText=${this._valueFormatter(t)} class=${C({
      thumb: !0,
      active: i
    })} data-entry=${e ?? D} @pointerdown=${this._onThumbPointerDown} @focus=${this._onThumbFocus} @blur=${this._onThumbBlur} @keydown=${this._onThumbKeyDown} role=slider style=${z({
      ...this._getPositionStyleForElement(t),
      "z-index": this._activePart === e ? 1 : 0
    })} tabindex=0><span class="handle"></span><arcgis-label-input .alignment=${d} class="label" .hidden=${!l} id=${c ?? D} .labelFormatter=${this._valueFormatter} @focus=${this._onThumbFocus} @blur=${this._onThumbBlur} @arcgisChange=${this._onValueInputChange} .readOnly=${!this.valueLabelsEditingEnabled} tabindex=-1 .value=${t} ${S(this._makeResizeRef())}></arcgis-label-input></div>`);
  }
  _renderRangeLabel(e) {
    let t = "center";
    return this.isHorizontal && (t = e === "min" ? "end" : "start", this.rangeLabelsPlacement === "trailing" && (t = t === "end" ? "start" : "end"), this.mirrored && (t = t === "end" ? "start" : "end")), b`<arcgis-label-input .alignment=${t} class=${C(e)} data-type=${e ?? D} .hidden=${!this.showRangeLabels} .labelFormatter=${this[`_${e}Formatter`]} @arcgisChange=${this._onRangeInputChange} .readOnly=${!this.rangeLabelsEditingEnabled} .value=${this[e]}></arcgis-label-input>`;
  }
}
function pe(n) {
  return "dataset" in n && n.tagName === "ARCGIS-LABEL-INPUT" && (n.dataset.type === "min" || n.dataset.type === "max");
}
function V(n) {
  const e = Y(n, "[data-entry]");
  return e && "dataset" in e ? e.dataset.entry : null;
}
function ve(n) {
  return typeof n != null && n !== "range";
}
function be(n, e) {
  return e ? n.renderRoot.querySelector(`div[data-entry="${e}"]`) : null;
}
function _e(n, e) {
  return e ? n.renderRoot.querySelector(`div[data-entry="${e}"] span.handle`) : null;
}
function H(n, e) {
  return e ? n.renderRoot.querySelector(`div[data-entry="${e}"] arcgis-label-input`) : null;
}
function R(n) {
  return n.isPrimary && n.button === 0;
}
const xe = 5;
function M(n, e, t) {
  const a = e - n, i = (t - n) / a * 100;
  return Number.parseFloat(i.toFixed(xe));
}
function U(n, e, t) {
  return Math.max(e, Math.min(t, n));
}
q("arcgis-slider", fe);
export {
  fe as ArcgisSlider
};
