import { Q as nt, U as C, W as G, Y as dt, e as X, a as F, Z as N, $ as I, a0 as mt, a1 as H, a2 as et, a3 as ut, a4 as st, a5 as ft, t as $, a6 as _t, E as lt, z as xt, R as ht, L as it, T as at, m as ot } from "./am-chart.H2jnOzFc.js";
import { C as rt } from "./ColumnSeries.DGazbfza.js";
class j extends nt {
  constructor() {
    super(...arguments), this._frequency = 1, this._m = 0, this._dates = [];
  }
  _afterNew() {
    this.valueFields.push("date"), this.addTag("gapless"), super._afterNew();
  }
  _getDates() {
    return this._customDates ? this._customDates : this._dates;
  }
  _updateDates(t, e) {
    if (!e.get("ignoreMinMax")) {
      const a = this._getDates(), o = C(a, (n) => G(n, t));
      o.found || dt(a, o.index, t);
    }
  }
  _updateAllDates() {
    if (!this._customDates) {
      const t = this._dates;
      t.length = 0, X(this.series, (r) => {
        let l = "valueX";
        r.get("yAxis") == this && (l = "valueY"), X(r.dataItems, (h) => {
          let c = h.get(l);
          F(c) && h.open && this._updateDates(h.open[l], r);
        });
      });
      const e = this.get("extraMax", 0), a = this.get("extraMin", 0);
      let o = t.length;
      const n = this.getPrivate("baseInterval"), i = n.count, s = n.timeUnit;
      if (e > 0) {
        const r = o * e;
        let l = t[o - 1];
        if (F(l))
          for (let h = o - 1; h < o + r; h++)
            l += N(s, i * this._getM(s)), l = I(l, s, i, this._root), t.push(l);
      }
      if (a > 0) {
        const r = o * a;
        let l = t[0];
        if (F(l))
          for (let h = 0; h < r; h++)
            l -= N(s, i), l = I(l, s, i, this._root), t.unshift(l);
      }
    }
  }
  /**
   * Convers value to a relative position on axis.
   *
   * @param   value  Value
   * @return         Relative position
   */
  valueToPosition(t) {
    const e = this._getDates(), a = this.get("startLocation", 0), o = this.get("endLocation", 1), n = e.length - a - (1 - o), i = C(e, (r) => G(r, t));
    let s = i.index;
    if (i.found)
      return (s - a) / n;
    {
      s > 0 && (s -= 1);
      let r = e[s];
      const l = e[s + 1];
      if (l) {
        let c = l;
        Math.abs(c - t) < Math.abs(r - t) && (r = c, s++);
      }
      let h = t - r;
      return (s - a) / n + h / this._baseDuration / n;
    }
  }
  /**
   * Converts numeric value from axis scale to index.
   *
   * @param  value  Value
   * @return        Index
   */
  valueToIndex(t) {
    const e = this._getDates(), a = C(e, (n) => G(n, t));
    let o = a.index;
    return a.found || o > 0 && (o -= 1), o;
  }
  /**
   * Converts a relative position to a corresponding numeric value from axis
   * scale.
   *
   * @param   position  Relative position
   * @return            Value
   */
  positionToValue(t) {
    const e = this.get("startLocation", 0), a = this.get("endLocation", 1), o = this._getDates();
    let n = Math.round(o.length - e - (1 - a)), i = t * n, s = Math.floor(i);
    return s < 0 && (s = 0), s > n - 1 && (s = n - 1), o[s] + (i - s + e) * this._baseDuration;
  }
  _fixZoomFactor() {
    this.setPrivateRaw("maxZoomFactor", this._getDates().length - this.get("startLocation", 0) - (1 - this.get("endLocation", 1)));
  }
  /**
   * Zooms the axis to specific `start` and `end` dates.
   *
   * Optional `duration` specifies duration of zoom animation in milliseconds.
   *
   * @param  start     Start Date
   * @param  end       End Date
   * @param  duration  Duration in milliseconds
   */
  zoomToDates(t, e, a) {
    const o = this._getDates(), n = o.length;
    let i = C(o, (l) => G(l, t.getTime())), s = o[Math.min(i.index, n - 1)];
    i = C(o, (l) => G(l, e.getTime()));
    let r = o[i.index];
    i.index >= n && (r = o[n - 1] + this._baseDuration), this.zoomToValues(s, r, a);
  }
  /**
   * Zooms the axis to specific `start` and `end` values.
   *
   * Optional `duration` specifies duration of zoom animation in milliseconds.
   *
   * @param  start     Start value
   * @param  end       End value
   * @param  duration  Duration in milliseconds
   */
  zoomToValues(t, e, a) {
    const o = this.getPrivate("min", 0), n = this.getPrivate("max", 0);
    t = $(t, o, n), e = $(e, o, n), this.zoom(this.valueToPosition(t), this.valueToPosition(e), a);
  }
  _prepareAxisItems() {
    let t = this.getPrivate("selectionMin", 0), e = this.getPrivate("selectionMax", 0);
    if (F(t) && F(e)) {
      this._seriesValuesDirty && (this._seriesValuesDirty = !1, this._updateAllDates());
      const a = this._root, o = a.utc, n = a.timezone, i = this._getDates(), s = this.get("renderer"), r = i.length, l = this._baseDuration;
      let h = this.valueToIndex(t);
      h > 0 && h--;
      let c = this.valueToIndex(e);
      c < r - 1 && c++;
      let g = s.axisLength() / Math.max(s.get("minGridDistance"), 1 / Number.MAX_SAFE_INTEGER), u = Math.min(r, Math.ceil((c - h) / g));
      u = Math.max(1, u), h = Math.floor(h / u) * u, this._frequency = u, X(this.dataItems, (w) => {
        this._toggleDataItem(w, !1);
      }), X(this.minorDataItems, (w) => {
        this._toggleDataItem(w, !1);
      });
      let x = e - t - ((e - t) / l - (c - h)) * l, d = mt(0, x, g, this.get("gridIntervals"));
      const f = this.getPrivate("baseInterval");
      let m = H(d);
      m < l && (d = Object.assign({}, f), m = H(d)), this.setPrivateRaw("gridInterval", d), this._intervalDuration = m;
      const D = d.timeUnit, _ = this.get("dateFormats");
      let Y = Date.now();
      i[0] && (Y = i[0]);
      let b = I(this.getPrivate("selectionMin", 0), D, d.count, a, Y);
      const L = s.get("minorLabelsEnabled"), T = s.get("minorGridEnabled", L);
      let v, U = 0, E;
      T && (v = this._getMinorInterval(d), U = H(v));
      let A = this._getIndexes(b, this.getPrivate("selectionMax", b) + m, d, this.getPrivate("min", b));
      if (A.length > 0) {
        let w = 0;
        this._m = 0;
        let q = b - m * 10;
        const K = _t(D);
        if (v) {
          let z = i[A[0]];
          this._addMinorGrid(z - m, z, U, v);
        }
        let ct = s.axisLength() / s.gridCount() * 0.5;
        X(A, (z) => {
          var Z;
          let p;
          this.dataItems.length < w + 1 ? (p = new et(this, void 0, {}), this._dataItems.push(p), this.processDataItem(p)) : p = this.dataItems[w];
          let y = i[z], gt = new Date(y), S = y;
          w < A.length - 1 ? S = i[A[w + 1]] : S += m, p.setRaw("value", y), p.setRaw("endValue", S), p.setRaw("index", w), p.setRaw("labelEndValue", void 0);
          let tt = _[D];
          K && this.get("markUnitChange") && F(q) && D != "year" && ut(y, q, K, o, n) && (tt = this.get("periodChangeDateFormats")[D]), this._createAssets(p, []);
          const k = p.get("label");
          k && k.set("text", a.dateFormatter.format(gt, tt)), this._toggleDataItem(p, !0);
          let B = d.count;
          if (D == "week" && p.setRaw("labelEndValue", y), T) {
            let M = d.timeUnit;
            if (M == "week" && (M = "day"), B > 1 || d.timeUnit == "week") {
              let P = I(y, M, 1, a) + N(M, this._getM(M)), O = this.valueToIndex(P);
              if (P = i[O], P == y) {
                let V = i[O + 1];
                V ? P = V : P += U;
              }
              p.setRaw("labelEndValue", P);
            }
            B = 1;
          }
          if (this._prepareDataItem(p, B), k && E && s.getPrivate("letter") == "X") {
            let M = E.get("label");
            if (M) {
              let P = k.x(), O = M.x();
              if (P - O < ct) {
                let V = this._pickWorse(E, p, d);
                V && ((Z = V.get("label")) === null || Z === void 0 || Z.setPrivate("visible", !1));
              }
            }
          }
          v && this._addMinorGrid(y, S, U, v), w++, k && k.getPrivate("visible") && (E = p), q = y;
        });
      }
      X(this.series, (w) => {
        w.inited && w._markDirtyAxes();
      });
    }
    this._updateGhost();
  }
  _pickWorse(t, e, a) {
    const o = a.timeUnit, n = t.get("value", 0), i = e.get("value", 0);
    return o == "hour" && new Date(n).getDate() != new Date(i).getDate() ? t : e;
  }
  _addMinorGrid(t, e, a, o) {
    const n = this.get("minorDateFormats", this.get("dateFormats")), i = o.timeUnit;
    let s = t + N(i, this._getM(i));
    s = I(s, i, 1, this._root);
    let r = e - a * 0.5, l = this._getIndexes(s, r, o, s);
    const h = this._getDates();
    X(l, (c) => {
      let g;
      this.minorDataItems.length < this._m + 1 ? (g = new et(this, void 0, {}), this.minorDataItems.push(g), this.processDataItem(g)) : g = this.minorDataItems[this._m], s = h[c], g.setRaw("value", s), g.setRaw("endValue", s + a), g.setRaw("index", c), this._createAssets(g, ["minor"], !0);
      const u = g.get("label");
      if (u)
        if (this.get("renderer").get("minorLabelsEnabled")) {
          let x = new Date(s), d = n[i];
          u.set("text", this._root.dateFormatter.format(x, d));
        } else
          u.setPrivate("visible", !1);
      this._toggleDataItem(g, !0), this._prepareDataItem(g, 1), this._m++;
    });
  }
  _getIndexes(t, e, a, o) {
    const n = [], i = a.timeUnit, s = a.count, r = this._getM(i), l = this.getPrivate("baseInterval"), h = this._root, c = this._getDates();
    let g = s - 1, u = -1 / 0, x = N(i, r), d = N(i, s * r), f = t;
    for (i == "day" && (t = o); t <= e; ) {
      t = I(t, i, s, h);
      let m = this.valueToIndex(t), D = c[m];
      if (i == "day" && l.timeUnit == "day")
        this._hasDate(t) && g++, g == s && (t >= f - d * 2 && st(n, m), g = 0), t += x, t = I(t, i, 1, h);
      else {
        if (D < t) {
          for (let _ = m, Y = c.length; _ < Y; _++)
            if (D = c[_], D >= t) {
              m = _;
              break;
            }
        }
        st(n, m), t += d, t = I(t, i, s, h);
      }
      if (t == u && (t += d + x, t = I(t, i, s, h)), t == u)
        break;
      u = t;
    }
    return n;
  }
  _hasDate(t) {
    return C(this._getDates(), (a) => ft(a, t)).found;
  }
  _nextTime(t, e, a) {
    let o = $(this.valueToIndex(t) + e, 0, this._dates.length - 1);
    return this._dates[o];
  }
}
j.className = "GaplessDateAxis";
j.classNames = nt.classNames.concat([j.className]);
class Q extends lt {
  _beforeChanged() {
    super._beforeChanged();
    const t = this.get("sprite");
    if (this.isDirty("sprite") && t && (t.setAll({ position: "absolute", role: "figure" }), this._disposers.push(t)), this.isDirty("location")) {
      const e = t.dataItem;
      this.axis && t && e && this.axis._prepareDataItem(e);
    }
  }
  _dispose() {
    const t = this.axis;
    t && xt(t._bullets, (e, a) => {
      a.uid == this.uid && delete t._bullets[e];
    }), super._dispose();
  }
}
Q.className = "AxisBullet";
Q.classNames = lt.classNames.concat([Q.className]);
class R extends ht {
  _beforeChanged() {
    super._beforeChanged(), (this.isDirty("lowX0") || this.isDirty("lowY0") || this.isDirty("lowX1") || this.isDirty("lowY1") || this.isDirty("highX0") || this.isDirty("highX1") || this.isDirty("highY0") || this.isDirty("highY1")) && (this._clear = !0);
  }
  _draw() {
    super._draw();
    const t = this._display;
    t.moveTo(this.get("lowX0", 0), this.get("lowY0", 0)), t.lineTo(this.get("lowX1", 0), this.get("lowY1", 0)), t.moveTo(this.get("highX0", 0), this.get("highY0", 0)), t.lineTo(this.get("highX1", 0), this.get("highY1", 0));
  }
}
R.className = "Candlestick";
R.classNames = ht.classNames.concat([R.className]);
class J extends rt {
  constructor() {
    super(...arguments), this.columns = this.addDisposer(new it(at.new({
      themeTags: ["autocolor"]
    }), () => R._new(this._root, {
      themeTags: ot(this.columns.template.get("themeTags", []), ["candlestick", "series", "column"])
    }, [this.columns.template])));
  }
  /**
   * @ignore
   */
  makeColumn(t, e) {
    const a = e.make();
    return this.get("turboMode") ? a.virtualParent = this.chart : this.mainContainer.children.push(a), a._setDataItem(t), e.push(a), a;
  }
  _updateGraphics(t, e, a) {
    super._updateGraphics(t, e, a);
    const o = this.getRaw("xAxis"), n = this.getRaw("yAxis");
    let i = this.get("vcy", 1), s = this.get("vcx", 1), r, l, h, c, g, u, x, d, f = this.get("locationX", t.get("locationX", 0.5)), m = this.get("locationY", t.get("locationY", 0.5)), D = this.get("openLocationX", t.get("openLocationX", f)), _ = this.get("openLocationY", t.get("openLocationY", m)), Y;
    if (a == 0) {
      let b = n.getDataItemPositionY(t, this._yOpenField, 1, i), L = n.getDataItemPositionY(t, this._yField, 1, i);
      c = n.getDataItemPositionY(t, this._yLowField, 1, i), d = n.getDataItemPositionY(t, this._yHighField, 1, i), x = Math.max(b, L), h = Math.min(b, L);
      let T = this._aLocationX0 + D - 0.5, v = this._aLocationX1 + f - 0.5;
      r = o.getDataItemPositionX(t, this._xField, T + (v - T) / 2, s), l = r, g = r, u = r, Y = "vertical";
    } else {
      let b = o.getDataItemPositionX(t, this._xOpenField, 1, s), L = o.getDataItemPositionX(t, this._xField, 1, s);
      l = o.getDataItemPositionX(t, this._xLowField, 1, s), u = o.getDataItemPositionX(t, this._xHighField, 1, s), g = Math.max(b, L), r = Math.min(b, L);
      let T = this._aLocationY0 + _ - 0.5, v = this._aLocationY1 + m - 0.5;
      h = n.getDataItemPositionY(t, this._yField, T + (v - T) / 2, i), c = h, x = h, d = h, Y = "horizontal";
    }
    this._updateCandleGraphics(t, r, l, h, c, g, u, x, d, Y);
  }
  _updateCandleGraphics(t, e, a, o, n, i, s, r, l, h) {
    let c = t.get("graphics");
    if (c) {
      let g = this.getPoint(e, o), u = this.getPoint(a, n), x = this.getPoint(i, r), d = this.getPoint(s, l);
      if (this.get("turboMode")) {
        const f = this.allColumnsData[this.allColumnsData.length - 1];
        f.lowX0 = g.x, f.lowY0 = g.y, f.lowX1 = u.x, f.lowY1 = u.y, f.highX0 = x.x, f.highY0 = x.y, f.highX1 = d.x, f.highY1 = d.y;
      } else {
        let f = c.x(), m = c.y();
        c.set("lowX0", g.x - f), c.set("lowY0", g.y - m), c.set("lowX1", u.x - f), c.set("lowY1", u.y - m), c.set("highX0", x.x - f), c.set("highY0", x.y - m), c.set("highX1", d.x - f), c.set("highY1", d.y - m), c.set("orientation", h);
        let D = t.get("rangeGraphics");
        D && X(D, (_) => {
          _.set("lowX0", g.x - f), _.set("lowY0", g.y - m), _.set("lowX1", u.x - f), _.set("lowY1", u.y - m), _.set("highX0", x.x - f), _.set("highY0", x.y - m), _.set("highX1", d.x - f), _.set("highY1", d.y - m), _.set("orientation", h);
        });
      }
    }
  }
  _afterColumnsDraw() {
    this.get("turboMode") && this.allColumns.set("draw", (t) => {
      t.clear(), X(this.allColumnsData, (e) => {
        const a = e.width, o = e.height, n = e.x, i = e.y, s = e.stroke, r = e.fill, l = e.strokeWidth, h = e.strokeOpacity, c = e.fillOpacity, g = e.lowX0, u = e.lowY0, x = e.lowX1, d = e.lowY1, f = e.highX0, m = e.highY0, D = e.highX1, _ = e.highY1;
        t.beginFill(r, c), t.beginPath(), t.lineStyle(l, s, h), t.drawRect(n, i, a, o), t.moveTo(g, u), t.lineTo(x, d), t.moveTo(f, m), t.lineTo(D, _), t.endStroke(), t.endFill();
      });
    });
  }
  _processAxisRange(t) {
    super._processAxisRange(t), t.columns = new it(at.new({}), () => R._new(this._root, {
      themeTags: ot(t.columns.template.get("themeTags", []), ["candlestick", "series", "column"])
    }, [this.columns.template, t.columns.template]));
  }
}
J.className = "CandlestickSeries";
J.classNames = rt.classNames.concat([J.className]);
export {
  Q as A,
  R as C,
  j as G,
  J as a
};
