/* 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 c, bT 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 d, h as m } from "../../chunks/index4.js";
import "@arcgis/toolkit/dom";
import { LitElement as g, createEvent as p } from "@arcgis/lumina";
import { css as f, html as o } from "lit";
import { C as a } from "../../chunks/interfaces.js";
const u = f`:host{margin-bottom:var(--arcgis-charts-intra-section-margin);margin-top:var(--arcgis-charts-intra-section-margin);height:100%}`;
class C extends g {
  constructor() {
    super(...arguments), this.onModelConfigChange = async (e) => {
      const i = e?.detail.config ?? this.model.config;
      this.layer === void 0 && await this.updateFetchLayerFieldsInfo(i);
    }, this.activeColorMatch = !1, this.popoverPlacement = "leading", this.arcgisChartsConfigNoSeriesUpdate = p();
  }
  static {
    this.properties = { layerFieldsInfo: 16, activeColorMatch: 16, model: 0, timeZone: 1, popoverPlacement: 1, seriesColor: 0, calculatedMinMaxBounds: 0, page: 1, layer: 0, usePopupTemplateFieldsInfo: 5 };
  }
  static {
    this.styles = u;
  }
  async load() {
    this.seriesColor !== void 0 && this.seriesColorChange(this.seriesColor), await this.updateFetchLayerFieldsInfo(this.model?.config), this.modelChange(this.model), this.updateDataFilters();
  }
  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 !== void 0 && this.usePopupTemplateFieldsInfo !== e.get("usePopupTemplateFieldsInfo") && (t = !0), e.has("seriesColor") && this.seriesColor !== void 0 && 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.activeColorMatch = e?.get(0) === void 0, this.model.colorMatch && e?.forEach((t, i) => {
      d(t) && e?.get(0) !== void 0 && t?.color !== void 0 && !r(this.model.getSeriesColor(i), t?.color) && this.model.setSeriesColor(t?.color, i);
    });
  }
  async updateDataFilters() {
    const e = this.model.getDataFilters(), t = e?.where, i = this.layer?.definitionExpression ?? void 0;
    r(t, i) || await this.model.setDataFilters({
      ...e,
      where: i
    });
  }
  async updateFetchLayerFieldsInfo(e) {
    const t = e ?? this.model.config;
    let i = this.layer;
    if (!i) {
      const s = m(t) ? t.iLayer : void 0;
      s && (i = await n(s));
    }
    i && (this.layerFieldsInfo = await c(i, this.usePopupTemplateFieldsInfo));
  }
  render() {
    const e = this.layerFieldsInfo?.find((s) => s.name === this.model.xAxisField), t = e !== void 0 && h(e);
    let i;
    switch (this.page) {
      case a.Data:
        i = o`<arcgis-charts-config-bar-chart-data .model=${this.model} .layerFieldsInfo=${this.layerFieldsInfo}></arcgis-charts-config-bar-chart-data>`;
        break;
      case a.Series:
        i = o`<arcgis-charts-config-bar-chart-series .model=${this.model} .activeColorMatch=${this.activeColorMatch} .popoverPlacement=${this.popoverPlacement}></arcgis-charts-config-bar-chart-series>`;
        break;
      case a.Axes:
        i = o`<arcgis-charts-config-axes .model=${this.model} show-max-y-bound-option .calculatedMinMaxBounds=${this.calculatedMinMaxBounds}></arcgis-charts-config-axes>`;
        break;
      case a.Guides:
        i = o`<arcgis-charts-config-guides .model=${this.model} .timeZone=${this.timeZone} .enableXAxisGuide=${t} enable-y-axis-guide .calculatedMinMaxBounds=${this.calculatedMinMaxBounds}></arcgis-charts-config-guides>`;
        break;
      case a.Format:
        i = o`<arcgis-charts-config-format .model=${this.model}></arcgis-charts-config-format>`;
        break;
      case a.General:
        i = o`<arcgis-charts-config-general .model=${this.model}></arcgis-charts-config-general>`;
        break;
      default:
        i = "";
        break;
    }
    return i;
  }
}
l("arcgis-charts-config-bar-chart", C);
export {
  C as ArcgisChartsConfigBarChart
};
