/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as e } from "../../chunks/runtime.js";
import { css as m, html as o } from "lit";
import { watch as u } from "@arcgis/core/core/reactiveUtils.js";
import { LitElement as l } from "@arcgis/lumina";
import f from "@arcgis/core/geometry/operators/support/GeographicTransformation.js";
import c from "@arcgis/core/geometry/operators/support/GeographicTransformationStep.js";
const d = m`.invalid-wkid-text{color:var(--calcite-color-status-danger);font-size:var(--calcite-font-size--0)}`, p = /^\s*\d+(?:\s*\+\s*\d+)*(?:\s*,\s*\d+(?:\s*\+\s*\d+)*)*\s*$/u;
function h(s) {
  if (!/^\d+$/u.test(s))
    return null;
  const t = Number(s);
  return Number.isSafeInteger(t) && t > 0 ? t : null;
}
function T(s) {
  if (!p.test(s))
    return null;
  const t = [];
  for (const i of s.split(",")) {
    const a = [];
    for (const r of i.split("+")) {
      const n = h(r.trim());
      if (n == null)
        return null;
      a.push(new c({ wkid: n }));
    }
    t.push(new f({ steps: a }));
  }
  return t;
}
function v(s) {
  return s == null || s.length === 0 ? "" : s.map(
    (t) => t.steps.map((i) => i.wkid).filter((i) => i != null).join("+")
  ).filter((t) => t.length > 0).join(",");
}
class w extends l {
  constructor() {
    super(...arguments), this._isValidDatumTransformations = !0;
  }
  static {
    this.properties = { _datumTransformations: 16, _isValidDatumTransformations: 16, templateOptions: 0, viewModel: 0, messages: 0 };
  }
  static {
    this.styles = d;
  }
  loaded() {
    this.manager.onLifecycle(() => [
      u(() => this.viewModel.datumTransformations, (t) => {
        this._datumTransformations = v(t), this._isValidDatumTransformations = !0;
      }, { initial: !0 })
    ]);
  }
  render() {
    const { messages: t } = this, i = this.viewModel.cimVersion;
    if (!(i != null && Number.parseFloat(i) < 3.7))
      return o`<div><calcite-label>${t.datumTransformations}<calcite-input .value=${this._datumTransformations ?? ""} .max=${Number.MAX_SAFE_INTEGER} @calciteInputInput=${({ currentTarget: a }) => {
        const r = a.value?.trim() ?? "";
        if (this._datumTransformations = r, r === "") {
          this.viewModel.datumTransformations = null, this._isValidDatumTransformations = !0;
          return;
        }
        const n = T(r);
        if (n == null) {
          this._isValidDatumTransformations = !1;
          return;
        }
        this._isValidDatumTransformations = !0, this.viewModel.datumTransformations = n;
      }}></calcite-input>${this._isValidDatumTransformations ? null : o`<div class="invalid-wkid-text">${t.invalidWkid}</div>`}</calcite-label></div>`;
  }
}
e("arcgis-print-datum-transformation-input", w);
export {
  w as PrintDatumTransformationInput
};
