import { c as v } from "../../chunks/runtime.js";
import { ref as w } from "lit/directives/ref.js";
import { css as x, html as g } from "lit";
import { classes as d } from "@arcgis/toolkit/dom";
import { getDefaultUnitForView as y } from "@arcgis/core/applications/Components/getDefaultUnits.js";
import { watch as k } from "@arcgis/core/core/reactiveUtils.js";
import { formatNumber as C } from "@arcgis/core/intl.js";
import $ from "@arcgis/core/widgets/ScaleBar/ScaleBarViewModel.js";
import { LitElement as z, createEvent as M, safeClassMap as a, safeStyleMap as f } from "@arcgis/lumina";
import { u as L } from "../../chunks/useT9n.js";
import { m as S } from "../../chunks/useViewModel.js";
import { g as m } from "../../chunks/globalCss.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 */
function B(u = 0, e = 0) {
  return { x: u, y: e };
}
const t = "esri-scale-bar", i = {
  base: t,
  labelContainer: `${t}__label-container`,
  rulerLabelContainer: `${t}__label-container--ruler`,
  lineLabelContainer: `${t}__label-container--line`,
  topLabelContainer: `${t}__label-container--top`,
  bottomLabelContainer: `${t}__label-container--bottom`,
  label: `${t}__label`,
  line: `${t}__line`,
  topLine: `${t}__line--top`,
  bottomLine: `${t}__line--bottom`,
  ruler: `${t}__ruler`,
  barContainer: `${t}__bar-container`,
  rulerBarContainer: `${t}__bar-container--ruler`,
  lineBarContainer: `${t}__bar-container--line`
}, D = x`.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.esri-widget{--esri-widget-padding-x: 15px;--esri-widget-padding-y: var(--calcite-spacing-md);--esri-widget-padding: var(--esri-widget-padding-y) var(--esri-widget-padding-x);box-sizing:border-box;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget *,.esri-widget :before,.esri-widget :after{box-sizing:inherit}.esri-widget.esri-widget--disabled>*{opacity:.4;pointer-events:none}.esri-widget.esri-widget--compact{--esri-widget-padding-y: 0;--esri-widget-padding-x: 0}.esri-widget__anchor{color:var(--calcite-color-text-2)}.esri-widget__anchor:hover{color:var(--calcite-color-text-3)}.esri-widget__anchor:hover,.esri-widget__anchor:focus{text-decoration:underline}.esri-widget__anchor--disabled{opacity:.4;pointer-events:none}.esri-widget__header{background-color:var(--calcite-color-foreground-1);flex:1 0 100%;justify-content:space-between;align-items:center;width:100%;min-height:48px;padding:12px 0 12px 15px;display:flex}.esri-widget__header .esri-widget__heading{width:calc(100% - 48px);text-align:initial;color:var(--calcite-color-text-1);align-items:center;margin:0;padding:0;display:flex}.esri-widget__header-button{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);border:none;flex:0 0 48px;justify-content:center;align-self:stretch;align-items:center;width:48px;padding:0;display:flex}.esri-widget__footer{background-color:var(--calcite-color-foreground-1);justify-content:center;align-items:center;width:100%;min-height:48px;display:flex}.esri-widget__footer-pagination{color:var(--calcite-color-text-2);justify-content:space-between;align-items:center;display:flex}.esri-widget__footer-pagination-previous-button,.esri-widget__footer-pagination-next-button{cursor:pointer;background-color:var(--calcite-color-foreground-1);border:0;margin:0 7px;padding:12px 15px;transition:background-color .125s ease-in-out}.esri-widget__footer-pagination-previous-button:hover,.esri-widget__footer-pagination-previous-button:focus,.esri-widget__footer-pagination-next-button:hover,.esri-widget__footer-pagination-next-button:focus{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1)}.esri-menu{visibility:hidden;z-index:1;background-clip:padding;background-color:var(--calcite-color-foreground-1);background-clip:padding-box;width:100%;max-height:0;margin:2px 0 0;padding:0;font-size:var(--calcite-font-size);line-height:var(--calcite-spacing-xl);position:absolute;top:100%;left:0;overflow:hidden;box-shadow:0 1px 2px #0000004d}.esri-menu .esri-menu__header{color:var(--calcite-color-text-inverse);background-color:var(--calcite-color-inverse);padding:6px 12px}.esri-menu__list{margin:0;padding:0;list-style:none}.esri-menu__list-item{cursor:pointer;border-top:1px solid #adadad4d;border-left:3px solid #0000;padding:.8em 1em}.esri-menu__list-item [class^=esri-icon-],.esri-menu__list-item [class*=" esri-icon-"]{padding-right:2.8px}.esri-menu__list-item:first-child{border-top:none}.esri-menu__list-item--focus,.esri-menu__list-item:hover,.esri-menu__list-item:focus{background-color:var(--calcite-color-foreground-1)}.esri-menu__list-item:active{background-color:var(--calcite-color-foreground-current)}.esri-menu__list-item--active,.esri-menu__list-item--active:hover,.esri-menu__list-item--active:focus{background-color:var(--calcite-color-foreground-1);border-left-color:var(--calcite-color-brand)}.esri-widget__table{border-collapse:collapse;color:var(--calcite-color-text-1);border:none;width:100%;line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget__table tr:nth-child(odd){background-color:var(--calcite-color-transparent)}.esri-widget__table tr:nth-child(2n){background-color:var(--calcite-color-transparent-press)}.esri-widget__table tr a{color:var(--calcite-color-text-2)}.esri-widget__table tr a:hover,.esri-widget__table tr a:focus{color:var(--calcite-color-text-1)}.esri-widget__table tr td,.esri-widget__table tr th{vertical-align:top;word-break:break-word;padding:.5em .7em;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular)}.esri-widget__table tr th{text-align:left;border-right:3px solid #0000000d;width:50%}.esri-widget__table tr td{width:50%}.esri-input{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1);border:1px solid #959595;font-size:var(--calcite-font-size)}.esri-input::-ms-clear{display:none}.esri-input::placeholder{opacity:1;color:var(--calcite-color-text-2)}.esri-input:placeholder-shown{text-overflow:ellipsis}.esri-input[type=text],.esri-input[type=password],.esri-input[type=number]{height:32px;padding:0 .5em}calcite-combobox.esri-input{border:none}.esri-widget__content--empty{text-align:center;color:var(--calcite-color-border-input);flex-flow:column wrap;align-items:center;padding:18px 22px;display:flex}.esri-widget__content--empty h1.esri-widget__heading,.esri-widget__content--empty h2.esri-widget__heading,.esri-widget__content--empty h3.esri-widget__heading,.esri-widget__content--empty h4.esri-widget__heading,.esri-widget__content--empty h5.esri-widget__heading{font-weight:var(--calcite-font-weight-regular)}.esri-widget__content-illustration--empty{width:128px;padding:1rem 0}.esri-widget__content-icon--empty{width:32px;padding:.5rem 0}.esri-select{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background:var(--calcite-color-foreground-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 32 32' width='32' height='32'%3E%3Cpath d='M8 11.207l-4-4V5.793l4 4 4-4v1.414z' fill='%23adadad' fillrule='nonzero'/%3E%3C/svg%3E") 100% no-repeat;border:1px solid #959595;border-radius:0;width:100%;height:32px;margin:0;padding:0 .5em;font-family:inherit;font-size:.85em;display:block}.esri-select[disabled]{cursor:auto}.esri-select::-ms-expand{display:none}.esri-disabled a,.esri-disabled [role=menu],.esri-disabled [role=checkbox],.esri-disabled [class^=esri-icon-],.esri-disabled [class*=" esri-icon-"]{color:var(--calcite-color-text-3)}.keynav-mode .esri-widget:focus,.keynav-mode .esri-widget :focus{z-index:1;outline-offset:2px;outline:2px solid #adadad}.esri-widget__loader-animation{border:.15em solid #adadad4d;border-top-color:var(--calcite-color-border-input);border-radius:100%;width:1em;height:1em;font-size:var(--calcite-font-size-md);animation:1.25s linear infinite esri-rotate;display:block;transform:translateZ(0)}:dir(rtl) .esri-widget__table th{text-align:right;border-left:3px solid #0000000d;border-right:none}:dir(rtl) .esri-select{background-position:0}:dir(rtl) .esri-menu__list-item{border-left:none;border-right:3px solid #0000}:dir(rtl) .esri-menu__list-item [class^=esri-icon-],:dir(rtl) .esri-menu__list-item [class*=" esri-icon-"]{padding-left:2px;padding-right:0}:dir(rtl) .esri-menu__list-item--active{border-right-color:var(--calcite-color-brand)}.esri-icon-font-fallback-text{clip:rect(0 0 0 0);width:1px;height:1px;position:absolute;overflow:hidden}.esri-rotating{animation:1.25s linear infinite esri-rotate;transform:translateZ(0)}.esri-clearfix:before,.esri-clearfix:after{content:" ";display:table}.esri-clearfix:after{clear:both}.esri-interactive{cursor:pointer}.esri-hidden{display:none!important}.esri-invisible{visibility:hidden!important}.esri-offscreen{position:absolute;top:-999em;left:-999em}.esri-match-height{flex-direction:column;flex:auto;display:flex;overflow:hidden}.esri-scale-bar{box-shadow:none!important;background:0 0}.esri-component.esri-scale-bar.esri-widget,.esri-scale-bar.esri-widget{box-shadow:none;background:0 0}.esri-scale-bar__bar-container{align-items:flex-end;font-size:var(--calcite-font-size-sm);transition:width .25s ease-in-out;display:flex;position:relative}.esri-scale-bar__bar-container--ruler{flex-direction:column}.esri-scale-bar__ruler{--color-ruler-background: var(--calcite-color-inverse);--color-ruler-foreground: var(--calcite-color-foreground-1);height:var(--calcite-spacing-xs);box-shadow:0 0 0 1px var(--calcite-color-text-1),0 1px 2px var(--calcite-color-foreground-1)}.esri-scale-bar__ruler:before,.esri-scale-bar__ruler:after{content:"";display:block;height:50%;background-image:linear-gradient(to right,var(--color-ruler-foreground) 0%,var(--color-ruler-foreground) 25%,var(--color-ruler-background) 25%,var(--color-ruler-background) 50%,var(--color-ruler-foreground) 50%,var(--color-ruler-foreground) 75%,var(--color-ruler-background) 75%,var(--color-ruler-background) 100%)}.esri-scale-bar__ruler:after{transform:scaleX(-1)}.esri-scale-bar__bar-container--line:last-child{align-items:flex-start}.esri-scale-bar__line{--line-thickness: 2px;--tic-height: 1.5em;--border-style: var(--line-thickness) solid var(--calcite-color-text-1);background-color:color-mix(in srgb,var(--calcite-color-foreground-1) 50%,transparent);height:var(--tic-height);position:relative;left:0}.esri-scale-bar__line--top{border-bottom:var(--border-style)}.esri-scale-bar__line--bottom{border-top:var(--border-style);top:calc(-1 * var(--line-thickness))}.esri-scale-bar__line--top:before,.esri-scale-bar__line--top:after,.esri-scale-bar__line--bottom:before,.esri-scale-bar__line--bottom:after{content:"";background-color:color-mix(in srgb,var(--calcite-color-foreground-1) 50%,transparent);border-right:var(--border-style);width:1px;height:var(--tic-height);display:block;position:absolute}.esri-scale-bar__line--top:before{bottom:calc(-1 * var(--line-thickness));left:0}.esri-scale-bar__line--top:after{bottom:calc(-1 * var(--line-thickness));right:0}.esri-scale-bar__line--bottom:before{top:calc(-1 * var(--line-thickness));left:0}.esri-scale-bar__line--bottom:after{height:var(--tic-height);top:calc(-1 * var(--line-thickness));right:0}.esri-scale-bar__label-container--line{position:absolute;left:0}.esri-scale-bar__label-container--ruler{justify-content:space-between;width:100%;display:flex;position:relative}.esri-scale-bar__label-container--ruler .esri-scale-bar__label{text-shadow:1px 0 var(--calcite-color-foreground-1),0 1px var(--calcite-color-foreground-1),1px 1px var(--calcite-color-foreground-1),-1px 0 var(--calcite-color-foreground-1),0 -1px var(--calcite-color-foreground-1),-1px -1px var(--calcite-color-foreground-1);padding:6px 0 0}.esri-scale-bar__label-container--top{bottom:0}.esri-scale-bar__label-container--bottom{top:1px}.esri-scale-bar__label{white-space:nowrap;color:var(--calcite-color-text-1);font-size:inherit;padding:0 7px;font-weight:var(--calcite-font-weight-semibold)}:dir(rtl) .esri-scale-bar__ruler{margin:0 .5ch 0 2ch}:dir(rtl) .esri-scale-bar__label-container--line{left:auto;right:0}`, R = S($);
class E extends z {
  constructor() {
    super(...arguments), this._defaultUnit = "metric", this.messages = L(), this.viewModel = R(this), this.view = this.viewModel.view, this.autoDestroyDisabled = !1, this.barStyle = "line", this.icon = "actual-size", this.arcgisReady = M();
  }
  static {
    this.properties = { view: 0, autoDestroyDisabled: 5, barStyle: 1, icon: 1, label: 1, messageOverrides: 0, position: 3, referenceElement: 1, unit: 1 };
  }
  static {
    this.styles = D;
  }
  get unit() {
    return this._unit ?? this._defaultUnit;
  }
  set unit(e) {
    this._unit = e;
  }
  async destroy() {
    await this.manager.destroy();
  }
  updated() {
    this._handleRootCreateOrUpdate();
  }
  loaded() {
    this.manager.onLifecycle(() => k(() => ({
      defaultUnit: this.viewModel.view ? y(this.viewModel.view) : void 0,
      stationary: this.viewModel.view?.stationary,
      center: this.viewModel.view?.center,
      scale: this.viewModel.view?.scale,
      zoom: this.viewModel.view?.zoom
    }), ({ defaultUnit: e, stationary: r }) => {
      this._defaultUnit = e ?? "metric", r && this.requestUpdate();
    }, { initial: !0 }));
  }
  _handleContainerRef(e) {
    e !== void 0 && this._handleRootCreateOrUpdate();
  }
  _handleRootCreateOrUpdate() {
    const e = this.el;
    if (!this.viewModel && !e.childElem)
      return;
    const r = e.childElem?.getBoundingClientRect();
    if (!r)
      return;
    const { scaleComputedFrom: l } = this.viewModel, c = r.left + window.pageXOffset, o = r.top + window.pageYOffset, n = B(c, o);
    (n.x !== l.x || n.y !== l.y) && (this.viewModel.scaleComputedFrom = n);
  }
  _formatDistance(e, r) {
    return C(e, {
      style: "unit",
      unit: r,
      unitDisplay: "short"
    });
  }
  render() {
    const e = this.viewModel.state === "disabled", r = {
      [m.disabled]: e
    };
    let l, c;
    if (!e) {
      const { unit: o, barStyle: n } = this, p = o === "imperial" || o === "dual", h = o === "metric" || o === "dual", b = 100, _ = o === "dual" ? "line" : n;
      if (p) {
        const s = this.viewModel.getScaleBarProperties(b, "imperial");
        s && (c = _ === "ruler" ? this._renderRuler(s) : this._renderLine(s, "bottom"));
      }
      if (h) {
        const s = this.viewModel.getScaleBarProperties(b, "metric");
        s && (l = _ === "ruler" ? this._renderRuler(s) : this._renderLine(s, "top"));
      }
    }
    return g`<div class=${a(d(i.base, m.widget, r))} ${w(this._handleContainerRef)}>${l}${c}</div>`;
  }
  _renderRuler(e) {
    const { length: r, unit: l, value: c } = e, o = Math.round(r), n = this._formatDistance(c, l);
    return g`<div class=${a(d(i.barContainer, i.rulerBarContainer))}><div class=${a(i.ruler)} style=${f({ width: `${o}px` })}></div><div class=${a(d(i.labelContainer, i.rulerLabelContainer))}><div class=${a(i.label)}>0</div><div class=${a(i.label)}>${n}</div></div></div>`;
  }
  _renderLine(e, r) {
    const { length: l, unit: c, value: o } = e, n = Math.round(l), p = this._formatDistance(o, c), h = {
      [i.topLabelContainer]: r === "top",
      [i.bottomLabelContainer]: r === "bottom"
    }, b = g`<div class=${a(d(i.labelContainer, i.lineLabelContainer, h))}><div class=${a(i.label)}>${p}</div></div>`, _ = {
      [i.topLine]: r === "top",
      [i.bottomLine]: r === "bottom"
    }, s = g`<div class=${a(d(i.line, _))} style=${f({ width: `${n}px` })}></div>`;
    return g`<div class=${a(d(i.barContainer, i.lineBarContainer))}>${[s, b]}</div>`;
  }
}
v("arcgis-scale-bar", E);
export {
  E as ArcgisScaleBar
};
