import { c as $ } from "../../chunks/runtime.js";
import { css as P, html as g } from "lit";
import { classes as u } from "@arcgis/toolkit/dom";
import C from "@arcgis/core/widgets/Swipe/SwipeViewModel.js";
import { LitElement as D, createEvent as f, safeClassMap as h, safeStyleMap as m, nothing as M } from "@arcgis/lumina";
import { usePropertyChange as K } from "@arcgis/lumina/controllers";
import { createRef as z, ref as L } from "lit/directives/ref.js";
import { u as A } from "../../chunks/useT9n.js";
import { m as S } from "../../chunks/useViewModel.js";
import { g as b } from "../../chunks/globalCss.js";
import { l as y } from "../../chunks/legacyIcon.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
v4.34.7 */
const k = P`:host{position:absolute;margin:0;background:transparent!important;padding:0;width:100%;height:100%;overflow:hidden;user-select:none;--arcgis-internal-swipe-handle-color-background: var(--calcite-color-background);--arcgis-internal-swipe-divider-color-background: var(--calcite-color-background)}.arcgis-swipe{width:100%;height:100%;overflow:hidden;user-select:none}.arcgis-swipe,.arcgis-ui .arcgis-swipe{pointer-events:none!important}.arcgis-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}.arcgis-swipe--horizontal .arcgis-swipe__container{margin-left:calc(var(--calcite-spacing-xxxl) / 2 * -1);cursor:col-resize;height:100%}.arcgis-swipe--vertical .arcgis-swipe__container{margin-top:calc(var(--calcite-spacing-xxxl) / 2 * -1);cursor:row-resize;width:100%}.arcgis-swipe--disabled .arcgis-swipe__container{cursor:default;pointer-events:none}.arcgis-swipe__divider{position:absolute;background-color:var(--arcgis-internal-swipe-divider-color-background)}.arcgis-swipe--horizontal .arcgis-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%}.arcgis-swipe--vertical .arcgis-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)}.arcgis-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(--arcgis-internal-swipe-handle-color-background);width:var(--calcite-spacing-xxxl);height:var(--calcite-spacing-xxxl);color:var(--calcite-color-text-3)}.arcgis-swipe__handle--hidden{visibility:hidden}.arcgis-swipe--vertical .arcgis-swipe__handle{rotate:90deg}.arcgis-swipe__handle-icon{position:relative;z-index:2}.arcgis-swipe__handle-icon:before{content:"|||";color:inherit}.arcgis-swipe--horizontal .arcgis-swipe__handle{top:calc(50% - calc(var(--calcite-spacing-xxxl) / 2))}.arcgis-swipe--vertical .arcgis-swipe__handle{left:calc(50% - calc(var(--calcite-spacing-xxxl) / 2))}.arcgis-swipe__container:focus .arcgis-swipe__handle,.arcgis-swipe__container:focus .arcgis-swipe__divider{outline:inset 2px var(--calcite-color-focus, var(--calcite-ui-focus-color, var(--calcite-color-brand)))}.arcgis-swipe__container:focus .arcgis-swipe__handle{outline-offset:calc(-2px*(1 - (2*clamp(0,var(--calcite-offset-invert-focus),1))))}`, l = "arcgis-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`
}, H = S(C);
class V extends D {
  constructor() {
    super(...arguments), this._container = null, this._containerRef = z(), this._swiping = !1, this._swipePositionChanged = !1, this.messages = A({}), this._pointerOffset = 0, this.viewModel = H(this), this._onContainerPointerDown = (i) => {
      i.preventDefault();
      const { _container: e } = this;
      e && document.activeElement !== this.el && e.focus(), this._swiping = !0, this._calculatePointerOffset(i);
    }, this.view = this.viewModel.view, 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.swipePosition = this.viewModel.position, this.state = this.viewModel.state, this.trailingLayers = this.viewModel.trailingLayers, this.arcgisPropertyChange = K()("state"), this.arcgisReady = f(), this.arcgisSwipeChange = f(), this.arcgisSwipeInput = f();
  }
  static {
    this.properties = { view: 0, 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.styles = k;
  }
  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 = this._containerRef.value, 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._swipePositionChanged && (this.arcgisSwipeChange.emit(), this._swipePositionChanged = !1), 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(), _ = r === "vertical" ? p : c, w = (r === "vertical" ? o - d - e : s - a - e) / _ * 100;
    this.swipePosition !== w && (this.swipePosition = w, this._swipePositionChanged = !0, this.arcgisSwipeInput.emit());
  }
  _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 v = i.shiftKey ? c : o;
      return t + v;
    }
    if (a === "vertical" ? e === "ArrowUp" || e === "ArrowLeft" : e === "ArrowDown" || e === "ArrowLeft") {
      const v = i.shiftKey ? c : o;
      return t - v;
    }
    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 && (this.swipePosition = e, this.arcgisSwipeInput.emit(), this.arcgisSwipeChange.emit());
  }
  render() {
    const { state: i, direction: e } = this.viewModel, t = i === "disabled" || this.disabled, r = {
      [b.disabled]: t,
      [n.baseDisabled]: t,
      [n.vertical]: e === "vertical",
      [n.horizontal]: e === "horizontal"
    };
    return g`<div class=${h(u(n.base, b.widget, r))}>${i === "disabled" ? null : this._renderContainer()}</div>`;
  }
  _renderHandle() {
    const { direction: i } = this.viewModel, { hideHandle: e } = this, t = {
      [y.dragHorizontal]: i === "vertical",
      [y.dragVertical]: i === "horizontal"
    }, r = u(n.handle, !!e && n.handleHidden);
    return g`<div class=${h(r)} role=presentation><span aria-hidden=true class=${h(u(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=${m(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=${m(c)} tabindex=0 title=${d ?? M} touch-action=none ${L(this._containerRef)}>${p}</div>`;
  }
}
$("arcgis-swipe", V);
export {
  V as ArcgisSwipe
};
