/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { fetchT9nStringsBundle as p, getElementLocale as d } from "@arcgis/toolkit/intl";
import { g as h } from "./runtime.js";
import { bM as r, bO as c, bR as g, aX as f } from "./index.js";
import { c as l } from "./index2.js";
import "lodash-es";
import "luxon";
import "d3-array";
import "@arcgis/toolkit/type";
import "./series-types.js";
import "@arcgis/core/core/promiseUtils.js";
import "@arcgis/core/request.js";
import "@arcgis/core/geometry/support/jsonUtils.js";
import "@arcgis/core/rest/support/AttributeBinsQuery.js";
import "@arcgis/core/rest/support/StatisticDefinition.js";
import "@arcgis/core/time/TimeExtent.js";
import "@esri/arcgis-html-sanitizer";
import "@arcgis/toolkit/dom";
import "@arcgis/core/intl.js";
import "@arcgis/core/Graphic.js";
import "@arcgis/core/renderers/support/jsonUtils.js";
import "@arcgis/core/symbols/support/symbolUtils.js";
import "@arcgis/core/layers/support/FeatureFilter.js";
import "@arcgis/core/smartMapping/statistics/histogram.js";
import "@arcgis/core/smartMapping/statistics/summaryStatistics.js";
import "simple-statistics";
import "@arcgis/core/core/sql.js";
import "@arcgis/core/AttributeBinsGraphic.js";
class G extends EventTarget {
  /**
   * @param args
   * @privateRemarks This "any" constructor is needed for TypeScript to merge
   * the base class and mixin classes types together smoothly.
   */
  constructor(...i) {
    super(), this.dirtyAsyncSetters = [], this.asyncConfigUpdateInProgress = !1, this.pendingUpdates = 0, this.dataStore = {}, this.asyncUpdatesPromise = new Promise((t) => {
      this.resolveSetup = t;
    }), this.emitConfigUpdate = (t) => {
      this.dispatchEvent(
        new CustomEvent("arcgisChartsModelConfigChange", {
          detail: { config: this._config, setterName: t }
        })
      );
    }, this.guardSetterFromAsyncOverwrite = async (t) => {
      t(), this.asyncConfigUpdateInProgress && (await this.asyncUpdatesPromise, t());
    };
  }
  /**
   * The chart type.
   */
  get chartType() {
    return this._chartType;
  }
  /**
   * Checks if the current chart model is for the same chart as another chart model.
   *
   * @param otherModel - The other chart model to compare to.
   */
  isSameChartAs(i) {
    const t = i?.layer;
    return t !== void 0 && this._config.id === i?.chartId && this.layerInfo?.layer.id === t.id;
  }
  /**
   * Can be awaited to allow any pending async updates to complete.
   * @public
   */
  async update() {
    await this.asyncUpdatesPromise;
  }
  /**
   * A function that loads the config based on the provided props.
   *
   * @param params.layer - The layer to be used as the data source for the chart.
   * @param params.iLayer - The layer description to use if the layer is not provided.
   * @param params.config - The config object to be loaded.
   * @private
   */
  async loadConfigFromLayer(i) {
    const { layer: t, iLayer: s, config: a } = i;
    this.commonStrings = await p(
      d(document.documentElement).t9nLocale,
      h("./assets/common/t9n"),
      "messages."
    );
    let e = t;
    if (!e && s ? e = await r(s) : !e && a?.iLayer && (e = await r(a.iLayer)), e) {
      const o = await c(e, !0), m = g(e).idField;
      this.layerInfo = {
        layer: e,
        layerFieldsInfo: o,
        objectIdField: m
      };
    }
    this._config = a ? await l(a) : this.generateDefaultConfig(), this._config.legend !== void 0 && this._config.legend?.title === void 0 && (this._config.legend.title = f().title), s && (this._config.iLayer = s);
  }
  /**
   * Manually block the async guard to queue up config updates until unblocked.
   * @private
   */
  startAsyncUpdate() {
    this.pendingUpdates === 0 && (this.asyncConfigUpdateInProgress = !0, this.asyncUpdatesPromise = new Promise((i) => {
      this.resolveSetup = i;
    })), this.pendingUpdates += 1;
  }
  /**
   * Manually unblock the async guard to allow queued config updates to proceed.
   * @private
   */
  finishAsyncUpdate() {
    this.pendingUpdates -= 1, this.pendingUpdates === 0 && (this.asyncConfigUpdateInProgress = !1, this.resolveSetup?.());
  }
  // #endregion
}
function H(n, i, t) {
  const s = t.set, a = t.value;
  return s && (t.set = function(e) {
    this.guardSetterFromAsyncOverwrite(() => {
      s.call(this, e), this.emitConfigUpdate(i);
    });
  }), a && (t.value = function(...e) {
    this.guardSetterFromAsyncOverwrite(() => {
      a.apply(this, e), this.emitConfigUpdate(i);
    });
  }), t;
}
export {
  G as C,
  H as m
};
