import { c as E } from "../../chunks/runtime.js";
import { css as F, html as k } from "lit";
import { keyed as L } from "lit/directives/keyed.js";
import P from "@arcgis/core/widgets/Features/FeaturesViewModel.js";
import { u as T } from "../../chunks/useT9n.js";
import { usePropertyChange as H } from "@arcgis/lumina/controllers";
import { m as N } from "../../chunks/useViewModel.js";
import { LitElement as S, createEvent as y, safeStyleMap as O, safeClassMap as b } from "@arcgis/lumina";
import { stripHTML as W } from "@arcgis/core/applications/Components/stringUtils.js";
import { unsafeGetElementDirection as D, classes as x } from "@arcgis/toolkit/dom";
import { createRef as v, ref as _ } from "lit-html/directives/ref.js";
import { watch as g } from "@arcgis/core/core/reactiveUtils.js";
import V from "@arcgis/core/support/actions/ActionButton.js";
import { t as I } from "../../chunks/screenLocation.js";
import "../arcgis-search-result-renderer/customElement.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 p = "arcgis-popup", u = `${p}--is-docked`, a = {
  base: p,
  baseHidden: `${p}--hidden`,
  main: `${p}__main-container`,
  // global modifiers
  shadow: `${p}--shadow`,
  isDocked: u,
  isDockedTopLeft: `${u}-top-left`,
  isDockedTopCenter: `${u}-top-center`,
  isDockedTopRight: `${u}-top-right`,
  isDockedBottomLeft: `${u}-bottom-left`,
  isDockedBottomCenter: `${u}-bottom-center`,
  isDockedBottomRight: `${u}-bottom-right`,
  isXlWidthBreakpoint: `${p}--is-xl-width-breakpoint`,
  isLgWidthBreakpoint: `${p}--is-lg-width-breakpoint`,
  isMdWidthBreakpoint: `${p}--is-md-width-breakpoint`,
  isSmWidthBreakpoint: `${p}--is-sm-width-breakpoint`,
  isXsWidthBreakpoint: `${p}--is-xs-width-breakpoint`,
  isXlHeightBreakpoint: `${p}--is-xl-height-breakpoint`,
  isLgHeightBreakpoint: `${p}--is-lg-height-breakpoint`,
  isMdHeightBreakpoint: `${p}--is-md-height-breakpoint`,
  isSmHeightBreakpoint: `${p}--is-sm-height-breakpoint`,
  isXsHeightBreakpoint: `${p}--is-xs-height-breakpoint`,
  alignTopCenter: `${p}--aligned-top-center`,
  alignBottomCenter: `${p}--aligned-bottom-center`,
  alignTopLeft: `${p}--aligned-top-left`,
  alignBottomLeft: `${p}--aligned-bottom-left`,
  alignTopRight: `${p}--aligned-top-right`,
  alignBottomRight: `${p}--aligned-bottom-right`,
  // pointer
  pointer: `${p}__pointer`,
  pointerDirection: `${p}__pointer-direction`
}, R = F`:host{display:contents;--arcgis-internal-popup-pointer-size: 12px;--arcgis-internal-popup-content-small-size: 280px;--arcgis-internal-popup-content-medium-size: 340px;--arcgis-internal-popup-content-large-size: 400px;--arcgis-internal-popup-content-x-large-size: 460px;--arcgis-internal-popup-content-min-size-y: 48px;--arcgis-internal-popup-pointer-size-half: calc(var(--arcgis-internal-popup-pointer-size) / 2);--arcgis-internal-popup-pointer-size-half-negative: calc(var(--arcgis-internal-popup-pointer-size-half) * -1)}.arcgis-popup{display:flex;position:absolute;flex-flow:column nowrap;z-index:1;pointer-events:none}.arcgis-popup--hidden{visibility:hidden}arcgis-features{flex:1;width:100%}.arcgis-popup--shadow{box-shadow:var(--calcite-shadow-sm)}.arcgis-popup--aligned-top-center{transform-origin:50% 100%}.arcgis-popup--aligned-bottom-center{transform-origin:50% -5%}.arcgis-popup--aligned-top-left,.arcgis-popup--aligned-bottom-left{transform-origin:100% 50%}.arcgis-popup--aligned-top-right,.arcgis-popup--aligned-bottom-right{transform-origin:-5% 50%}.arcgis-popup--aligned-top-center,.arcgis-popup--aligned-top-left,.arcgis-popup--aligned-top-right{animation:popup-intro-animation-down .2s ease-in-out}.arcgis-popup--aligned-bottom-center,.arcgis-popup--aligned-bottom-left,.arcgis-popup--aligned-bottom-right{animation:popup-intro-animation-up .2s ease-in-out}.arcgis-popup__main-container{display:flex;position:relative;z-index:1;background-color:var(--calcite-color-foreground-1);width:var(--arcgis-internal-popup-content-medium-size);min-height:var(--arcgis-internal-popup-content-min-size-y);max-height:var(--arcgis-internal-popup-content-medium-size);overflow:hidden;pointer-events:auto}.arcgis-popup__pointer{position:absolute;width:0;height:0}.arcgis-popup__pointer-direction{position:absolute;width:var(--arcgis-internal-popup-pointer-size);height:var(--arcgis-internal-popup-pointer-size);content:"";background-color:var(--calcite-color-foreground-1)}.arcgis-popup--aligned-top-center .arcgis-popup__pointer{top:100%;left:50%;margin:0 0 0 var(--arcgis-internal-popup-pointer-size-half-negative)}.arcgis-popup--aligned-bottom-center .arcgis-popup__pointer{bottom:100%;left:50%;margin:0 0 0 var(--arcgis-internal-popup-pointer-size-half-negative)}.arcgis-popup--aligned-top-left .arcgis-popup__pointer{right:var(--arcgis-internal-popup-pointer-size-half);bottom:var(--arcgis-internal-popup-pointer-size-half);transform:rotate(-45deg)}.arcgis-popup--aligned-bottom-left .arcgis-popup__pointer{top:var(--arcgis-internal-popup-pointer-size-half);right:var(--arcgis-internal-popup-pointer-size-half);transform:rotate(45deg)}.arcgis-popup--aligned-top-right .arcgis-popup__pointer{bottom:var(--arcgis-internal-popup-pointer-size-half);left:var(--arcgis-internal-popup-pointer-size-half);transform:rotate(45deg)}.arcgis-popup--aligned-bottom-right .arcgis-popup__pointer{top:var(--arcgis-internal-popup-pointer-size-half);left:var(--arcgis-internal-popup-pointer-size-half);transform:rotate(-45deg)}.arcgis-popup--aligned-top-center .arcgis-popup__pointer-direction,.arcgis-popup--aligned-bottom-center .arcgis-popup__pointer-direction{transform:scale(.75,2) rotate(45deg)}.arcgis-popup--aligned-top-left .arcgis-popup__pointer-direction,.arcgis-popup--aligned-bottom-left .arcgis-popup__pointer-direction,.arcgis-popup--aligned-top-right .arcgis-popup__pointer-direction,.arcgis-popup--aligned-bottom-right .arcgis-popup__pointer-direction{top:var(--arcgis-internal-popup-pointer-size-half-negative);left:var(--arcgis-internal-popup-pointer-size-half-negative);transform:scale(.75,2.5) rotate(45deg)}.arcgis-popup--aligned-top-center .arcgis-popup__pointer-direction{top:var(--arcgis-internal-popup-pointer-size-half-negative);left:0}.arcgis-popup--aligned-bottom-center .arcgis-popup__pointer-direction{bottom:var(--arcgis-internal-popup-pointer-size-half-negative);left:0}.arcgis-popup--is-xl-width-breakpoint .arcgis-popup__main-container{width:var(--arcgis-internal-popup-content-x-large-size)}.arcgis-popup--is-lg-width-breakpoint .arcgis-popup__main-container{width:var(--arcgis-internal-popup-content-large-size)}.arcgis-popup--is-md-width-breakpoint .arcgis-popup__main-container{width:var(--arcgis-internal-popup-content-medium-size)}.arcgis-popup--is-sm-width-breakpoint .arcgis-popup__main-container,.arcgis-popup--is-xs-width-breakpoint .arcgis-popup__main-container{width:var(--arcgis-internal-popup-content-small-size)}.arcgis-popup--is-xs-width-breakpoint.arcgis-popup--is-docked-top-center,.arcgis-popup--is-xs-width-breakpoint.arcgis-popup--is-docked-bottom-center{margin:0;width:auto}.arcgis-popup--is-xs-width-breakpoint.arcgis-popup--is-docked-top-center .arcgis-popup__main-container,.arcgis-popup--is-xs-width-breakpoint.arcgis-popup--is-docked-bottom-center .arcgis-popup__main-container{position:absolute;right:0;left:0;width:100%;max-height:75%}.arcgis-popup--is-xs-width-breakpoint.arcgis-popup--is-docked-bottom-center .arcgis-popup__main-container{bottom:0}.arcgis-popup--is-xs-width-breakpoint.arcgis-popup--is-docked-top-center .arcgis-popup__main-container{top:0}.arcgis-popup--is-xl-height-breakpoint .arcgis-popup__main-container{max-height:var(--arcgis-internal-popup-content-x-large-size)}.arcgis-popup--is-lg-height-breakpoint .arcgis-popup__main-container{max-height:var(--arcgis-internal-popup-content-large-size)}.arcgis-popup--is-sm-height-breakpoint .arcgis-popup__main-container,.arcgis-popup--is-xs-height-breakpoint .arcgis-popup__main-container{max-height:var(--arcgis-internal-popup-content-small-size)}.arcgis-popup--is-docked{inset:0;margin:var(--calcite-spacing-lg) var(--calcite-spacing-lg) var(--calcite-spacing-xxxl) var(--calcite-spacing-lg);animation:docking-animation .25s ease-out}.arcgis-popup--is-docked-top-left,.arcgis-popup--is-docked-top-center,.arcgis-popup--is-docked-top-right{align-items:flex-start}.arcgis-popup--is-docked-bottom-left,.arcgis-popup--is-docked-bottom-center,.arcgis-popup--is-docked-bottom-right{align-items:flex-end}.arcgis-popup--is-docked-top-left,.arcgis-popup--is-docked-bottom-left{justify-content:flex-start}.arcgis-popup--is-docked-top-center,.arcgis-popup--is-docked-bottom-center{justify-content:center}.arcgis-popup--is-docked-top-right,.arcgis-popup--is-docked-bottom-right{justify-content:flex-end}.arcgis-popup--is-docked-top-left .arcgis-popup__main-container,.arcgis-popup--is-docked-top-right .arcgis-popup__main-container,.arcgis-popup--is-docked-bottom-left .arcgis-popup__main-container,.arcgis-popup--is-docked-bottom-right .arcgis-popup__main-container{max-height:80%}.arcgis-popup--is-docked-top-center .arcgis-popup__main-container,.arcgis-popup--is-docked-bottom-center .arcgis-popup__main-container{max-height:40%}.arcgis-popup--is-docked{flex-flow:row nowrap}:dir(rtl) .arcgis-popup--is-docked-top-left,:dir(rtl) .arcgis-popup--is-docked-bottom-left{justify-content:flex-end}:dir(rtl) .arcgis-popup--is-docked-top-right,:dir(rtl) .arcgis-popup--is-docked-bottom-right{justify-content:flex-start}@media (prefers-reduced-motion){.arcgis-popup--aligned-top-center,.arcgis-popup--aligned-top-left,.arcgis-popup--aligned-top-right,.arcgis-popup--aligned-bottom-center,.arcgis-popup--aligned-bottom-left,.arcgis-popup--aligned-bottom-right{animation:none}}@media (prefers-reduced-motion){.arcgis-popup--is-docked{animation:none}}@keyframes docking-animation{0%{opacity:0}25%{opacity:0}to{opacity:1}}@keyframes popup-intro-animation-down{0%{transform:translateY(calc(var(--calcite-spacing-xs) * -1));opacity:0}to{transform:translate(0);opacity:1}}@keyframes popup-intro-animation-up{0%{transform:translateY(var(--calcite-spacing-xs));opacity:0}to{transform:translate(0);opacity:1}}`;
function w(C) {
  return C && Number.parseInt(C.replaceAll(/[^-\d.]/gu, ""), 10) || 0;
}
const j = N(P), $ = {
  buttonEnabled: !0,
  position: "auto",
  breakpoint: {
    width: 544
  }
};
class X extends S {
  constructor() {
    super(...arguments), this._featuresComponent = v(), this._dockAction = new V({ id: "popup-dock-action" }), this._mainContainerNode = v(), this._pointerNode = v(), this.messages = T({}), this.viewModel = j(this), this._containerNode = v(), this.screenLocation = I(this), this.actions = this.viewModel.actions, this.active = this.viewModel.active, this.alignment = "auto", this.autoCloseEnabled = this.viewModel.autoCloseEnabled, this.autoDestroyDisabled = !1, this.collapsed = !1, this.content = this.viewModel.content, this.defaultPopupTemplateEnabled = this.viewModel.defaultPopupTemplateEnabled, this.dockEnabled = !1, this.featureCount = this.viewModel.featureCount, this.featureMenuOpen = this.viewModel.featureMenuOpen, this.features = this.viewModel.features, this.goToOverride = this.viewModel.goToOverride, this.heading = this.viewModel.title, this.headingLevel = 2, this.hideActionBar = !1, this.hideCloseButton = !1, this.hideCollapseButton = !1, this.hideFeatureMenuHeading = !1, this.hideFeatureNavigation = !1, this.hideFeatureListLayerTitle = !1, this.hideHeading = !1, this.hideSpinner = !1, this.highlightDisabled = this.viewModel.highlightEnabled, this.includeDefaultActionsDisabled = this.viewModel.includeDefaultActions, this.initialDisplayMode = this.viewModel.initialDisplayMode, this.location = this.viewModel.location, this.promises = this.viewModel.promises, this.selectedFeature = this.viewModel.selectedFeature, this.selectedFeatureIndex = this.viewModel.selectedFeatureIndex, this.state = this.viewModel.state, this.updateLocationEnabled = this.viewModel.updateLocationEnabled, this.view = this.viewModel.view, this.visible = this.viewModel.visible, this.arcgisPropertyChange = H()("active", "collapsed", "currentAlignment", "dockEnabled", "featureCount", "featureMenuOpen", "features", "promises", "selectedDrillInFeature", "selectedFeature", "selectedFeatureComponent", "selectedFeatureIndex", "state", "visible"), this.arcgisReady = y(), this.arcgisClose = y(), this.arcgisTriggerAction = y();
  }
  static {
    this.properties = { screenLocation: 16, positionStyle: 16, _featureNavigationTop: 16, actions: 0, active: 0, alignment: 1, autoCloseEnabled: 5, autoDestroyDisabled: 5, collapsed: 0, content: 1, currentAlignment: 32, currentDockPosition: 32, defaultPopupTemplateEnabled: 5, dockEnabled: 5, dockOptions: 0, featureCount: 0, featureMenuOpen: 5, features: 0, goToOverride: 0, heading: 1, headingLevel: 9, hideActionBar: 5, hideCloseButton: 5, hideCollapseButton: 5, hideFeatureMenuHeading: 5, hideFeatureNavigation: 5, hideFeatureListLayerTitle: 5, hideHeading: 5, hideSpinner: 5, highlightDisabled: 5, includeDefaultActionsDisabled: 5, initialDisplayMode: 1, label: 1, location: 0, messageOverrides: 0, promises: 0, referenceElement: 1, selectedDrillInFeature: 32, selectedFeature: 0, selectedFeatureComponent: 32, selectedFeatureIndex: 9, state: 3, updateLocationEnabled: 5, view: 0, visible: 5 };
  }
  static {
    this.styles = R;
  }
  get trackLocation() {
    return this.viewModel.active && !this.dockEnabled;
  }
  get _featureNavigationTop() {
    const { currentAlignment: t, currentDockPosition: e } = this;
    return t === "bottom-left" || t === "bottom-center" || t === "bottom-right" || e === "top-left" || e === "top-center" || e === "top-right";
  }
  get currentAlignment() {
    return this._getCurrentAlignment();
  }
  get currentDockPosition() {
    return this._getCurrentDockPosition();
  }
  get dockOptions() {
    return this._dockOptions || $;
  }
  set dockOptions(t) {
    const e = { ...$ }, o = this.viewModel?.view?.breakpoints, s = {};
    o && (s.width = o.xsmall, s.height = o.xsmall);
    const i = { ...e, ...t }, n = { ...e.breakpoint, ...s }, { breakpoint: r } = i;
    typeof r == "object" ? i.breakpoint = { ...n, ...r } : r && (i.breakpoint = n), this._dockOptions = i;
  }
  get selectedDrillInFeature() {
    return this._featuresComponent.value?.selectedDrillInFeature ?? null;
  }
  get selectedFeatureComponent() {
    return this._featuresComponent.value?.selectedFeatureComponent ?? null;
  }
  async handleViewClick(t) {
    return this.viewModel.handleViewClick(t);
  }
  async clear() {
    return this.viewModel.clear();
  }
  async destroy() {
    await this.manager.destroy(), this._dockAction.destroy();
  }
  async fetchFeatures(t, e) {
    return await this.viewModel.fetchFeatures(t, e);
  }
  async next() {
    return this.viewModel.next();
  }
  async open(t) {
    this.viewModel.open(t);
  }
  async previous() {
    return this.viewModel.previous();
  }
  async setFocus() {
    this._featuresComponent.value?.setFocus();
  }
  async triggerAction(t) {
    return await this._featuresComponent.value?.triggerAction(t);
  }
  loaded() {
    this.manager.onLifecycle(() => [
      g(() => [this.viewModel?.view?.widthBreakpoint, this.dockEnabled], () => this._handleDockIcon(), { initial: !0 }),
      g(() => [this.dockEnabled, this.messages?.undock, this.messages?.dock], () => this._handleDockEnabled(), { initial: !0 }),
      g(() => this.dockOptions, (t) => {
        const { _dockAction: e } = this, o = this._featuresComponent.value?.headerActions;
        o?.remove(e), t.buttonEnabled && o?.add(e);
      }, { initial: !0 }),
      g(() => [
        this._featuresComponent.value,
        this._mainContainerNode.value,
        this._pointerNode.value,
        this.alignment,
        this.currentAlignment,
        this.dockEnabled,
        this.dockOptions,
        this.screenLocation,
        this.viewModel?.active,
        this.viewModel?.location,
        this.viewModel?.view?.padding,
        this.viewModel?.view?.size
      ], () => this._positionContainer(), { initial: !0 }),
      g(() => this.viewModel?.view?.size, (t, e) => this._updateDockEnabledForViewSize(t, e)),
      g(() => this.viewModel?.view?.ready, () => this._setDockEnabledForViewSize(this.dockOptions), { initial: !0 }),
      g(() => this.view?.map, (t) => {
        this.viewModel.map = t;
      }, { initial: !0 }),
      g(() => this.screenLocation, (t, e) => this._autoClose(t, e))
    ]);
  }
  _handleClose(t) {
    t.stopPropagation(), this.arcgisClose.emit();
  }
  _autoClose(t, e) {
    this.autoCloseEnabled && t != null && e != null && (this.visible = !1);
  }
  _handleArcgisPropertyChange(t) {
    t.detail.name === "collapsed" && (this.collapsed = t.target.collapsed);
  }
  _handleArcgisTriggerAction(t) {
    t.stopPropagation(), t.detail.action === this._dockAction && (this.dockEnabled = !this.dockEnabled), this.arcgisTriggerAction.emit({ action: t.detail.action });
  }
  _isOutsideView(t) {
    const { popupHeight: e, popupWidth: o, screenLocation: s, side: i, view: n } = t;
    if (Number.isNaN(o) || Number.isNaN(e) || !n || !s)
      return !1;
    const r = n.padding;
    return i === "right" && s.x + o / 2 > n.width - (r?.right ?? 0) || i === "left" && s.x - o / 2 < (r?.left ?? 0) || i === "top" && s.y - e < (r?.top ?? 0) || i === "bottom" && s.y + e > n.height - (r?.bottom ?? 0);
  }
  _getPointerSize() {
    const { _pointerNode: t } = this, e = t.value ? window.getComputedStyle(t.value) : null, o = w(e?.height), s = w(e?.width);
    return Math.hypot(o, s);
  }
  _calculateAutoAlignment(t) {
    if (t !== "auto")
      return t;
    const { _mainContainerNode: e, viewModel: o } = this, { view: s } = o, { screenLocation: i } = this;
    if (i == null || !s || !e.value)
      return "top-center";
    const n = window.getComputedStyle(e.value), r = w(n.maxHeight), l = w(n.height), c = this._getPointerSize(), { height: h, width: d } = e.value.getBoundingClientRect(), m = d + c, f = Math.max(h, r, l) + c, z = this._isOutsideView({
      popupHeight: f,
      popupWidth: m,
      screenLocation: i,
      side: "right",
      view: s
    }), B = this._isOutsideView({
      popupHeight: f,
      popupWidth: m,
      screenLocation: i,
      side: "left",
      view: s
    }), M = this._isOutsideView({
      popupHeight: f,
      popupWidth: m,
      screenLocation: i,
      side: "top",
      view: s
    }), A = this._isOutsideView({
      popupHeight: f,
      popupWidth: m,
      screenLocation: i,
      side: "bottom",
      view: s
    });
    return B ? M ? "bottom-right" : "top-right" : z ? M ? "bottom-left" : "top-left" : M ? A ? "top-center" : "bottom-center" : "top-center";
  }
  _callCurrentAlignment(t) {
    return typeof t == "function" ? t.call(this) : t;
  }
  _getCurrentAlignment() {
    return this.dockEnabled || !this.viewModel.active || !this._mainContainerNode.value ? null : this._calculatePositionResult(this._calculateAutoAlignment(this._callCurrentAlignment(this.alignment)));
  }
  _calculatePositionResult(t) {
    const e = ["left", "right"];
    return D(this.el) === "rtl" && e.reverse(), t?.replace(/start/giu, e[0]).replace(/end/giu, e[1]);
  }
  _callDockPosition(t) {
    return typeof t == "function" ? t.call(this) : t;
  }
  _getDockPosition() {
    return this._calculatePositionResult(this._calculateAutoDockPosition(this._callDockPosition(this.dockOptions?.position)));
  }
  _getCurrentDockPosition() {
    return this.dockEnabled && this.viewModel.active ? this._getDockPosition() : null;
  }
  _calculateAutoDockPosition(t) {
    if (t !== "auto")
      return t;
    const e = this.viewModel?.view, o = D(this.el) === "rtl" ? "top-left" : "top-right";
    if (!e)
      return o;
    const s = e.padding, i = e.width - (s?.left ?? 0) - (s?.right ?? 0), { breakpoints: n } = e;
    return n?.xsmall && i <= n.xsmall ? "bottom-center" : o;
  }
  _getDockIcon() {
    const t = this._getDockPosition();
    if (this.dockEnabled)
      return "minimize";
    switch (t) {
      case "top-left":
      case "bottom-left":
        return "dock-left";
      case "top-center":
        return "maximize";
      case "bottom-center":
        return "dock-bottom";
      case "top-right":
      case "bottom-right":
      default:
        return "dock-right";
    }
  }
  _handleDockIcon() {
    this._dockAction.icon = this._getDockIcon();
  }
  _handleDockEnabled() {
    this._dockAction.title = this.dockEnabled ? this.messages?.undock : this.messages?.dock;
  }
  _positionContainer() {
    this.positionStyle = this._calculatePositionStyle();
  }
  _calculateFullWidth(t) {
    const { currentAlignment: e } = this;
    return e === "top-left" || e === "bottom-left" || e === "top-right" || e === "bottom-right" ? t + this._getPointerSize() : t;
  }
  _calculateAlignmentPosition(t, e, o, s) {
    const { currentAlignment: i } = this;
    if (!o)
      return;
    const { padding: n } = o, r = s / 2, l = o.height - e, c = o.width - t, h = this._getPointerSize(), d = h / 2;
    if (i === "bottom-center")
      return {
        top: e + h - (n?.top ?? 0),
        left: t - r - (n?.left ?? 0)
      };
    if (i === "top-left")
      return {
        bottom: l + d - (n?.bottom ?? 0),
        right: c + d - (n?.right ?? 0)
      };
    if (i === "bottom-left")
      return {
        top: e + d - (n?.top ?? 0),
        right: c + d - (n?.right ?? 0)
      };
    if (i === "top-right")
      return {
        bottom: l + d - (n?.bottom ?? 0),
        left: t + d - (n?.left ?? 0)
      };
    if (i === "bottom-right")
      return {
        top: e + d - (n?.top ?? 0),
        left: t + d - (n?.left ?? 0)
      };
    if (i === "top-center")
      return {
        bottom: l + h - (n?.bottom ?? 0),
        left: t - r - (n?.left ?? 0)
      };
  }
  _calculatePositionStyle() {
    const { screenLocation: t } = this, { view: e } = this.viewModel, o = this._mainContainerNode.value?.getBoundingClientRect().width ?? 0;
    if (!e || this.dockEnabled || t == null || !o)
      return;
    const s = this._calculateFullWidth(o), i = this._calculateAlignmentPosition(t.x, t.y, e, s);
    if (i)
      return {
        top: i.top !== void 0 ? `${i.top}px` : "auto",
        left: i.left !== void 0 ? `${i.left}px` : "auto",
        bottom: i.bottom !== void 0 ? `${i.bottom}px` : "auto",
        right: i.right !== void 0 ? `${i.right}px` : "auto"
      };
  }
  _dockingThresholdCrossed(t, e, o) {
    const [s, i] = t, [n, r] = e, { width: l = 0, height: c = 0 } = o ?? {};
    return s <= l && n > l || s > l && n <= l || i <= c && r > c || i > c && r <= c;
  }
  _updateDockEnabledForViewSize(t, e) {
    if (!t || !e)
      return;
    const o = this.viewModel?.view?.padding, s = (o?.left ?? 0) + (o?.right ?? 0), i = (o?.top ?? 0) + (o?.bottom ?? 0), n = [], r = [];
    n[0] = t[0] - s, n[1] = t[1] - i, r[0] = e[0] - s, r[1] = e[1] - i;
    const { dockOptions: l } = this, c = l.breakpoint;
    typeof c == "object" && this._dockingThresholdCrossed(n, r, c) && this._setDockEnabledForViewSize(l);
  }
  _shouldDockAtCurrentViewSize(t) {
    const e = t.breakpoint, o = this.viewModel?.view?.ui;
    if (!o)
      return !1;
    const { width: s, height: i } = o;
    if (Number.isNaN(s) || Number.isNaN(i) || typeof e != "object")
      return !1;
    const n = typeof e.width == "number" && s <= (e.width ?? 0), r = typeof e.height == "number" && i <= (e.height ?? 0);
    return n || r;
  }
  _setDockEnabledForViewSize(t) {
    this.viewModel?.view?.ready && typeof t.breakpoint == "object" && (this.dockEnabled = this._shouldDockAtCurrentViewSize(t));
  }
  render() {
    const { dockEnabled: t, currentAlignment: e, currentDockPosition: o, positionStyle: s } = this, { active: i, view: n } = this.viewModel, r = i && t, l = i && !t, c = n?.widthBreakpoint, h = n?.heightBreakpoint, d = {
      [a.alignTopCenter]: e === "top-center",
      [a.alignBottomCenter]: e === "bottom-center",
      [a.alignTopLeft]: e === "top-left",
      [a.alignBottomLeft]: e === "bottom-left",
      [a.alignTopRight]: e === "top-right",
      [a.alignBottomRight]: e === "bottom-right",
      [a.isDocked]: r,
      [a.shadow]: l,
      [a.isDockedTopLeft]: o === "top-left",
      [a.isDockedTopCenter]: o === "top-center",
      [a.isDockedTopRight]: o === "top-right",
      [a.isDockedBottomLeft]: o === "bottom-left",
      [a.isDockedBottomCenter]: o === "bottom-center",
      [a.isDockedBottomRight]: o === "bottom-right",
      [a.isXlWidthBreakpoint]: c === "xlarge",
      [a.isLgWidthBreakpoint]: c === "large",
      [a.isMdWidthBreakpoint]: c === "medium",
      [a.isSmWidthBreakpoint]: c === "small",
      [a.isXsWidthBreakpoint]: c === "xsmall",
      [a.isXlHeightBreakpoint]: h === "xlarge",
      [a.isLgHeightBreakpoint]: h === "large",
      [a.isMdHeightBreakpoint]: h === "medium",
      [a.isSmHeightBreakpoint]: h === "small",
      [a.isXsHeightBreakpoint]: h === "xsmall"
    };
    return k`<div style=${O(this.positionStyle)} .ariaHidden=${!i} .ariaLabel=${W(this.heading ?? "")} class=${b(x(a.base, d, {
      [a.baseHidden]: !i || !s && !t
    }))} role=dialog ${_(this._containerNode)}>${this._renderMainContainer()}${this._renderPointer()}</div>`;
  }
  _renderPointer() {
    return !this.dockEnabled || !this.active ? k`<div class=${b(a.pointer)} role=presentation><div class=${b(x(a.pointerDirection, a.shadow))} ${_(this._pointerNode)}></div></div>` : null;
  }
  _renderMainContainer() {
    const t = {
      [a.shadow]: this.dockEnabled
    };
    return k`<div class=${b(x(a.main, t))} ${_(this._mainContainerNode)}>${L(this.viewModel, k`<arcgis-features .collapsed=${this.collapsed} .featureNavigationTop=${this._featureNavigationTop} .headingLevel=${this.headingLevel} .hidden=${!this.active} .hideActionBar=${this.hideActionBar} .hideCloseButton=${this.hideCloseButton} .hideFeatureListLayerTitle=${this.hideFeatureListLayerTitle} .hideFeatureMenuHeading=${this.hideFeatureMenuHeading} .hideFeatureNavigation=${this.hideFeatureNavigation} .hideHeading=${this.hideHeading} .hideSpinner=${this.hideSpinner} @arcgisPropertyChange=${this._handleArcgisPropertyChange} @arcgisTriggerAction=${this._handleArcgisTriggerAction} @arcgisClose=${this._handleClose} .referenceElement=${this.referenceElement} .responsiveActionsEnabled=${!0} .showCollapseButton=${!this.hideCollapseButton} .viewModel=${this.viewModel} ${_(this._featuresComponent)}></arcgis-features>`)}</div>`;
  }
}
E("arcgis-popup", X);
export {
  X as ArcgisPopup
};
