/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as W } from "../../chunks/runtime.js";
import { keyed as J } from "lit/directives/keyed.js";
import { LitElement as Y, createEvent as T, safeClassMap as z, safeStyleMap as F, nothing as I } from "@arcgis/lumina";
import { makeAccessorController as Q } from "@arcgis/lumina/controllers/accessor";
import { slotChangeHasAssignedElement as L, classes as Z, getClosestElement as ee } from "@arcgis/toolkit/dom";
import { css as te, html as _ } from "lit";
import { map as ae } from "lit/directives/map.js";
import { createRef as H, ref as R } from "lit/directives/ref.js";
import { u as ne } from "../../chunks/useT9n.js";
import { g as re } from "../../chunks/locale.js";
import ie from "@arcgis/core/core/Accessor.js";
import { property as k, subclass as se } from "@arcgis/core/core/accessorSupport/decorators.js";
import { watch as O } from "@arcgis/core/core/reactiveUtils.js";
import { generateGuid as B } from "@arcgis/toolkit/string";
const m = {
  increment: "ArrowUp",
  incrementHorizontal: "ArrowRight",
  decrement: "ArrowDown",
  decrementHorizontal: "ArrowLeft",
  pageIncrement: "PageUp",
  pageDecrement: "PageDown",
  jumpToStart: "Home",
  jumpToEnd: "End",
  confirmEdit: "Enter"
};
function K({ key: n, shiftKey: e }, t, a) {
  const i = le(n);
  if (i == null)
    return null;
  const r = ce(n) || oe(n) && e ? de(t) : 1;
  return {
    direction: a ? i * -1 : i,
    count: r
  };
}
function le(n) {
  return n === m.increment || n === m.incrementHorizontal || n === m.pageIncrement ? 1 : n === m.decrement || n === m.decrementHorizontal || n === m.pageDecrement ? -1 : null;
}
function N(n) {
  return n === m.jumpToEnd || n === m.jumpToStart;
}
function oe(n) {
  return n === m.increment || n === m.decrement || n === m.decrementHorizontal || n === m.incrementHorizontal;
}
function ce(n) {
  return n === m.pageIncrement || n === m.pageDecrement;
}
function de(n) {
  const e = Number.isFinite(n) ? Math.floor(n) : 1;
  return Math.max(1, e);
}
const ue = te`: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-start: 0;--arcgis-slider-internal-value-labels-placement-end: 0;--arcgis-slider-internal-range-labels-placement-center: 0;--arcgis-slider-internal-range-labels-placement-end: 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="start"]){--arcgis-slider-internal-value-labels-placement-start: var(--arcgis-slider-internal-show-value-labels)}:host([value-labels-placement="end"]){--arcgis-slider-internal-value-labels-placement-end: 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="end"]){--arcgis-slider-internal-range-labels-placement-end: 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-start{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-end{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-start{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-end{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([disabled]),:host([disabled][layout="horizontal"]),:host([disabled][layout="vertical"]){.track-range.interactive:after{cursor:default;pointer-events:none}}: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:calc(-1 * var(--arcgis-slider-internal-handle-offset));block-size:var(--arcgis-slider-handle-size);margin-left:1px;writing-mode:vertical-lr}}.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 var(--calcite-animation-timing, .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="start"]){.label{right:var(--arcgis-slider-internal-label-input-margin)}}&:host([value-labels-placement="end"]){.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-start) * 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-end) * 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="start"]){.label{bottom:var(--arcgis-slider-internal-label-input-margin)}}&:host([value-labels-placement="end"]){.label{top:var(--arcgis-slider-internal-label-input-margin)}}}:host([layout="horizontal"][range-labels-placement="end"]){.content{--arcgis-slider-internal-content-start-min-height: calc( var(--arcgis-slider-internal-handle-offset) + var(--arcgis-slider-internal-value-labels-placement-start) * var(--arcgis-slider-internal-label-input-height) );--arcgis-slider-internal-content-end-min-height: calc( var(--arcgis-slider-internal-value-labels-placement-end) * 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-end) * 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="start"]){.label{bottom:var(--arcgis-slider-internal-label-input-margin)}}&:host([value-labels-placement="end"]){.label{top:calc(var(--arcgis-slider-internal-label-input-margin) + var(--arcgis-slider-internal-range-labels-placement-end) * (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 he = Object.defineProperty, ge = Object.getOwnPropertyDescriptor, w = (n, e, t, a) => {
  for (var i = a > 1 ? void 0 : a ? ge(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 && he(e, t, i), i;
};
function me() {
  return {
    min: 0,
    max: 100,
    values: []
  };
}
let x = class extends ie {
  //--------------------------------------------------------------------------
  //
  //  Lifecycle
  //
  //--------------------------------------------------------------------------
  constructor(n = {}) {
    super({ ...me(), 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 = b(t, n), e = b(e, n), a = a?.map((r) => $(b(r, n), e, t)), this._set("min", e), this._set("max", t), this._set("values", a);
    const i = new Map(a?.map((r) => [B(), r]));
    this._entries = i, O(
      () => 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 }
    ), O(
      () => 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 }
    ), O(
      () => this.precision,
      (r) => {
        const { min: l, max: s, values: o } = this;
        this._set("min", b(l, r)), this._set("max", b(s, r)), o?.length && (this._entries.forEach((c, d) => {
          this._entries.set(d, b(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 = b(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 = b(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) => $(b(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) => [B(), 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 = $(b(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 = $(b(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()
], x.prototype, "_entries", 2);
w([
  k({ readOnly: !0 })
], x.prototype, "entries", 1);
w([
  k()
], x.prototype, "max", 1);
w([
  k()
], x.prototype, "min", 1);
w([
  k({ cast: (n) => $(n, 0, 20) })
], x.prototype, "precision", 2);
w([
  k({ readOnly: !0 })
], x.prototype, "ready", 2);
w([
  k()
], x.prototype, "values", 1);
x = w([
  se("esri.widgets.Slider.SliderData")
], x);
function $(n, e, t) {
  return Math.min(Math.max(n, e), t);
}
function b(n, e) {
  return Number.parseFloat(n.toFixed(e));
}
class fe {
  constructor(e) {
    this.steps = e, this.minIndex = 0, this.maxIndex = this.steps.length - 1;
  }
  indexToValue(e) {
    return this.steps[E(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 pe {
  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 + E(e, this.minIndex, this.maxIndex) * this.stepSize;
  }
  valueToIndex(e) {
    return e = E(e, this.min, this.max), Math.round((e - this.min) / this.stepSize);
  }
}
function ve(n) {
  if (n.steps == null)
    return null;
  const e = n.steps;
  return Array.isArray(e) ? e.length === 0 ? null : new fe(e) : new pe(n.min, n.max, e);
}
function be(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), f = Math.abs(h - c);
      let p = !1;
      for (let v = 0; v < d.length; v++)
        if (f < d[v].dist) {
          d.splice(v, 0, { idx: u, value: h, dist: f }), p = !0;
          break;
        }
      !p && d.length < a && d.push({ idx: u, value: h, dist: f }), 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 U(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 _e(n, e, t, a = 1) {
  const i = q(a);
  let r = e, l = !1;
  for (let s = 0; s < i; s++) {
    const o = ye(n, r, t);
    if (l ||= o.changed, r = o.entries, !o.changed)
      break;
  }
  return { changed: l, entries: r };
}
function xe(n, e, t, a, i = 1) {
  const r = q(i);
  if (r === 1)
    return A(n, e, t, a);
  const l = new Map(e);
  let s = l.get(t);
  for (let o = 0; o < r; o++) {
    const c = A(n, l, t, a);
    if (c === s)
      break;
    s = c, l.set(t, s);
  }
  return s;
}
function q(n) {
  const e = Number.isFinite(n) ? Math.floor(n) : 1;
  return Math.max(1, e);
}
function ye(n, e, t) {
  const a = /* @__PURE__ */ new Map(), i = t > 0 ? De : G, 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 = A(n, a, o, t);
      c === d && (s = !1), l ||= s, a.set(o, d);
    }
  return { changed: l, entries: a };
}
function A(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 = E(c + a * l, s, o);
    if (i)
      return g;
    const y = /* @__PURE__ */ new Set();
    for (const [P, C] of e)
      P !== t && y.add(C);
    for (; y.has(g) && g <= o && g >= s; )
      g = E(g + a * l, s, o);
    return y.has(g) || g > o || g < s ? c : g;
  }
  const d = r.valueToIndex(c);
  if (d === -1)
    return c;
  if (i) {
    const g = E(d + a, r.minIndex, r.maxIndex);
    return r.indexToValue(g);
  }
  const u = /* @__PURE__ */ new Set();
  for (const [g, y] of e)
    g !== t && u.add(r.valueToIndex(y));
  let h = d, f = !1;
  const p = r.minIndex, v = r.maxIndex;
  let D = 0;
  for (; D < Math.abs(v - p) && (h += a, !(h < p || h > v)); ) {
    if (!u.has(h)) {
      f = !0;
      break;
    }
    D++;
  }
  return f ? r.indexToValue(h) : c;
}
function we(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 f = new Set(
      Array.from(e).filter(([v]) => v !== t).map(([, v]) => v)
    );
    let p = a > 0 ? o : s;
    if (i)
      return p;
    for (; f.has(p); )
      if (p -= a * l, a > 0 && p > o || a < 0 && p < s) {
        p = c;
        break;
      }
    return p;
  }
  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(([f]) => f !== t).map(([, f]) => r.valueToIndex(f))
  );
  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 ke(n, e, t) {
  const { stepsProvider: a, min: i, max: r } = n, l = /* @__PURE__ */ new Map(), s = Array.from(e).sort((c, d) => G(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 G(n, e) {
  return n - e;
}
function De(n, e) {
  return e - n;
}
function E(n, e, t) {
  return Math.max(e, Math.min(t, n));
}
const Ie = Q(x);
class Ee extends Y {
  constructor() {
    super(...arguments), this._popoverElement = H(), this._trackElement = H(), this.messages = ne({}), this._onPointerMoveDragUpdate = (e) => {
      this._updateDrag(this._mapEventToRange(e));
    }, this._onPointerUpDragEnd = (e) => {
      M(e) && this._endDrag();
    }, this._onPointerCancelDragEnd = () => {
      this._endDrag();
    }, this._formatLabel = (e, t, a) => {
      const i = re(this.messages._lang, t), r = this.labelFormatter;
      if (!r)
        return i.format(a);
      const l = r(a, e, (s) => i.format(s));
      return l ?? i.format(a);
    }, this._numberFormatOptions = {}, this._createFormatter = (e, t) => this._formatLabel.bind(this, e, t), this._minFormatter = this._createFormatter("min", this._numberFormatOptions), this._maxFormatter = this._createFormatter("max", this._numberFormatOptions), this._valueFormatter = this._createFormatter("value", this._numberFormatOptions), this._resizeObserver = new ResizeObserver(() => {
      this._layoutLabelInputs();
    }), this._labelInputsUpdateComplete = null, this._dragInfo = null, this._hasPopoverContent = !1, this._hasContentStart = !1, this._hasContentEnd = !1, this._sliderData = Ie(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 = "start", this.precision = this._sliderData.precision, this.rangeLabelsEditingEnabled = !1, this.rangeLabelsPlacement = "center", this.segmentsDraggingDisabled = !1, this.showRangeLabels = !1, this.valueLabelsDisplay = "hidden", this.valueLabelsPlacement = "start", this.valueLabelsEditingEnabled = !1, this.keyboardLargeStep = 10, 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, fullRangeMax: 11, fullRangeMin: 11, fillPlacement: 1, labelFormatter: 0, layout: 3, max: 11, min: 11, mirrored: 7, 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, keyboardLargeStep: 9, 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 = ue;
  }
  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 = ve(this)), e.has("messages") || e.has("min") || e.has("max") || e.has("precision") || e.has("labelFormatter")) {
      const t = this.max != null && this.min != null && this.max - this.min > 10 ? 2 : this.precision;
      this._numberFormatOptions = { maximumFractionDigits: t }, this._minFormatter = this._createFormatter("min", this._numberFormatOptions), this._maxFormatter = this._createFormatter("max", this._numberFormatOptions), this._valueFormatter = this._createFormatter("value", this._numberFormatOptions);
    }
  }
  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 a = this._trackElement.value;
    if (!a)
      return;
    const 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 = Ce(this, r), c = j(this, r);
        if (!o || !c)
          continue;
        const d = o.getBoundingClientRect(), u = c.getBoundingClientRect(), h = c.getLabelBoundingClientRect(), f = d.width / 2, p = Math.round(d.left + f), v = Math.round(h.width / 2);
        let D = u.width / 2;
        const g = i.left - f, y = i.right + f, P = p - v, C = p + v;
        P < g ? D += P - g : C > y && (D += C - y), c.style.transform = `translateX(${-Math.round(D)}px)`;
      }
    }
  }
  _onTrackFocus() {
    this._setActivePart("range");
  }
  _onTrackBlur() {
    this._setActivePart(null);
  }
  _onTrackRangePointerDown(e) {
    this._disabledOrInvalid || !M(e) || this._startDrag("range", this._mapEventToRange(e));
  }
  async _onPointerDown(e) {
    if (this._disabledOrInvalid || !M(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 (Ve(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 = S(this._fullMin, this._fullMax, r) / 100;
    this._startDrag(i, s);
    const o = U(this._stepsProvider, this._sliderData.entries, i, l, this.allowValuesOverlap);
    this._setValue(i, o), this._focusEntry(i);
  }
  _onThumbPointerDown(e) {
    const t = V(e.currentTarget);
    if (!M(e) || this._disabledOrInvalid || !t)
      return;
    const a = j(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 = be(this._stepsProvider, i, s);
      this._setValues(o);
    } else {
      const o = U(this._stepsProvider, i, t, s, this.allowValuesOverlap);
      this._setValue(t, o);
    }
  }
  _focusEntry(e) {
    e && Pe(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 = S(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;
    if (e.key === m.confirmEdit) {
      a.edit();
      return;
    }
    const i = K(e, this.keyboardLargeStep, this.mirrored);
    if (i) {
      e.preventDefault();
      const r = xe(this._getStepsConfiguration(), this._sliderData.entries, t, i.direction, i.count);
      this._setValue(t, r);
      return;
    }
    if (N(e.key)) {
      e.preventDefault();
      const r = we(this._getStepsConfiguration(), this._sliderData.entries, t, this._getDirectionForHomeEndKey(e.key));
      this._setValue(t, r);
    }
  }
  _onTrackRangeKeyDown(e) {
    if (this._disabledOrInvalid)
      return;
    const t = K(e, this.keyboardLargeStep, this.mirrored);
    if (t) {
      e.preventDefault();
      const { entries: a } = _e(this._getStepsConfiguration(), this._sliderData.entries, t.direction, t.count);
      this._setValues(a);
      return;
    }
    if (N(e.key)) {
      e.preventDefault();
      const a = ke(this._getStepsConfiguration(), this._sliderData.entries, this._getDirectionForHomeEndKey(e.key));
      this._setValues(a);
    }
  }
  _getStepsConfiguration() {
    return {
      allowValuesOverlap: this.allowValuesOverlap,
      stepsProvider: this._stepsProvider,
      resolution: this.resolution,
      min: this.min,
      max: this.max
    };
  }
  _getDirectionForHomeEndKey(e) {
    return this.isHorizontal && this.mirrored || this.layout === "vertical" ? e === m.jumpToEnd ? -1 : 1 : e === m.jumpToStart ? -1 : 1;
  }
  _setActivePart(e) {
    this._activePart !== e && (this._activePart = e, this.arcgisActiveValueChange.emit());
  }
  render() {
    return _`<div class=${z({
      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 ? $e(e) ? e : "track-range" : "", o = this._hasPopoverContent && !!s, c = t === "horizontal" ? a === "start" ? "top" : "bottom" : a === "start" ? "left" : "right";
    let d = 14;
    return r !== "hidden" && a === i && (d += 24), _`<calcite-popover flip-disabled focus-trap-disabled .label=${l} .open=${o} .offsetDistance=${d} .placement=${c} pointer-disabled .referenceElement=${s} scale=s trigger-disabled ${R(this._popoverElement)}><slot name=popover @slotchange=${this._popoverSlotChange}></slot></calcite-popover>`;
  }
  _renderContentStart() {
    return _`<div class="content-start" .hidden=${!this._hasContentStart}><slot name=content-start @slotchange=${this._onContentStartSlotChange}></slot></div>`;
  }
  _renderContentEnd() {
    return _`<div class="content-end" .hidden=${!this._hasContentEnd}><slot name=content-end @slotchange=${this._onContentEndSlotChange}></slot></div>`;
  }
  _renderTrackRange() {
    return _`<div class="track-container">${this._renderTrack()}${this._renderThumbs()}</div>`;
  }
  _renderTrack() {
    return _`<div class="track" ${R(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 ? _`<div class="segment track-bounds" style=${F({ left: "0%", right: "0%", top: "0%", bottom: "0%" })}></div>` : (l < t && (o.push(this._renderSegment(l, t, [
      this.mirrored ? "track-effective-end" : "track-effective-start",
      !r && a === "start" ? "track-fill" : null
    ])), l = t), s > e && (o.push(this._renderSegment(e, s, [
      this.mirrored ? "track-effective-start" : "track-effective-end",
      !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((s, o) => s - o);
    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;
      }
    const l = this.segmentsDraggingDisabled;
    return this._renderSegment(r[0], r[r.length - 1], ["track-range", l ? null : "interactive", this._activePart === "range" ? "active" : null], {
      id: "track-range",
      onFocus: l ? void 0 : this._onTrackFocus,
      onBlur: l ? void 0 : this._onTrackBlur,
      onPointerDown: l ? void 0 : this._onTrackRangePointerDown,
      onKeyDown: l ? void 0 : this._onTrackRangeKeyDown
    });
  }
  _renderSegment(e, t, a, i) {
    const { _fullMin: r, _fullMax: l, mirrored: s } = this, o = [
      S(r, l, X(e, r, l)),
      100 - S(r, l, X(t, r, l))
    ];
    s && o.reverse();
    const c = this.isHorizontal ? {
      left: `${o[0]}%`,
      right: `${o[1]}%`
    } : {
      top: `${o[1]}%`,
      bottom: `${o[0]}%`
    }, d = Z("segment", ...a);
    return _`<div id=${i?.id ?? I} class=${z(d)} style=${F(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 ae(t, ([a, i]) => this._renderThumb(a, i));
  }
  _renderThumb(e, t) {
    const { valueLabelsDisplay: a } = this, i = this._disabledOrInvalid, r = this._activePart === e || this._activePart === "range", l = this._activePart === "range" || this._activePart === e, s = a === "always" || a === "auto" && l, o = this.isHorizontal, c = o ? "horizontal" : "vertical", d = `label-${e}`, u = o ? "center" : this.valueLabelsPlacement === "start" ? "end" : "start";
    return J(e, _`<div id=${e ?? I} .ariaLabel=${this.messages.sliderValue} aria-labelledby=${(a ? d : void 0) ?? I} .ariaOrientation=${c} .ariaValueMin=${this._minFormatter(this.min)} .ariaValueMax=${this._maxFormatter(this.max)} .ariaValueNow=${t} .ariaValueText=${this._valueFormatter(t)} class=${z({
      thumb: !0,
      active: r
    })} data-entry=${e ?? I} @pointerdown=${this._onThumbPointerDown} @focus=${this._onThumbFocus} @blur=${this._onThumbBlur} @keydown=${this._onThumbKeyDown} role=slider style=${F({
      ...this._getPositionStyleForElement(t),
      "z-index": this._activePart === e ? 1 : 0
    })} .tabIndex=${i ? -1 : 0}><span class="handle"></span><arcgis-label-input .alignment=${u} class="label" .hidden=${!s} id=${d ?? I} .labelFormatter=${this._valueFormatter} @focus=${i ? void 0 : this._onThumbFocus} @blur=${i ? void 0 : this._onThumbBlur} @arcgisChange=${this._onValueInputChange} .readOnly=${!this.valueLabelsEditingEnabled} tabindex=-1 .value=${t} ${R(this._makeResizeRef())}></arcgis-label-input></div>`);
  }
  _renderRangeLabel(e) {
    let t = "center";
    return this.isHorizontal && (t = e === "min" ? "end" : "start", this.rangeLabelsPlacement === "end" && (t = t === "end" ? "start" : "end"), this.mirrored && (t = t === "end" ? "start" : "end")), _`<arcgis-label-input .alignment=${t} class=${z(e)} data-type=${e ?? I} .hidden=${!this.showRangeLabels} .labelFormatter=${this[`_${e}Formatter`]} @arcgisChange=${this._onRangeInputChange} .readOnly=${!this.rangeLabelsEditingEnabled} .value=${this[e]}></arcgis-label-input>`;
  }
}
function Ve(n) {
  return "dataset" in n && n.tagName === "ARCGIS-LABEL-INPUT" && (n.dataset.type === "min" || n.dataset.type === "max");
}
function V(n) {
  const e = ee(n, "[data-entry]");
  return e && "dataset" in e ? e.dataset.entry : null;
}
function $e(n) {
  return typeof n != null && n !== "range";
}
function Pe(n, e) {
  return e ? n.renderRoot.querySelector(`div[data-entry="${e}"]`) : null;
}
function Ce(n, e) {
  return e ? n.renderRoot.querySelector(`div[data-entry="${e}"] span.handle`) : null;
}
function j(n, e) {
  return e ? n.renderRoot.querySelector(`div[data-entry="${e}"] arcgis-label-input`) : null;
}
function M(n) {
  return n.isPrimary && n.button === 0;
}
const Te = 5;
function S(n, e, t) {
  const a = e - n, i = (t - n) / a * 100;
  return Number.parseFloat(i.toFixed(Te));
}
function X(n, e, t) {
  return Math.max(e, Math.min(t, n));
}
W("arcgis-slider", Ee);
export {
  Ee as ArcgisSlider
};
