/* 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 o } from "lodash-es";
import "luxon";
import "d3-array";
import "@arcgis/toolkit/type";
import "../../chunks/series-types.js";
import { bM as n, bO as h, bS as c, bT as d } 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 as m } from "../../chunks/index4.js";
import "@arcgis/toolkit/dom";
import { LitElement as g, createEvent as f } from "@arcgis/lumina";
import { css as p, html as a } from "lit";
import { C as r } from "../../chunks/interfaces.js";
const u = p`: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 C extends g {
  constructor() {
    super(...arguments), this.onModelConfigChange = async (t) => {
      const i = t?.detail.config ?? this.model.config;
      this.layer === void 0 && await this.updateFetchLayerFieldsInfo(i);
    }, this.activeColorMatch = !1, this.popoverPlacement = "leading", this.arcgisChartsConfigNoSeriesUpdate = f();
  }
  static {
    this.properties = { layerFieldsInfo: 16, activeColorMatch: 16, model: 0, timeZone: 1, popoverPlacement: 1, seriesColor: 0, calculatedDataMinMaxBounds: 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);
  }
  willUpdate(t) {
    let e = !1;
    t.has("model") && this.modelChange(this.model, t.get("model")), t.has("layer") && this.layer !== void 0 && !o(t.get("layer"), this.layer) && (e = !0), t.has("usePopupTemplateFieldsInfo") && this.usePopupTemplateFieldsInfo !== t.get("usePopupTemplateFieldsInfo") && (e = !0), t.has("seriesColor") && this.seriesColorChange(this.seriesColor), this.layerFieldsInfo === void 0 && (e = !0), e && this.updateFetchLayerFieldsInfo();
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.model.removeEventListener("arcgisChartsModelConfigChange", this.onModelConfigChange);
  }
  modelChange(t, e) {
    e?.removeEventListener("arcgisChartsModelConfigChange", this.onModelConfigChange), t?.addEventListener("arcgisChartsModelConfigChange", this.onModelConfigChange);
  }
  seriesColorChange(t) {
    this.activeColorMatch = t?.get(0)?.markerSymbol === void 0, this.model.colorMatch && t?.forEach((e, i) => {
      e && t?.get(0) !== void 0 && ("lineSymbol" in e && (e.lineSymbol?.color !== void 0 && !o(this.model.getSeriesColor(i), e.lineSymbol.color) && this.model.setSeriesColor(e.lineSymbol.color, i), e.lineSymbol?.style !== void 0 && !o(this.model.getSeriesLineStyle(i), e.lineSymbol.style) && this.model.setSeriesLineStyle(e.lineSymbol.style, i), e.lineSymbol?.width !== void 0 && !o(this.model.getSeriesLineWidth(i), e.lineSymbol.width) && this.model.setSeriesLineWidth(e.lineSymbol.width, i)), "markerSymbol" in e && (e.markerSymbol?.color !== void 0 && !o(this.model.getSeriesMarkerColor(i), e.markerSymbol?.color) && this.model.setSeriesMarkerColor(e.markerSymbol?.color, i), e.markerSymbol?.style !== void 0 && !o(this.model.getSeriesMarkerStyle(i), e.markerSymbol?.style) && this.model.setSeriesMarkerStyle(e.markerSymbol?.style, i), e.markerSymbol?.size !== void 0 && this.model.getSeriesMarkerSize(i) !== e.markerSymbol?.size && this.model.setSeriesMarkerSize(e.markerSymbol?.size, i)));
    });
  }
  async updateFetchLayerFieldsInfo(t) {
    const e = t ?? this.model.config;
    let i = this.layer;
    if (!i) {
      const s = m(e) ? e.iLayer : void 0;
      s && (i = await n(s));
    }
    i && (this.layerFieldsInfo = await h(i, this.usePopupTemplateFieldsInfo));
  }
  render() {
    const t = this.layerFieldsInfo?.find((s) => s.name === this.model.xAxisField), e = t !== void 0 && (c(t) || d(t));
    let i;
    switch (this.page) {
      case r.Data:
        i = a`<arcgis-charts-config-line-chart-data .model=${this.model} .resetTimeInterval=${this.model.resetTimeInterval} .layerFieldsInfo=${this.layerFieldsInfo}></arcgis-charts-config-line-chart-data>`;
        break;
      case r.Series:
        i = a`<arcgis-charts-config-line-chart-series .model=${this.model} .activeColorMatch=${this.activeColorMatch} .popoverPlacement=${this.popoverPlacement}></arcgis-charts-config-line-chart-series>`;
        break;
      case r.Axes:
        i = a`<arcgis-charts-config-axes .model=${this.model} show-min-y-bound-option show-max-y-bound-option show-enable-x-log-option show-enable-y-log-option .calculatedMinMaxBounds=${this.calculatedMinMaxBounds} .calculatedDataMinMaxBounds=${this.calculatedDataMinMaxBounds}></arcgis-charts-config-axes>`;
        break;
      case r.Guides:
        i = a`<arcgis-charts-config-guides .model=${this.model} .timeZone=${this.timeZone} .calculatedMinMaxBounds=${this.calculatedMinMaxBounds} .enableXAxisGuide=${e} enable-y-axis-guide></arcgis-charts-config-guides>`;
        break;
      case r.Format:
        i = a`<arcgis-charts-config-format .model=${this.model}></arcgis-charts-config-format>`;
        break;
      case r.General:
        i = a`<arcgis-charts-config-general .model=${this.model}></arcgis-charts-config-general>`;
        break;
      default:
        i = "";
        break;
    }
    return i;
  }
}
l("arcgis-charts-config-line-chart", C);
export {
  C as ArcgisChartsConfigLineChart
};
