/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { s as y, u as v, j as X, a as O } from "./utils.js";
import { substitute as Y } from "@arcgis/core/intl.js";
import { isEmpty as x, isEqual as D } from "lodash-es";
import "@arcgis/toolkit/intl";
import "luxon";
import "d3-array";
import "@arcgis/toolkit/type";
import { W as w } from "./series-types.js";
import { b3 as z, b4 as c, d3 as p, _ as T, bU as k, bq as E } from "./index.js";
import "@arcgis/core/Graphic.js";
import "@arcgis/core/renderers/support/jsonUtils.js";
import "@arcgis/core/symbols/support/symbolUtils.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";
import { g as V } from "./series-length.js";
import { g as b } from "./utils2.js";
import { C as U } from "./chart-model.js";
import { M as j, a as B, W as G, b as q } from "./model-with-tooltips.js";
import { W as N } from "./data-labels-symbol.js";
import { W as H, a as J, b as K } from "./axis-lines-symbol.js";
import { W as Q, b as R } from "./model-with-guides.js";
import { W as Z, a as $, b as ee } from "./generate-x-axis-title.js";
import { m as d } from "./model-setter.js";
import { M as te, a as ie } from "./model-with-y-guides.js";
import { M as se } from "./model-with-x-guides.js";
const F = (t) => {
  y({ config: t, value: null, axisIndex: 0, isMax: !1 }), y({ config: t, value: null, axisIndex: 0, isMax: !0 }), y({ config: t, value: null, axisIndex: 1, isMax: !1 }), y({ config: t, value: null, axisIndex: 1, isMax: !0 });
}, L = (t) => {
  const { name: e, axisIndex: i, config: s, layerInfo: r } = t, { layerFieldsInfo: o } = r, n = o.find((h) => h.name === e), a = n !== void 0 && k(n);
  X(s, i, a);
};
function I(t, e, i) {
  const s = g(t, e, i), r = V(t), o = T(t);
  return s === r || o;
}
function M(t, e) {
  const { layerFieldsInfo: i } = e, s = p(i, u(t)), r = b(1, t), o = T(t);
  return s === r || o;
}
function _(t, e) {
  const { layerFieldsInfo: i } = e, s = f(t), r = p(i, s), o = b(0, t), n = T(t);
  return r === o || n;
}
function g(t, e, i) {
  const s = f(t), r = u(t), { layerFieldsInfo: o } = e, n = p(o, s), a = p(o, r);
  return Y(i.titleLabels.xAndY, { x: n, y: a });
}
const C = (t) => {
  const { x: e, y: i, config: s, layerInfo: r, updateChartTitle: o, updateXAxisTitle: n, updateYAxisTitle: a, commonStrings: h } = t, { layerFieldsInfo: A } = r, W = p(A, e), P = p(A, i);
  !x(e) && n && v(s, 0, W), !x(i) && a && v(s, 1, P), !x(e) && !x(i) && s.title && o && (s.title.content.text = g(s, r, h));
}, f = (t) => t.series[0]?.x ?? "", u = (t) => t.series[0]?.y ?? "", re = (t) => {
  const { fieldName: e, config: i, layerInfo: s, commonStrings: r } = t, o = I(i, s, r), n = _(i, s), a = M(i, s);
  F(i), i.series[0] && (i.series[0].x = e), C({
    x: e,
    y: u(i),
    config: i,
    layerInfo: s,
    updateChartTitle: o,
    commonStrings: r,
    updateXAxisTitle: n,
    updateYAxisTitle: a
  }), L({
    name: e,
    axisIndex: 0,
    config: i,
    layerInfo: s
  });
}, oe = (t) => {
  const { fieldName: e, config: i, layerInfo: s, commonStrings: r } = t, o = I(i, s, r), n = _(i, s), a = M(i, s);
  F(i), i.series[0] && (i.series[0].y = e), C({
    x: f(i),
    y: e,
    config: i,
    layerInfo: s,
    commonStrings: r,
    updateChartTitle: o,
    updateXAxisTitle: n,
    updateYAxisTitle: a
  }), L({
    name: e,
    axisIndex: 1,
    config: i,
    layerInfo: s
  });
}, ne = (t) => {
  const e = {};
  return t.series[0]?.markerSymbol ?? e;
}, ae = (t, e) => {
  e.series[0] && (e.series[0].markerSymbol = t);
}, le = (t) => (t.series[0]?.overlays?.trendLine?.visible ?? !0) && (t.series[0]?.overlays?.trendLine?.created ?? !1), de = (t) => {
  const e = {};
  return t.series[0]?.overlays?.trendLine?.symbol ?? e;
}, me = (t, e) => {
  e.series[0].overlays ??= c(), e.series[0].overlays.trendLine ??= c().trendLine, e.series[0].overlays.trendLine.symbol = t;
}, pe = (t, e) => {
  e.series[0].overlays ??= c(), e.series[0].overlays.trendLine ??= c().trendLine, e.series[0].overlays.trendLine.visible = t;
}, ce = (t, e) => {
  !(e.series[0]?.overlays?.trendLine?.created ?? !1) && t && (e.series[0].overlays ??= c(), e.series[0].overlays.trendLine ??= c().trendLine, e.series[0].overlays.trendLine.created = t), pe(t, e);
}, S = (t) => t.series[0]?.sizePolicy ?? z(), ye = (t, e) => {
  e.series[0] && (t !== void 0 && t.field?.trim() !== "" ? e.series[0].sizePolicy = { ...e.series[0].sizePolicy, ...t } : e.series[0].sizePolicy = void 0);
}, xe = (t) => t?.series?.[0]?.overlays, fe = (t, e) => {
  e?.series[0] !== void 0 && (e.series[0].overlays = t);
}, ue = (t) => t.series.find((e) => e.additionalTooltipFields !== void 0)?.additionalTooltipFields ?? [], he = (t, e) => {
  e.series.forEach((i) => {
    Array.isArray(t) ? i.additionalTooltipFields = t : typeof t == "string" ? i.additionalTooltipFields = t.trim() === "" ? [] : [t] : i.additionalTooltipFields = [];
  });
};
var Te = Object.defineProperty, ge = Object.getOwnPropertyDescriptor, m = (t, e, i, s) => {
  for (var r = ge(e, i), o = t.length - 1, n; o >= 0; o--)
    (n = t[o]) && (r = n(e, i, r) || r);
  return r && Te(e, i, r), r;
};
class l extends U {
  constructor() {
    super(...arguments), this._chartType = w.ScatterSeries;
  }
  async setup(e) {
    await this.loadConfigFromLayer(e), typeof this.resolveSetup == "function" && this.resolveSetup();
  }
  // ---------------------------------------------------------------------------------------------
  // #region Data Props
  // ---------------------------------------------------------------------------------------------
  /**
   * X-axis field.
   */
  get xAxisField() {
    return f(this._config);
  }
  set xAxisField(e) {
    re({ fieldName: e, config: this._config, layerInfo: this.layerInfo, commonStrings: this.commonStrings }), this.dispatchEvent(new CustomEvent("arcgisChartsModelDataChange"));
  }
  /**
   * Y-axis field.
   */
  get yAxisField() {
    return u(this._config);
  }
  set yAxisField(e) {
    oe({ fieldName: e, config: this._config, layerInfo: this.layerInfo, commonStrings: this.commonStrings }), this.dispatchEvent(new CustomEvent("arcgisChartsModelDataChange"));
  }
  /**
   * Whether the linear trend line is shown.
   */
  get showLinearTrend() {
    return le(this._config);
  }
  set showLinearTrend(e) {
    ce(e, this._config);
  }
  /**
   * Line symbol for the linear trend line.
   */
  get linearTrendSymbol() {
    return de(this._config);
  }
  set linearTrendSymbol(e) {
    me(e, this._config);
  }
  /**
   * Marker symbol used for the scatterplot points when using a fixed symbol (i.e. no size policy is set).
   */
  get fixedMarkerSymbol() {
    return ne(this._config);
  }
  set fixedMarkerSymbol(e) {
    ae(e, this._config);
  }
  /**
   * Size policy for the scatterplot points. This is used to scale the size of the marker symbol based on a given field.
   */
  get sizePolicy() {
    return S(this._config);
  }
  set sizePolicy(e) {
    const i = S(this._config);
    D(i, e) || ye(e, this._config);
  }
  /**
   * Trendline overlay for the scatterplot.
   */
  get seriesOverlays() {
    return xe(this._config);
  }
  set seriesOverlays(e) {
    e !== void 0 && fe(e, this._config);
  }
  /**
   * Add an additional field to display for scatterplot tooltips.
   *
   * **Note**: Only numeric fields are supported.
   */
  get additionalTooltipField() {
    return ue(this._config);
  }
  set additionalTooltipField(e) {
    he(e, this._config);
  }
  // ---------------------------------------------------------------------------------------------
  // #region General Methods
  // ---------------------------------------------------------------------------------------------
  /**
   * Generate the proper chart title given the current config.
   */
  generateChartTitle() {
    return g(this._config, this.layerInfo, this.commonStrings);
  }
  /**
   * Generate the proper y-axis title given the current config.
   */
  generateYAxisTitle() {
    const e = this.yAxisField;
    return p(this.layerInfo.layerFieldsInfo, e);
  }
  // ---------------------------------------------------------------------------------------------
  // #region Protected methods
  // ---------------------------------------------------------------------------------------------
  /** @private */
  generateDefaultConfig() {
    return E(this.commonStrings);
  }
}
m([
  d
], l.prototype, "xAxisField");
m([
  d
], l.prototype, "yAxisField");
m([
  d
], l.prototype, "showLinearTrend");
m([
  d
], l.prototype, "linearTrendSymbol");
m([
  d
], l.prototype, "fixedMarkerSymbol");
m([
  d
], l.prototype, "sizePolicy");
m([
  d
], l.prototype, "seriesOverlays");
m([
  d
], l.prototype, "additionalTooltipField");
const Ae = [
  te,
  j,
  B,
  G,
  q,
  N,
  se,
  ie,
  Z,
  Q,
  $,
  R,
  H,
  J,
  K,
  ee
];
O(l, Ae);
export {
  l as ScatterplotModel
};
