/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import "@arcgis/toolkit/type";
import { e as B, W as c, a as F, w as C, g as k } from "./series-types.js";
import "@arcgis/toolkit/intl";
import "lodash-es";
import "luxon";
import "d3-array";
import { aR as w, c$ as D, by as j, d3 as S, bR as v, aP as M, aN as q, bI as W, b7 as $, bW as E, cn as L, bX as P, ai as O, bY as U, d7 as X, k as K, dk as H } from "./index.js";
import "@arcgis/core/core/promiseUtils.js";
import "@arcgis/core/request.js";
import "./runtime.js";
import "@arcgis/toolkit/dom";
import "@arcgis/core/Graphic.js";
import "@arcgis/core/renderers/support/jsonUtils.js";
import "@arcgis/core/symbols/support/symbolUtils.js";
import { substitute as h } from "@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/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 { s as R } from "./index4.js";
function Se(i, e, s) {
  const t = i?.axes?.[e];
  t?.title !== void 0 ? t.title.content.text = s : t !== void 0 && (t.title = M({
    text: s,
    visible: !0,
    font: q(W.AxisTitle)
  }));
}
function he(i) {
  const { config: e, layerInfo: s, commonStrings: t, numericFields: a, aggregationType: r } = i;
  let o = "";
  if (e)
    if (D(e) === B.Stacked100)
      o = t.utilsStrings.statistics.percent;
    else {
      const d = j(r, t);
      if (e.series[0]?.type === c.HeatSeries)
        o = S(s.layerFieldsInfo, e.series[0].y);
      else if (a.length === 1) {
        const l = S(s.layerFieldsInfo, a[0]), f = v(s.layer).idField;
        r === F.NoAggregation ? o = l : r === F.Count && f !== void 0 && a[0] === f ? o = t.utilsStrings.statistics.count : o = h(t.axisLabels.aggregationOfFieldName, {
          aggregation: d,
          fieldName: l
        });
      } else a.length > 1 && (r === F.NoAggregation ? o = t.axisLabels.values : o = h(t.axisLabels.aggregationOfValues, {
        aggregation: d
      }));
    }
  return o;
}
const V = (i, e, s) => i.axes?.[e] ?? $(s, i.type)[e], T = (i) => {
  const { config: e, axis: s, axisIndex: t } = i;
  e.axes !== void 0 && (e.axes[t] = s);
}, Ie = (i) => {
  const { config: e, axisIndex: s, isMax: t } = i;
  let a = Number.NaN;
  return t ? a = e.axes?.[s]?.maximum : a = e.axes?.[s]?.minimum, a ?? Number.NaN;
}, I = (i) => {
  const { config: e, value: s, axisIndex: t, isMax: a } = i, r = e?.axes?.[t];
  r !== void 0 && (a ? r.maximum = s : r.minimum = s);
}, Ne = (i) => i.axes?.[0]?.valueFormat ?? w(), ve = (i, e, s) => {
  const t = V(i, 0, e);
  if (t !== void 0 && s !== void 0) {
    const a = {
      ...t,
      valueFormat: s
    };
    T({ config: i, axis: a, axisIndex: 0 });
  }
}, Le = (i, e, s) => {
  const t = i.axes?.[e];
  t !== void 0 && (t.integerOnlyValues = s);
}, Y = (i) => {
  const e = C(i.series);
  return e === c.BarSeries || e === c.ComboLineAndBarSeries || e === c.LineSeries;
}, G = (i) => {
  const { axisIndex: e, config: s, isMultiAxis: t } = i;
  let a = !1;
  return e === 0 || e === 1 && t ? a = !0 : e === 2 && (a = Y(s)), a;
}, Oe = (i) => {
  const { axisIndex: e, func: s, config: t } = i;
  return G({ axisIndex: e, config: t, isMultiAxis: !0 }) ? s(e) : void 0;
}, N = (i, e) => {
  let s;
  const t = e.axes?.[i]?.valueFormat;
  return (i === 0 || i >= 1 && R(t)) && (s = t), s;
}, Ve = (i) => {
  const { config: e, commonStrings: s, valueFormat: t, axisIndex: a = 0 } = i, r = V(e, a, s);
  if (r !== void 0 && t !== void 0) {
    const o = {
      ...r,
      valueFormat: t
    };
    T({
      config: e,
      axis: o,
      axisIndex: a
    });
  }
}, Te = (i, e) => i.axes?.[e]?.isLogarithmic ?? !1, Be = (i) => {
  const { config: e, isLogarithmic: s, axisIndex: t } = i, a = e.axes?.[t];
  a && (a.isLogarithmic = s, I({ config: e, value: null, axisIndex: t, isMax: !0 }), I({ config: e, value: null, axisIndex: t, isMax: !1 }));
}, Ce = (i) => {
  const { config: e, scrollbar: s, axisIndex: t } = i;
  e.axes?.[t] !== void 0 && (e.axes[t].scrollbar = s);
};
async function ke(i) {
  const { config: e, layer: s, xAxisField: t, splitByField: a, layerFieldsInfo: r, aggregationFields: o, fetchNullValues: u } = i, l = r.filter((p) => p.name === a)[0]?.type, f = u !== !0 ? `${a} IS NOT NULL` : "", x = t && u !== !0 ? `${t} IS NOT NULL` : "", { where: g } = e?.dataFilters ?? {}, A = {
    where: L([g, f, x]),
    // excluding the null values from the list
    orderByFields: X(a) ? [] : [`${a} ${k.Ascending}`],
    // default sorting ascending for split-by field
    geometry: e?.dataFilters?.geometry
  }, b = s;
  let m = "";
  o.length === 0 ? m = v(b).idField : [m] = o;
  let y = await O({
    queryObject: b,
    category: e?.series[0].x ?? "",
    splitByField: a,
    queryConfig: A
  });
  if (e) {
    const p = e?.series.map((n) => K({ where: n.query?.where })?.toString() ?? "").filter((n) => n !== void 0 && n !== "");
    y = H({
      arrayA: y,
      arrayB: p,
      getKey: (n) => n === null ? null : n?.toString()
    });
  }
  return { categoriesArray: y, splitByFieldType: l, numericalField: m };
}
function we(i, e) {
  let s = e === "";
  for (const t of i)
    if (e === t.name) {
      s = !0;
      break;
    }
  return s;
}
function De(i, e) {
  const s = E(i);
  let t = e.length === 0, a = 0;
  for (const r of e) {
    for (const o of s)
      if (r === o && (a += 1), a === e.length) {
        t = !0;
        break;
      }
    if (t)
      break;
  }
  return t;
}
function je(i, e) {
  e.forEach((s) => {
    Object.getOwnPropertyNames(s.prototype).forEach((t) => {
      Object.defineProperty(
        i.prototype,
        t,
        Object.getOwnPropertyDescriptor(s.prototype, t) || /* @__PURE__ */ Object.create(null)
      );
    });
  });
}
async function Me(i) {
  const { layerInfo: e, config: s, category: t } = i, { layer: a } = e, { where: r } = s?.dataFilters ?? {}, { fetchNullValues: o } = s?.series?.[0]?.query ?? {}, u = o !== !0 ? `${t} IS NOT NULL` : "", d = {
    where: L([r, u]),
    // excluding the null values from the list
    orderByFields: [],
    geometry: s?.dataFilters?.geometry
  }, l = P(a);
  return (
    // fetch unique category values asynchronously
    (await O({ queryObject: a, category: t, queryConfig: d })).map((x) => {
      const g = String(x);
      return U({
        fieldName: t,
        fieldValueToMatch: g,
        subtypeInfo: l,
        // use the retrieved subtype information
        fieldList: e.layerFieldsInfo
        // list of field information from the layer
      }) ?? g;
    })
  );
}
function qe(i) {
  return i !== void 0 && N(0, i)?.type === c.CategoryAxisFormat && N(1, i)?.type === c.CategoryAxisFormat;
}
export {
  je as a,
  De as b,
  we as c,
  Ne as d,
  Me as e,
  ve as f,
  he as g,
  ke as h,
  qe as i,
  Le as j,
  Ie as k,
  N as l,
  Ve as m,
  Te as n,
  Be as o,
  Ce as p,
  Oe as r,
  I as s,
  Se as u
};
