/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as p } from "../../chunks/runtime.js";
import { html as m } from "lit";
import { watch as o } from "@arcgis/core/core/reactiveUtils.js";
import { LitElement as h } from "@arcgis/lumina";
import { i as u } from "../../chunks/utils3.js";
class d extends h {
  constructor() {
    super(...arguments), this._dpi = 1;
  }
  static {
    this.properties = { _dpi: 16, viewModel: 0, messages: 0 };
  }
  loaded() {
    this.manager.onLifecycle(() => [
      o(() => this.viewModel.templateOptions.dpi, (e) => this._dpi = e <= 0 ? 1 : e, { initial: !0 })
    ]);
  }
  _handleDPIChange(e) {
    const t = this.viewModel.templateOptions, i = Number(e.target.value);
    if (Number.isNaN(i) || i <= 0 || !Number.isFinite(i)) {
      e.target.value = `${this._dpi}`;
      return;
    }
    if (u(t.layout)) {
      const a = t.dpi > 0 ? t.dpi : this._dpi, n = t.width, r = t.height;
      if (a > 0 && typeof n == "number" && typeof r == "number" && Number.isFinite(n) && Number.isFinite(r) && i !== a) {
        const s = i / a;
        t.width = Math.max(1, Math.round(n * s)), t.height = Math.max(1, Math.round(r * s));
      }
    }
    t.dpi = i;
  }
  render() {
    return m`<div><calcite-label>${this.messages.dpi}<calcite-input-number data-input-name=dpi min=1 .value=${`${this._dpi}`} .max=${Number.MAX_SAFE_INTEGER} @calciteInputNumberChange=${this._handleDPIChange}></calcite-input-number></calcite-label></div>`;
  }
}
p("arcgis-print-dpi-input", d);
export {
  d as PrintDPIInput
};
