/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { m as n } from "./model-setter.js";
import { S as f, s as p, a as S } from "./serial-chart-model.js";
import { g as c } from "./serial-chart-data.js";
import { a as g } from "./data.js";
import { g as h, s as y, a as u, b as v } from "./bar-chart-series.js";
import "@arcgis/toolkit/intl";
import "lodash-es";
import "luxon";
import "d3-array";
import "@arcgis/toolkit/type";
import { W as b } from "./series-types.js";
import { bk as O, bd as _, bR as a, aJ as L, ar as I } from "./index.js";
import "@arcgis/core/Graphic.js";
import "@arcgis/core/renderers/support/jsonUtils.js";
import "@arcgis/core/symbols/support/symbolUtils.js";
import "@esri/arcgis-html-sanitizer";
import "@arcgis/core/intl.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/request.js";
import "@arcgis/core/core/sql.js";
import "@arcgis/core/AttributeBinsGraphic.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 "@arcgis/core/core/promiseUtils.js";
import "./runtime.js";
import "@arcgis/toolkit/dom";
var C = Object.defineProperty, z = Object.getOwnPropertyDescriptor, d = (o, e, t, r) => {
  for (var i = z(e, t), s = o.length - 1, m; s >= 0; s--)
    (m = o[s]) && (i = m(e, t, i) || i);
  return i && C(e, t, i), i;
};
class l extends f {
  constructor() {
    super(...arguments), this._chartType = b.BarSeries;
  }
  async setup(e) {
    await this.loadConfigFromLayer(e), this.setupLocalProps(), e.config !== void 0 && await this.updateSeriesFromLayerFilter(), typeof this.resolveSetup == "function" && this.resolveSetup();
  }
  // #endregion
  // ---------------------------------------------------------------------------------------------
  // #region Protected Methods
  // ---------------------------------------------------------------------------------------------
  /** @private */
  generateDefaultConfig() {
    const e = O(this.commonStrings);
    return e.series = [
      _({
        objectIDField: a(this.layerInfo.layer).idField,
        commonStrings: this.commonStrings
      })
    ], e;
  }
  // #endregion
  // ---------------------------------------------------------------------------------------------
  // #region Series Methods
  // ---------------------------------------------------------------------------------------------
  /**
   * Gets whether to hide oversized data labels of the side-by-side series based on the series index.
   * If the index is out of bounds, it will return `undefined`.
   *
   * @param seriesIndex - The index of the series.
   */
  getSeriesHideOversizedSideBySideLabels(e) {
    return h(e, this._config);
  }
  setSeriesHideOversizedSideBySideLabels(e, t) {
    y(e, t, this._config);
  }
  /**
   * Gets whether to hide oversized stacked labels of the series based on the series index.
   * If the index is out of bounds, it will return `undefined`.
   *
   * @param seriesIndex - The index of the series.
   */
  getSeriesHideOversizedStackedLabels(e) {
    return u(e, this._config);
  }
  setSeriesHideOversizedStackedLabels(e, t) {
    v(e, t, this._config);
  }
  // #endregion
  //#region Sorting Methods
  /**
   * Gets the sort order for the bar chart.
   * @returns {"xAxisAsc" | "xAxisDesc" | "yAxisAsc" | "yAxisDesc" | "customSort"}
   */
  getSortOrder() {
    return g(this._config);
  }
  resetSeriesStyling() {
    for (let e = 0; e < this.seriesLength; e += 1) {
      const t = this.getSeriesId(e), r = L({
        colorIndex: e,
        opacity: I
      });
      if (p(r, e, this._config), this.layerInfo !== void 0) {
        const i = c({
          config: this._config,
          seriesIndex: e,
          layerInfo: this.layerInfo,
          commonStrings: this.commonStrings
        });
        i !== a(this.layerInfo.layer).idField && S(i ?? t, e, this._config);
      }
    }
    this._config.colorMatch = !0;
  }
  /**
   * Returns whether the series styling is able to be reset.
   */
  resetAvailable() {
    const e = !this.colorMatch;
    let t = !1;
    if (!e && this.layerInfo !== void 0)
      for (let r = 0; r < this.seriesLength; r += 1) {
        const i = c({
          config: this._config,
          seriesIndex: r,
          layerInfo: this.layerInfo,
          commonStrings: this.commonStrings
        }), s = this.getSeriesName(r);
        if (i !== void 0 && i !== a(this.layerInfo.layer).idField && i !== s) {
          t = !0;
          break;
        }
      }
    return e || t;
  }
  // #endregion
}
d([
  n
], l.prototype, "setSeriesHideOversizedSideBySideLabels");
d([
  n
], l.prototype, "setSeriesHideOversizedStackedLabels");
d([
  n
], l.prototype, "resetSeriesStyling");
export {
  l as BarChartModel
};
