/* 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 } 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 { h } from "../../chunks/index4.js";
import "@arcgis/toolkit/dom";
import { LitElement as d } from "@arcgis/lumina";
import { css as m, html as s } from "lit";
import { C as a } from "../../chunks/interfaces.js";
const f = m`: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 o = e?.detail.config ?? this.model.config;
      this.layer === void 0 && await this.updateFetchLayerFieldsInfo(o);
    }, this.activeColorMatch = !1, this.popoverPlacement = "leading";
  }
  static {
    this.properties = { layerFieldsInfo: 16, activeColorMatch: 16, model: 0, popoverPlacement: 1, seriesColor: 0, page: 1, calculatedMinMaxBounds: 0, 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), this.updateDataFilters();
  }
  willUpdate(e) {
    let i = !1;
    e.has("model") && this.modelChange(this.model, e.get("model")), e.has("layer") && this.layer !== void 0 && !r(e.get("layer"), this.layer) && (i = !0), e.has("usePopupTemplateFieldsInfo") && this.usePopupTemplateFieldsInfo !== e.get("usePopupTemplateFieldsInfo") && (i = !0), e.has("seriesColor") && this.seriesColorChange(this.seriesColor), this.layerFieldsInfo === void 0 && (i = !0), i && this.updateFetchLayerFieldsInfo();
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.model.removeEventListener("arcgisChartsModelConfigChange", this.onModelConfigChange);
  }
  modelChange(e, i) {
    i?.removeEventListener("arcgisChartsModelConfigChange", this.onModelConfigChange), e?.addEventListener("arcgisChartsModelConfigChange", this.onModelConfigChange);
  }
  seriesColorChange(e) {
    this.activeColorMatch = e?.get(0) === void 0, this.model.colorMatch && e?.forEach((i, o) => {
      let t;
      i && ("fillSymbol" in i ? t = i.fillSymbol?.color : "lineSymbol" in i && (t = i.lineSymbol.color)), e?.get(0) !== void 0 && t !== void 0 && !r(this.model.getSeriesColor(o), t) && this.model.setSeriesColor(t, o);
    });
  }
  async updateDataFilters() {
    const e = this.model.getDataFilters(), i = e?.where, o = this.layer?.definitionExpression ?? void 0;
    r(i, o) || await this.model.setDataFilters({
      ...e,
      where: o ?? void 0
    });
  }
  async updateFetchLayerFieldsInfo(e) {
    const i = e ?? this.model.config;
    let o = this.layer;
    if (!o) {
      const t = h(i) ? i.iLayer : void 0;
      t && (o = await n(t));
    }
    o && (this.layerFieldsInfo = await c(o, this.usePopupTemplateFieldsInfo));
  }
  render() {
    let e;
    switch (this.page) {
      case a.Data:
        e = s`<arcgis-charts-config-box-plot-data .model=${this.model} .layerFieldsInfo=${this.layerFieldsInfo}></arcgis-charts-config-box-plot-data>`;
        break;
      case a.Series:
        e = s`<arcgis-charts-config-box-plot-series .model=${this.model} .activeColorMatch=${this.activeColorMatch} .popoverPlacement=${this.popoverPlacement}></arcgis-charts-config-box-plot-series>`;
        break;
      case a.Axes:
        e = s`<arcgis-charts-config-axes .model=${this.model} show-min-y-bound-option show-max-y-bound-option .calculatedMinMaxBounds=${this.calculatedMinMaxBounds}></arcgis-charts-config-axes>`;
        break;
      case a.Guides:
        e = s`<arcgis-charts-config-guides .model=${this.model} enable-y-axis-guide></arcgis-charts-config-guides>`;
        break;
      case a.Format:
        e = s`<arcgis-charts-config-format .model=${this.model}></arcgis-charts-config-format>`;
        break;
      case a.General:
        e = s`<arcgis-charts-config-general .model=${this.model}></arcgis-charts-config-general>`;
        break;
      default:
        e = "";
        break;
    }
    return e;
  }
}
l("arcgis-charts-config-box-plot", p);
export {
  p as ArcgisChartsConfigBoxPlot
};
