/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { C as v } from "./chart-model.js";
import { m as o } from "./model-setter.js";
import { W as _, a as I, b as C } from "./axis-lines-symbol.js";
import { W as L, b as T } from "./model-with-guides.js";
import { W as A, a as W, b as F } from "./generate-x-axis-title.js";
import { g as V, a as D } from "./utils.js";
import "@arcgis/toolkit/intl";
import "lodash-es";
import "luxon";
import "d3-array";
import "@arcgis/toolkit/type";
import { W as m, G as E, a as y } from "./series-types.js";
import { b8 as d, aP as b, a_ as w, bi as x, bp as M, bR as N } from "./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 "./runtime.js";
import "@arcgis/toolkit/dom";
import { M as R } from "./model-with-x-guides.js";
const G = (t) => t.axes[0].needle?.visible ?? !0, P = (t, e) => {
  e.axes[0].needle === void 0 && (e.axes[0].needle = d()), e.axes[0].needle.visible = t;
}, k = (t) => t.axes[0].needle?.symbol, O = (t, e) => {
  e.axes[0].needle === void 0 && (e.axes[0].needle = d()), e.axes[0].needle.symbol = t;
}, X = (t) => t.axes[0].needle?.startWidth, $ = (t, e) => {
  e.axes[0].needle === void 0 && (e.axes[0].needle = d()), e.axes[0].needle.startWidth = t;
}, j = (t) => t.axes[0].needle?.endWidth, q = (t, e) => {
  e.axes[0].needle === void 0 && (e.axes[0].needle = d()), e.axes[0].needle.endWidth = t;
}, B = (t) => t.axes[0].needle?.innerRadius, Q = (t, e) => {
  e.axes[0].needle === void 0 && (e.axes[0].needle = d()), e.axes[0].needle.innerRadius = t;
}, Y = (t) => t.axes[0].needle?.displayPin ?? !1, z = (t, e) => {
  e.axes[0].needle === void 0 && (e.axes[0].needle = d()), e.axes[0].needle.displayPin = t;
}, H = (t) => t.axes[0].innerLabel?.visible ?? !0, J = (t, e) => {
  e.axes[0].innerLabel === void 0 && (e.axes[0].innerLabel = b()), e.axes[0].innerLabel.visible = t;
}, K = (t) => t.axes[0].innerLabel?.content, U = (t, e) => {
  e.axes[0].innerLabel === void 0 && (e.axes[0].innerLabel = b()), t !== void 0 && (e.axes[0].innerLabel.content = t);
}, Z = (t) => t.axes[0].ticks?.visible ?? !0, ee = (t, e) => {
  e.axes[0].ticks === void 0 && (e.axes[0].ticks = {
    type: m.GaugeAxisTick
  }), e.axes[0].ticks.visible = t;
}, te = (t) => t.axes[0].labelsIncrement, ie = (t, e) => {
  e.axes[0].labelsIncrement = t;
}, se = (t) => t.axes[0].onlyShowFirstAndLastLabels ?? !1, ne = (t, e) => {
  e.axes[0].onlyShowFirstAndLastLabels = t;
}, oe = (t) => t.series[0]?.valueConversion, re = (t, e) => {
  e.series[0] !== void 0 && (e.series[0].valueConversion = t);
}, S = (t) => t.series[0]?.featureIndex, f = (t) => {
  const { featureIndex: e, config: i, layerInfo: a, commonStrings: n } = t, l = h(i), g = p(i);
  e === null ? delete i.series[0].featureIndex : i.series[0] !== void 0 && (i.series[0].featureIndex = e), c({ config: i, layerInfo: a, field: l, aggregationType: g, commonStrings: n });
}, ae = (t) => t.subType ?? E.StatisticGauge, le = (t) => {
  const { config: e, field: i, aggregationType: a } = t;
  if (a !== y.NoAggregation) {
    const n = S(e), l = u(n) ? {} : {
      outStatistics: [
        {
          statisticType: a,
          onStatisticField: i,
          outStatisticFieldName: `${a}_${i}`
        }
      ]
    };
    e.series[0].query = l;
  }
}, de = (t) => {
  const { config: e, layerInfo: i, commonStrings: a, field: n, aggregationType: l } = t;
  e.title && (e.title.content.text = V({
    config: e,
    layerInfo: i,
    commonStrings: a,
    numericFields: [n],
    aggregationType: l
  }));
}, c = (t) => {
  const { config: e, field: i, aggregationType: a } = t;
  e.series[0] === void 0 && (e.series = [x({})]);
  const n = u(e.series[0]?.featureIndex);
  let l = n ? i : `${a}_${i}`;
  n && i.startsWith(`${a}_`) && (l = i.replace(`${a}_`, "")), e.series[0].x = l, le({ config: e, field: i, aggregationType: a }), de(t);
}, p = (t) => t.series[0]?.query?.outStatistics?.[0]?.statisticType ?? y.Count, ge = (t) => {
  const { config: e, layerInfo: i, commonStrings: a, aggregationType: n } = t, l = h(e);
  c({
    config: e,
    layerInfo: i,
    commonStrings: a,
    field: l,
    aggregationType: n
  });
}, u = (t) => typeof t == "number" && t >= 0, h = (t) => u(t.series[0]?.featureIndex) ? t.series[0]?.x : t.series[0]?.query?.outStatistics?.[0]?.onStatisticField ?? "", ce = (t) => {
  const { field: e, config: i, layerInfo: a, commonStrings: n } = t, l = p(i);
  c({ config: i, layerInfo: a, commonStrings: n, field: e, aggregationType: l });
}, pe = (t) => t.innerRadius ?? 50, ue = (t, e) => {
  e.innerRadius = t;
}, he = (t) => t.startAngle ?? -90, fe = (t, e) => {
  e.startAngle = t;
}, me = (t) => t.endAngle ?? 270, ye = (t, e) => {
  e.endAngle = t;
};
function be(t) {
  return w(t);
}
var xe = Object.defineProperty, Se = Object.getOwnPropertyDescriptor, r = (t, e, i, a) => {
  for (var n = Se(e, i), l = t.length - 1, g; l >= 0; l--)
    (g = t[l]) && (n = g(e, i, n) || n);
  return n && xe(e, i, n), n;
};
class s extends v {
  constructor() {
    super(...arguments), this._chartType = m.GaugeSeries;
  }
  /**
   * Generate the proper chart title given the current config.
   */
  generateChartTitle() {
    return be(this.commonStrings);
  }
  async setup(e) {
    await this.loadConfigFromLayer(e), typeof this.resolveSetup == "function" && this.resolveSetup();
  }
  // ---------------------------------------------------------------------------------------------
  // Data Props
  // ---------------------------------------------------------------------------------------------
  /**
   * Data field used for the gauge.
   */
  get field() {
    return h(this._config);
  }
  set field(e) {
    ce({ field: e, config: this._config, layerInfo: this.layerInfo, commonStrings: this.commonStrings }), this.dispatchEvent(new CustomEvent("arcgisChartsModelDataChange"));
  }
  /**
   * Aggregation type used for the gauge.
   *
   * Must be one of the values allowed by `WebChartStatisticType`, excluding `"no_aggregation"`.
   */
  get aggregationType() {
    return p(this._config);
  }
  set aggregationType(e) {
    ge({
      aggregationType: e,
      config: this._config,
      layerInfo: this.layerInfo,
      commonStrings: this.commonStrings
    }), this.dispatchEvent(new CustomEvent("arcgisChartsModelDataChange"));
  }
  /**
   * Inner radius of the gauge.
   */
  get innerRadius() {
    return pe(this._config);
  }
  set innerRadius(e) {
    ue(e, this._config), this.dispatchEvent(new CustomEvent("arcgisChartsModelDataChange"));
  }
  /**
   * Start angle of the gauge.
   */
  get startAngle() {
    return he(this._config);
  }
  set startAngle(e) {
    fe(e, this._config), this.dispatchEvent(new CustomEvent("arcgisChartsModelDataChange"));
  }
  /**
   * End angle of the gauge.
   */
  get endAngle() {
    return me(this._config);
  }
  set endAngle(e) {
    ye(e, this._config), this.dispatchEvent(new CustomEvent("arcgisChartsModelDataChange"));
  }
  // ---------------------------------------------------------------------------------------------
  // Series Props
  // ---------------------------------------------------------------------------------------------
  /**
   * Conversion to apply to the gauge value.
   */
  get valueConversion() {
    return oe(this._config);
  }
  set valueConversion(e) {
    re(e, this._config);
  }
  /**
   * Gets the index of the feature to be rendered.
   * - For statistic gauge, this property will be ignored.
   * - For feature based gauge, if this property is not present, the first feature will be used (`featureIndex = 0`).
   */
  get featureIndex() {
    return S(this._config);
  }
  set featureIndex(e) {
    f({
      featureIndex: e,
      config: this._config,
      layerInfo: this.layerInfo,
      commonStrings: this.commonStrings
    });
  }
  removeFeatureIndex() {
    f({
      featureIndex: null,
      config: this._config,
      layerInfo: this.layerInfo,
      commonStrings: this.commonStrings
    });
  }
  /**
   * Type of gauge
   * - `featureGauge` indicates that the gauge is based on a specific feature from the layer.
   * - `statisticGauge` indicates that the gauge is based on a statistic value calculated from the layer's features.
   *
   * **Note**: When this property is not specified, it will be defaulted to `statisticGauge`.
   */
  get gaugeSubType() {
    return ae(this._config);
  }
  // ---------------------------------------------------------------------------------------------
  // Axes Props
  // ---------------------------------------------------------------------------------------------
  /**
   * Visibility of the gauge's needle.
   */
  get needleVisibility() {
    return G(this._config);
  }
  set needleVisibility(e) {
    P(e, this._config);
  }
  /**
   * Symbol of the gauge's needle.
   *
   * @example
   * ```typescript
   * gaugeModel.needleSymbol = {
   *   type: "esriSFS",
   *   color: [255, 0, 0, 255],
   * };
   * ```
   */
  get needleSymbol() {
    return k(this._config);
  }
  set needleSymbol(e) {
    O(e, this._config);
  }
  /**
   * Start width of the gauge's needle.
   */
  get needleStartWidth() {
    return X(this._config);
  }
  set needleStartWidth(e) {
    $(e, this._config);
  }
  /**
   * End width of the gauge's needle.
   */
  get needleEndWidth() {
    return j(this._config);
  }
  set needleEndWidth(e) {
    q(e, this._config);
  }
  /**
   * Inner radius of the gauge's needle.
   */
  get needleInnerRadius() {
    return B(this._config);
  }
  set needleInnerRadius(e) {
    Q(e, this._config);
  }
  /**
   * Whether to display the pin for the gauge's needle.
   */
  get needleDisplayPin() {
    return Y(this._config);
  }
  set needleDisplayPin(e) {
    z(e, this._config);
  }
  /**
   * Whether the inner label is visible.
   */
  get innerLabelVisible() {
    return H(this._config);
  }
  set innerLabelVisible(e) {
    J(e, this._config);
  }
  /**
   * Content symbol for the inner label.
   *
   * @example
   * ```typescript
   * gaugeModel.innerLabelContent = {
   *   type: "esriTS",
   *   text: "Inner label",
   * };
   * ```
   */
  get innerLabelContent() {
    return K(this._config);
  }
  set innerLabelContent(e) {
    U(e, this._config);
  }
  /**
   * Whether axis ticks are visible.
   */
  get axisTickVisibility() {
    return Z(this._config);
  }
  set axisTickVisibility(e) {
    ee(e, this._config);
  }
  /**
   * Labels increment for the gauge.
   */
  get labelsIncrement() {
    return te(this._config);
  }
  set labelsIncrement(e) {
    ie(e, this._config);
  }
  /**
   * Whether to only show the first and last axis labels.
   */
  get onlyShowFirstAndLastLabels() {
    return se(this._config);
  }
  set onlyShowFirstAndLastLabels(e) {
    ne(e, this._config);
  }
  // ---------------------------------------------------------------------------------------------
  // Protected Methods
  // ---------------------------------------------------------------------------------------------
  /** @private */
  generateDefaultConfig() {
    const e = M(this.commonStrings);
    return e.series = [x({ objectIDField: N(this.layerInfo.layer).idField })], e;
  }
}
r([
  o
], s.prototype, "field");
r([
  o
], s.prototype, "aggregationType");
r([
  o
], s.prototype, "innerRadius");
r([
  o
], s.prototype, "startAngle");
r([
  o
], s.prototype, "endAngle");
r([
  o
], s.prototype, "valueConversion");
r([
  o
], s.prototype, "featureIndex");
r([
  o
], s.prototype, "removeFeatureIndex");
r([
  o
], s.prototype, "needleVisibility");
r([
  o
], s.prototype, "needleSymbol");
r([
  o
], s.prototype, "needleStartWidth");
r([
  o
], s.prototype, "needleEndWidth");
r([
  o
], s.prototype, "needleInnerRadius");
r([
  o
], s.prototype, "needleDisplayPin");
r([
  o
], s.prototype, "innerLabelVisible");
r([
  o
], s.prototype, "innerLabelContent");
r([
  o
], s.prototype, "axisTickVisibility");
r([
  o
], s.prototype, "labelsIncrement");
r([
  o
], s.prototype, "onlyShowFirstAndLastLabels");
const ve = [
  A,
  L,
  W,
  T,
  _,
  I,
  C,
  F,
  R
];
D(s, ve);
export {
  s as GaugeModel
};
