/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as o } from "../../chunks/runtime.js";
import { css as u, html as h } from "lit";
import { i as p, m, s as d, U as r } from "../../chunks/chart-ui-utils2.js";
import { u as g } from "../../chunks/useT9n.js";
import { createRef as b, ref as f } from "lit/directives/ref.js";
import { LitElement as v, createEvent as F, safeClassMap as a } from "@arcgis/lumina";
const s = {
  container: "container",
  label: "label",
  numberInput: "number-input"
}, C = u`.hide{visibility:hidden}.am5-html-container{z-index:101!important}.am5-layer-1000{z-index:1000!important}.am5-layer-30{z-index:100!important}.show{display:block}.notifyPanel{flex:0 1 auto}.disable-interactions{pointer-events:none}.dim-text{color:var(--arcgis-charts-dim-text)}.container{width:var(--arcgis-charts-config-calcite-block-width, var(--arcgis-charts-config-calcite-block-default-width));height:var(--arcgis-charts-config-calcite-block-height, var(--arcgis-charts-config-calcite-block-default-height));margin-top:.5rem}.container>.number-input{margin-bottom:.5rem;display:flex}.container>.number-input>div{width:100%}.label{display:flex;margin-bottom:.5rem;justify-content:space-between}`;
class I extends v {
  constructor() {
    super(...arguments), this._messages = g(), this.decimalPlacesInputElement = b(), this.arcgisChartsConfigNumberFormatChange = F();
  }
  static {
    this.properties = { messageOverrides: 0, numberFormat: 0 };
  }
  static {
    this.styles = C;
  }
  onDecimalPlacesChange() {
    const t = this.decimalPlacesInputElement.value?.value, i = Math.floor(Number(t)), n = i === Number(t) && i >= 0;
    if (t !== void 0 && n && p(t, this.decimalPlacesInputElement.value?.min, this.decimalPlacesInputElement.value?.max)) {
      const c = Number.parseInt(t), e = {
        minimumFractionDigits: this.numberFormat?.minimumFractionDigits,
        maximumFractionDigits: c
      };
      e.maximumFractionDigits !== void 0 && e.minimumFractionDigits !== void 0 && e.minimumFractionDigits > e.maximumFractionDigits && (e.minimumFractionDigits = e.maximumFractionDigits);
      const l = this.getUpdatedNumberFormat(e);
      this.arcgisChartsConfigNumberFormatChange.emit(l), this.decimalPlacesInputElement.value && m({
        inputElement: this.decimalPlacesInputElement.value,
        status: r.IDLE
      });
    } else this.decimalPlacesInputElement.value && m({
      inputElement: this.decimalPlacesInputElement.value,
      status: r.INVALID
    });
  }
  onShowThousandsSeparatorChange(t) {
    const i = t.target.checked, n = this.getUpdatedNumberFormat({
      useGrouping: i
    });
    this.arcgisChartsConfigNumberFormatChange.emit(n);
  }
  getUpdatedNumberFormat(t) {
    return {
      ...this.numberFormat,
      ...t
    };
  }
  render() {
    return h`<div class=${a(s.container)}><calcite-label class=${a(s.label)}>${this._messages.decimalPlaces}<calcite-input type=number class=${a(s.numberInput)} min=0 max=20 step=1 .value=${d(this.numberFormat?.maximumFractionDigits, 2)} @calciteInputInput=${this.onDecimalPlacesChange} ${f(this.decimalPlacesInputElement)}></calcite-input></calcite-label><calcite-label layout=inline-space-between class=${a(s.label)}>${this._messages.showThousandSeparators}<calcite-switch name=useGrouping .checked=${!!(this.numberFormat?.useGrouping ?? !0)} @calciteSwitchChange=${this.onShowThousandsSeparatorChange}></calcite-switch></calcite-label></div>`;
  }
}
o("arcgis-charts-config-number-format", I);
export {
  I as ArcgisChartsConfigNumberFormat
};
