/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as r } from "../../chunks/runtime.js";
import { css as s, html as n } from "lit";
import { watch as c } from "@arcgis/core/core/reactiveUtils.js";
import u from "@arcgis/core/geometry/SpatialReference.js";
import { LitElement as o } from "@arcgis/lumina";
const p = s`.sr-label{display:flex;gap:var(--calcite-spacing-xs)}.invalid-wkid-text{color:var(--calcite-color-status-danger);font-size:var(--calcite-font-size--0)}`;
function d(e) {
  if (e == null)
    return !1;
  const t = e.wkid;
  return t != null && t >= 2e3 ? !0 : e.wkt2 != null || e.wkt != null;
}
function f(e) {
  return e == null ? e : Math.round(Number.parseFloat(e));
}
class m extends o {
  constructor() {
    super(...arguments), this._isValidSpatialReference = !0;
  }
  static {
    this.properties = { _isValidSpatialReference: 16, _outSpatialReference: 16, templateOptions: 0, viewModel: 0, messages: 0 };
  }
  static {
    this.styles = p;
  }
  loaded() {
    this.manager.onLifecycle(() => [
      c(() => this.viewModel.outSpatialReference, (t) => {
        this._outSpatialReference = t ?? void 0;
      }, { initial: !0 })
    ]);
  }
  render() {
    const { messages: t, _outSpatialReference: a } = this;
    return n`<div><calcite-label><div class="sr-label">${t.outSpatialReference}<calcite-link href=https://next.gha.afd.arcgis.com/rest/services-reference/enterprise/using-spatial-references/ target=_blank>(WKID)</calcite-link></div><calcite-input-number data-input-name=outSpatialReference integer number-button-type=none .value=${this._outSpatialReference?.wkid?.toString() ?? ""} .max=${Number.MAX_SAFE_INTEGER} @calciteInputNumberInput=${({ currentTarget: l }) => {
      const i = f(l.value);
      if (Number.isNaN(i) || i == null || i <= 0 || !Number.isFinite(i)) {
        l.value = `${a?.wkid ?? ""}`;
        return;
      }
      this.viewModel.outSpatialReference = Number.isNaN(i) || i == null ? null : new u({ wkid: i }), this._isValidSpatialReference = !a || d(a);
    }}></calcite-input-number>${this._isValidSpatialReference ? null : n`<div class="invalid-wkid-text">${t.invalidWkid}</div>`}</calcite-label></div>`;
  }
}
r("arcgis-print-out-spatial-reference-input", m);
export {
  m as PrintOutSpatialReferenceInput
};
