import { c as x } from "../../chunks/runtime.js";
import { html as g } from "lit-html";
import { usePropertyChange as $ } from "@arcgis/lumina/controllers";
import { classes as v } from "@arcgis/components-utils";
import D from "@geoscene/core/widgets/Swipe/SwipeViewModel.js";
import { LitElement as P, createEvent as C, noShadowRoot as M, safeClassMap as h, safeStyleMap as _, nothing as K } from "@arcgis/lumina";
import { u as z } from "../../chunks/useT9n.js";
import { m as L } from "../../chunks/useViewModel.js";
import { g as m } from "../../chunks/globalCss.js";
import { l as b } from "../../chunks/legacyIcon.js";
import { css as A } from "@lit/reactive-element/css-tag.js";
/*! All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
v4.33.18 */
const H = A`@layer{geoscene-swipe,.geoscene-swipe{position:absolute;margin:0;background:transparent!important;padding:0;width:100%;height:100%;overflow:hidden;user-select:none}.geoscene-swipe,.geoscene-ui .geoscene-swipe{pointer-events:none!important}.geoscene-swipe__container{position:absolute;z-index:1;margin:0;outline:0;border:0;padding:0;overflow:hidden;pointer-events:auto;touch-action:none;outline-color:transparent}.geoscene-swipe--horizontal .geoscene-swipe__container{margin-left:calc(var(--calcite-spacing-xxxl) / 2 * -1);cursor:col-resize;height:100%}.geoscene-swipe--vertical .geoscene-swipe__container{margin-top:calc(var(--calcite-spacing-xxxl) / 2 * -1);cursor:row-resize;width:100%}.geoscene-swipe--disabled .geoscene-swipe__container{cursor:default;pointer-events:none}.geoscene-swipe__divider{position:absolute;background-color:var(--calcite-color-background)}.geoscene-swipe--horizontal .geoscene-swipe__divider{top:0;left:calc(var(--calcite-spacing-xxxl) / 2);margin-left:calc(var(--calcite-border-width-lg) * .5 * -1);border-right:var(--calcite-border-width-sm) solid var(--calcite-color-border-1);border-left:var(--calcite-border-width-sm) solid var(--calcite-color-border-1);width:var(--calcite-border-width-lg);height:100%}.geoscene-swipe--vertical .geoscene-swipe__divider{top:calc(var(--calcite-spacing-xxxl) / 2);left:0;margin-top:calc(var(--calcite-border-width-lg) * .5 * -1);border-top:var(--calcite-border-width-sm) solid var(--calcite-color-border-1);border-bottom:var(--calcite-border-width-sm) solid var(--calcite-color-border-1);width:100%;height:var(--calcite-border-width-lg)}.geoscene-swipe__handle{display:flex;position:relative;align-items:center;justify-content:center;border:var(--calcite-border-width-sm) solid var(--calcite-color-border-1);border-radius:var(--calcite-corner-radius-round);background-color:var(--calcite-color-background);width:var(--calcite-spacing-xxxl);height:var(--calcite-spacing-xxxl);color:var(--calcite-color-border-input)}.geoscene-swipe__handle--hidden{visibility:hidden}.geoscene-swipe--vertical .geoscene-swipe__handle{rotate:90deg}.geoscene-swipe__handle-icon{position:relative;z-index:2}.geoscene-swipe--horizontal .geoscene-swipe__handle{top:calc(50% - calc(var(--calcite-spacing-xxxl) / 2))}.geoscene-swipe--vertical .geoscene-swipe__handle{left:calc(50% - calc(var(--calcite-spacing-xxxl) / 2))}.geoscene-swipe__container:focus .geoscene-swipe__handle,.geoscene-swipe__container:focus .geoscene-swipe__divider{outline:inset 2px var(--calcite-color-focus, var(--calcite-ui-focus-color, var(--calcite-color-brand)))}.geoscene-swipe__container:focus .geoscene-swipe__handle{outline-offset:calc(-2px*(1 - (2*clamp(0,var(--calcite-offset-invert-focus),1))))}}`, l = "geoscene-swipe", n = {
  base: l,
  baseDisabled: `${l}--disabled`,
  vertical: `${l}--vertical`,
  horizontal: `${l}--horizontal`,
  container: `${l}__container`,
  divider: `${l}__divider`,
  handle: `${l}__handle`,
  handleHidden: `${l}__handle--hidden`,
  handleIcon: `${l}__handle-icon`
}, V = L(D);
class O extends P {
  constructor() {
    super(...arguments), this._container = null, this._swiping = !1, this.messages = z({}), this._pointerOffset = 0, this.viewModel = V(this), this._onContainerPointerDown = (i) => {
      i.preventDefault();
      const { _container: e } = this;
      e && document.activeElement !== this.el && e.focus(), this._swiping = !0, this._calculatePointerOffset(i);
    }, this.autoDestroyDisabled = !1, this.direction = this.viewModel.direction, this.disabled = !1, this.hideDivider = !1, this.hideHandle = !1, this.icon = "compare", this.label = this.messages.componentLabel, this.leadingLayers = this.viewModel.leadingLayers, this.position = "manual", this.swipePosition = this.viewModel.position, this.state = this.viewModel.state, this.trailingLayers = this.viewModel.trailingLayers, this.geoscenePropertyChange = $()("state"), this.geosceneReady = C();
  }
  static {
    this.properties = { autoDestroyDisabled: 5, direction: 3, disabled: 7, hideDivider: 7, hideHandle: 7, icon: 1, label: 1, leadingLayers: 0, messageOverrides: 0, position: 3, swipePosition: 9, referenceElement: 1, state: 3, trailingLayers: 0 };
  }
  static {
    this.shadowRootOptions = M;
  }
  static {
    this.styles = H;
  }
  async destroy() {
    await this.manager.destroy();
  }
  loaded() {
    this.listenOn(document, "pointermove", this._onContainerPointerMove), this.listenOn(document, "pointerup", this._onContainerPointerUp);
  }
  _calculatePointerOffset(i) {
    const { direction: e } = this, t = i.target, r = (e === "vertical" ? t.clientHeight : t.clientWidth) / 2, s = t.getBoundingClientRect(), o = i.clientX - s.left, d = i.clientY - s.top;
    this._pointerOffset = e === "vertical" ? d - r : o - r;
  }
  _onContainerPointerUp(i) {
    this._swiping && (i.preventDefault(), this._swiping = !1);
  }
  _onContainerPointerMove(i) {
    if (!this._swiping)
      return;
    i.preventDefault();
    const { _pointerOffset: e, el: t, direction: r } = this, { clientX: s, clientY: o } = i, { top: d, left: a, width: c, height: p } = t.getBoundingClientRect(), u = r === "vertical" ? p : c, f = (r === "vertical" ? o - d - e : s - a - e) / u * 100;
    this.swipePosition = f;
  }
  _getKeyPosition(i) {
    const { key: e } = i, { swipePosition: t } = this, { max: r, min: s, step: o, stepMultiplier: d, direction: a } = this.viewModel, c = o * d;
    if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageUp", "PageDown"].includes(e) && (i.preventDefault(), i.stopPropagation()), a === "vertical" ? e === "ArrowDown" || e === "ArrowRight" : e === "ArrowUp" || e === "ArrowRight") {
      const w = i.shiftKey ? c : o;
      return t + w;
    }
    if (a === "vertical" ? e === "ArrowUp" || e === "ArrowLeft" : e === "ArrowDown" || e === "ArrowLeft") {
      const w = i.shiftKey ? c : o;
      return t - w;
    }
    return e === "Home" ? s : e === "End" ? r : (a === "vertical" ? e === "PageDown" : e === "PageUp") ? t + c : (a === "vertical" ? e === "PageUp" : e === "PageDown") ? t - c : null;
  }
  _onContainerKeyDown(i) {
    const e = this._getKeyPosition(i);
    typeof e == "number" && (this.swipePosition = e);
  }
  render() {
    const { state: i, direction: e } = this.viewModel, t = i === "disabled" || this.disabled, r = {
      [m.disabled]: t,
      [n.baseDisabled]: t,
      [n.vertical]: e === "vertical",
      [n.horizontal]: e === "horizontal"
    };
    return g`<div class=${h(v(n.base, m.widget, r))}>${i === "disabled" ? null : this._renderContainer()}</div>`;
  }
  _renderHandle() {
    const { direction: i } = this.viewModel, { hideHandle: e } = this, t = {
      [b.dragHorizontal]: i === "vertical",
      [b.dragVertical]: i === "horizontal"
    }, r = v(n.handle, !!e && n.handleHidden);
    return g`<div class=${h(r)} role=presentation><span aria-hidden=true class=${h(v(n.handleIcon, t))}></span></div>`;
  }
  _renderDivider() {
    return this.hideDivider ? null : g`<div class=${h(n.divider)} role=presentation></div>`;
  }
  _renderContent() {
    return [this._renderDivider(), this._renderHandle()];
  }
  _renderContainer() {
    const { disabled: i, viewModel: e } = this, { max: t, min: r, direction: s, position: o } = e, d = this.label ?? this.messages.dragLabel ?? "", a = `${o}%`, c = {
      top: s === "vertical" ? a : void 0,
      left: s === "vertical" ? void 0 : a
    }, p = this._renderContent();
    return i ? g`<div class=${h(n.container)} role=presentation style=${_(c)}>${p}</div>` : g`<div @pointerdown=${this._onContainerPointerDown} .ariaLabel=${d} .ariaOrientation=${s} .ariaValueMax=${`${t}`} .ariaValueMin=${`${r}`} .ariaValueNow=${`${o}`} .ariaValueText=${a} class=${h(n.container)} @keydown=${this._onContainerKeyDown} role=slider style=${_(c)} tabindex=0 title=${d ?? K} touch-action=none>${p}</div>`;
  }
}
x("geoscene-swipe", O);
export {
  O as GeosceneSwipe
};