/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as l } from "../../chunks/runtime.js";
import "@arcgis/toolkit/intl";
import { isEqual as r } from "lodash-es";
import "luxon";
import "d3-array";
import "@arcgis/toolkit/type";
import "../../chunks/series-types.js";
import { bM as n, bO as h } from "../../chunks/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 { b as m, h as c } from "../../chunks/index4.js";
import "@arcgis/toolkit/dom";
import { LitElement as d } from "@arcgis/lumina";
import { css as g, html as i } from "lit";
import { C as s } from "../../chunks/interfaces.js";
const f = g`:host{overflow-y:auto;overflow-x:hidden;margin-bottom:var(--arcgis-charts-intra-section-margin);margin-top:var(--arcgis-charts-intra-section-margin);height:100%}`;
class p extends d {
  constructor() {
    super(...arguments), this.onModelConfigChange = async (e) => {
      const a = e?.detail.config ?? this.model.config;
      this.layer === void 0 && await this.updateFetchLayerFieldsInfo(a);
    };
  }
  static {
    this.properties = { layerFieldsInfo: 16, model: 0, chartData: 0, seriesColor: 0, calculatedMinMaxBounds: 0, page: 1, layer: 0, usePopupTemplateFieldsInfo: 5 };
  }
  static {
    this.styles = f;
  }
  async load() {
    this.seriesColor !== void 0 && this.seriesColorChange(this.seriesColor), await this.updateFetchLayerFieldsInfo(this.model?.config), this.modelChange(this.model);
  }
  willUpdate(e) {
    let t = !1;
    e.has("model") && this.modelChange(this.model, e.get("model")), e.has("layer") && this.layer !== void 0 && !r(e.get("layer"), this.layer) && (t = !0), e.has("usePopupTemplateFieldsInfo") && this.usePopupTemplateFieldsInfo !== e.get("usePopupTemplateFieldsInfo") && (t = !0), e.has("seriesColor") && this.seriesColorChange(this.seriesColor), this.layerFieldsInfo === void 0 && (t = !0), t && this.updateFetchLayerFieldsInfo();
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.model.removeEventListener("arcgisChartsModelConfigChange", this.onModelConfigChange);
  }
  modelChange(e, t) {
    t?.removeEventListener("arcgisChartsModelConfigChange", this.onModelConfigChange), e?.addEventListener("arcgisChartsModelConfigChange", this.onModelConfigChange);
  }
  seriesColorChange(e) {
    this.model.colorMatch && e?.forEach((t) => {
      m(t) && e?.get(0) !== void 0 && !r(this.model.binSymbol, t) && (this.model.binSymbol = t);
    });
  }
  async updateFetchLayerFieldsInfo(e) {
    const t = e ?? this.model.config;
    let a = this.layer;
    if (!a) {
      const o = c(t) ? t.iLayer : void 0;
      o && (a = await n(o));
    }
    a && (this.layerFieldsInfo = await h(a, this.usePopupTemplateFieldsInfo));
  }
  render() {
    let e;
    switch (this.page) {
      case s.Data:
        e = i`<arcgis-charts-config-histogram-data .model=${this.model} .meanValue=${this.chartData?.mean} .medianValue=${this.chartData?.median} .standardDevValue=${this.chartData?.stddev} .minValue=${this.chartData?.min} .maxValue=${this.chartData?.max} .sumValue=${this.chartData?.sum} .nullsValue=${this.chartData?.nulls} .countValue=${this.chartData?.count} .layerFieldsInfo=${this.layerFieldsInfo}></arcgis-charts-config-histogram-data>`;
        break;
      case s.Axes:
        e = i`<arcgis-charts-config-axes .model=${this.model} show-max-y-bound-option .calculatedMinMaxBounds=${this.calculatedMinMaxBounds}></arcgis-charts-config-axes>`;
        break;
      case s.Guides:
        e = i`<arcgis-charts-config-guides .model=${this.model} enable-y-axis-guide></arcgis-charts-config-guides>`;
        break;
      case s.Format:
        e = i`<arcgis-charts-config-format .model=${this.model}></arcgis-charts-config-format>`;
        break;
      case s.General:
        e = i`<arcgis-charts-config-general .model=${this.model}></arcgis-charts-config-general>`;
        break;
      default:
        e = "";
        break;
    }
    return e;
  }
}
l("arcgis-charts-config-histogram", p);
export {
  p as ArcgisChartsConfigHistogram
};
