import { X as B, e as L, v as j, P as R, i as E, a as Y, _ as U } from "./am-chart.H2jnOzFc.js";
class M extends B {
  constructor() {
    super(...arguments), this._ph = 0, this._pw = 0, this._columnsUpdated = !1;
  }
  _makeGraphics(t, s) {
    return this.makeColumn(s, t);
  }
  _makeFieldNames() {
    super._makeFieldNames();
    const t = this.get("xAxis"), s = this.get("yAxis"), n = "CategoryAxis", i = "ValueAxis";
    t.isType(n) && (this.get("openCategoryXField") || (this._xOpenField = this._xField)), t.isType(i) && (this.get("openValueXField") || (this._xOpenField = this._xField)), s.isType(n) && (this.get("openCategoryYField") || (this._yOpenField = this._yField)), s.isType(i) && (this.get("openValueYField") || (this._yOpenField = this._yField));
  }
  _prepareChildren() {
    super._prepareChildren();
    const t = this.get("xAxis"), s = this.get("yAxis"), n = this.dataItems.length, i = Math.max(0, this.startIndex() - 2), e = Math.min(this.endIndex() + 2, n - 1);
    if (t.inited && s.inited)
      for (let o = i; o <= e; o++) {
        let a = this.dataItems[o];
        this._createGraphics(a);
      }
  }
  _updateChildren() {
    const t = this.chart;
    t && (this._ph = t.plotContainer.height(), this._pw = t.plotContainer.width());
    const s = this.get("xAxis"), n = this.get("yAxis"), i = this.get("baseAxis"), e = this.columns.template;
    this.isDirty("fill") && e.get("fill") == null && e.set("fill", this.get("fill")), this.isDirty("fillPattern") && e.get("fillPattern") == null && e.set("fillPattern", this.get("fillPattern")), this.isDirty("stroke") && e.get("stroke") == null && e.set("stroke", this.get("stroke"));
    let o = 0, a = 0, v = 0;
    i && L(i.series, (r) => {
      if (r instanceof M) {
        const h = r.get("stacked");
        h && v == 0 && a++, !h && r.get("clustered") && a++;
      }
      r === this && (o = a - 1), v++;
    }), this.get("clustered") || (o = 0, a = 1), a === 0 && (a = 1, o = 0);
    const m = "cellStartLocation", D = "cellEndLocation", g = this._xRenderer.get(m, 0), p = this._xRenderer.get(D, 1), f = this._yRenderer.get(m, 0), k = this._yRenderer.get(D, 1);
    if (this._aLocationX0 = g + o / a * (p - g), this._aLocationX1 = g + (o + 1) / a * (p - g), this._aLocationY0 = f + o / a * (k - f), this._aLocationY1 = f + (o + 1) / a * (k - f), s.inited && n.inited) {
      if (this._axesDirty || this._valuesDirty || this._stackDirty || this.isDirty("vcx") || this.isDirty("vcy") || this._sizeDirty) {
        const r = this.dataItems.length;
        let h = Math.max(0, this.startIndex() - 2), X = Math.min(this.endIndex() + 2, r - 1);
        for (let l = 0; l < h; l++)
          this._toggleColumn(this.dataItems[l], !1);
        let C = this.dataItems[h];
        for (let l = h; l <= X; l++) {
          let P = this.dataItems[l];
          if (P.get("valueX") != null && P.get("valueY") != null) {
            if (C = P, l > 0 && h > 0)
              for (let w = l - 1; w >= 0; w--) {
                let G = this.dataItems[w];
                if (G.get("valueX") != null && G.get("valueY") != null) {
                  C = G;
                  break;
                }
              }
            break;
          } else
            this._toggleColumn(P, !1);
        }
        this._beforeColumnsDraw();
        let d = 0;
        n.isType("CategoryAxis") && s.isType("CategoryAxis") ? d = 2 : s === i ? d = 0 : n === i && (d = 1);
        for (let l = h; l <= X; l++) {
          let P = this.dataItems[l];
          this._updateGraphics(P, C, d), P.get("valueX") != null && P.get("valueY") != null && (C = P);
        }
        this._afterColumnsDraw();
        for (let l = X + 1; l < r; l++)
          this._toggleColumn(this.dataItems[l], !1);
        this._columnsUpdated = !0;
      }
    } else
      this._skipped = !0;
    this.getPrivate("doNotUpdateLegend") || this.updateLegendMarker(this.get("tooltipDataItem")), super._updateChildren();
  }
  _afterChanged() {
    super._afterChanged(), this._columnsUpdated = !1;
  }
  _beforeColumnsDraw() {
  }
  _afterColumnsDraw() {
  }
  _createGraphics(t) {
    let s = t.get("graphics");
    if (!s) {
      s = this._makeGraphics(this.columns, t), t.set("graphics", s), s._setDataItem(t);
      const n = t.get("legendDataItem");
      if (n) {
        const e = n.get("markerRectangle");
        if (e) {
          const o = e.states.lookup("default");
          L(j, (a) => {
            const v = s.get(a, this.get(a));
            e.set(a, v), o.set(a, v);
          });
        }
      }
      let i = t.get("rangeGraphics");
      i && L(i, (e) => {
        e.dispose();
      }), i = [], t.setRaw("rangeGraphics", i), this.axisRanges.each((e) => {
        const o = e.container, a = this._makeGraphics(e.columns, t);
        i && i.push(a), a.setPrivate("list", e.columns), o.children.push(a);
      });
    }
  }
  createAxisRange(t) {
    return L(this.dataItems, (s) => {
      const n = s.get("graphics");
      n && (n.dispose(), s.set("graphics", void 0));
    }), super.createAxisRange(t);
  }
  _updateGraphics(t, s, n) {
    let i = t.get("graphics");
    const e = this._xField, o = this._yField, a = t.get(e), v = t.get(o), m = this.get("exactLocationX", !1);
    if (a != null && v != null) {
      const D = this._xOpenField, g = this._yOpenField, p = this.get("locationX", t.get("locationX", 0.5)), f = this.get("locationY", t.get("locationY", 0.5)), k = this.get("openLocationX", t.get("openLocationX", p)), r = this.get("openLocationY", t.get("openLocationY", f)), h = i.get("width"), X = i.get("height"), C = this.get("stacked"), d = this.get("xAxis"), l = this.get("yAxis"), P = d.get("start"), w = d.get("end"), G = l.get("start"), N = l.get("end");
      let x, A, y, F, T = this.get("vcy", 1), O = this.get("vcx", 1), S = !1, b = !1;
      if (n == 0) {
        let u = this._aLocationX0 + k - 0.5, _ = this._aLocationX1 + p - 0.5;
        if (h instanceof R) {
          let c = (_ - u) * (1 - h.value) / 2;
          u += c, _ -= c;
        }
        if (x = d.getDataItemPositionX(t, D, u, O, m), A = d.getDataItemPositionX(t, e, _, O, m), y = l.getDataItemPositionY(t, o, f, T), this._yOpenField !== this._yField)
          F = l.getDataItemPositionY(t, g, r, T);
        else if (C) {
          let c = t.get("stackToItemY");
          c ? F = l.getDataItemPositionY(c, o, r, c.component.get("vcy")) : F = l.basePosition();
        } else
          F = l.basePosition();
        t.setRaw("point", { x: x + (A - x) / 2, y }), b = !0;
      } else if (n == 1) {
        let u = this._aLocationY0 + r - 0.5, _ = this._aLocationY1 + f - 0.5;
        if (X instanceof R) {
          let c = (_ - u) * (1 - X.value) / 2;
          u += c, _ -= c;
        }
        if (y = l.getDataItemPositionY(t, g, u, T), F = l.getDataItemPositionY(t, o, _, T), A = d.getDataItemPositionX(t, e, p, O, m), this._xOpenField !== this._xField)
          x = d.getDataItemPositionX(t, D, k, O, m);
        else if (C) {
          let c = t.get("stackToItemX");
          c ? x = d.getDataItemPositionX(c, e, k, c.component.get("vcx"), m) : x = d.basePosition();
        } else
          x = d.basePosition();
        S = !0, t.setRaw("point", { x: A, y: y + (F - y) / 2 });
      } else if (n == 2) {
        let u = this._aLocationX0 + k - 0.5, _ = this._aLocationX1 + p - 0.5;
        if (h instanceof R) {
          let c = (_ - u) * (1 - h.value) / 2;
          u += c, _ -= c;
        }
        if (x = d.getDataItemPositionX(t, D, u, O), A = d.getDataItemPositionX(t, e, _, O), u = this._aLocationY0 + r - 0.5, _ = this._aLocationY1 + f - 0.5, X instanceof R) {
          let c = (_ - u) * (1 - X.value) / 2;
          u += c, _ -= c;
        }
        y = l.getDataItemPositionY(t, g, u, T), F = l.getDataItemPositionY(t, o, _, T), t.setRaw("point", { x: x + (A - x) / 2, y: y + (F - y) / 2 });
      }
      this._applyGraphicsStates(t, s), this._updateSeriesGraphics(t, i, x, A, y, F, S, b), x < P && A < P || x > w && A > w || y < G && F <= G || y >= N && F > N || E(x) || E(y) ? this._toggleColumn(t, !1) : this._toggleColumn(t, !0);
      let V = t.get("rangeGraphics");
      V && L(V, (u) => {
        this._updateSeriesGraphics(t, u, x, A, y, F, S, b);
      });
    } else
      this._toggleColumn(t, !1);
  }
  _updateSeriesGraphics(t, s, n, i, e, o, a, v) {
    const m = s.get("width"), D = s.get("height"), g = s.get("maxWidth"), p = s.get("maxHeight"), f = this.getPoint(n, e), k = this.getPoint(i, o), r = t.get("point");
    if (r) {
      const h = this.getPoint(r.x, r.y);
      r.x = h.x + this._x, r.y = h.y + this._y;
    }
    if (n = f.x, i = k.x, e = f.y, o = k.y, Y(m)) {
      const h = (i - n - m) / 2;
      n += h, i -= h;
    }
    if (Y(g) && g < Math.abs(i - n)) {
      const h = (i - n - g) / 2;
      n += h, i -= h;
    }
    if (Y(D)) {
      const h = (o - e - D) / 2;
      e += h, o -= h;
    }
    if (Y(p) && p < Math.abs(o - e)) {
      const h = (o - e - p) / 2;
      e += h, o -= h;
    }
    this.get("adjustBulletPosition") && (a && (i = Math.min(Math.max(0, i), this._pw), n = Math.min(Math.max(0, n), this._pw)), v && (e = Math.min(Math.max(0, e), this._ph), o = Math.min(Math.max(0, o), this._ph))), t.setRaw("left", n), t.setRaw("right", i), t.setRaw("top", e), t.setRaw("bottom", o), s.setPrivate("width", i - n), s.setPrivate("height", o - e), s.set("x", n), s.set("y", o - (o - e));
  }
  _handleDataSetChange() {
    super._handleDataSetChange(), L(this._dataItems, (t) => {
      this._toggleColumn(t, !1);
    });
  }
  _applyGraphicsStates(t, s) {
    const n = t.get("graphics"), i = n.states.lookup("dropFromOpen"), e = n.states.lookup("riseFromOpen"), o = n.states.lookup("dropFromPrevious"), a = n.states.lookup("riseFromPrevious");
    if (i || o || e || a) {
      const v = this.get("xAxis"), m = this.get("yAxis"), D = this.get("baseAxis");
      let g, p, f;
      D === v && m.isType("ValueAxis") ? (g = t.get(this._yOpenField), p = t.get(this._yField), f = s.get(this._yField)) : D === m && v.isType("ValueAxis") && (g = t.get(this._xOpenField), p = t.get(this._xField), f = s.get(this._xField)), Y(g) && Y(p) && (p < g ? i && i.apply() : e && e.apply(), Y(f) && (p < f ? o && o.apply() : a && a.apply()));
    }
  }
  /**
   * @ignore
   */
  disposeDataItem(t) {
    super.disposeDataItem(t);
    const s = t.get("graphics");
    s && (this.columns.removeValue(s), s.dispose());
    const n = t.get("rangeGraphics");
    n && L(n, (i) => {
      const e = i.getPrivate("list");
      e && e.removeValue(i), i.dispose();
    });
  }
  /**
   * Hides series's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  hideDataItem(t, s) {
    const n = Object.create(null, {
      hideDataItem: { get: () => super.hideDataItem }
    });
    return U(this, void 0, void 0, function* () {
      const i = [n.hideDataItem.call(this, t, s)], e = t.get("graphics");
      e && i.push(e.hide(s));
      const o = t.get("rangeGraphics");
      o && L(o, (a) => {
        i.push(a.hide(s));
      }), yield Promise.all(i);
    });
  }
  _toggleColumn(t, s) {
    const n = t.get("graphics");
    n && n.setPrivate("visible", s);
    const i = t.get("rangeGraphics");
    i && L(i, (o) => {
      o.setPrivate("visible", s);
    });
    const e = t.bullets;
    e && L(e, (o) => {
      o.setPrivate("hidden", !s);
    });
  }
  /**
   * Shows series's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  showDataItem(t, s) {
    const n = Object.create(null, {
      showDataItem: { get: () => super.showDataItem }
    });
    return U(this, void 0, void 0, function* () {
      const i = [n.showDataItem.call(this, t, s)], e = t.get("graphics");
      e && i.push(e.show(s));
      const o = t.get("rangeGraphics");
      o && L(o, (a) => {
        i.push(a.show(s));
      }), yield Promise.all(i);
    });
  }
  /**
   * @ignore
   */
  updateLegendMarker(t) {
    let s = this.get("legendDataItem");
    if (this.get("useLastColorForLegendMarker") && !t) {
      const n = this.dataItems[this.endIndex() - 1];
      n && (t = n);
    }
    if (s) {
      let n = this.columns.template;
      if (t) {
        let e = t.get("graphics");
        e && (n = e);
      }
      const i = s.get("markerRectangle");
      if (i && !s.get("itemContainer").get("disabled")) {
        const e = i.states.lookup("default");
        L(j, (o) => {
          const a = n.get(o, this.get(o));
          i.set(o, a), e.set(o, a);
        });
      }
    }
  }
  _getTooltipTarget(t) {
    if (this.get("seriesTooltipTarget") == "bullet")
      return super._getTooltipTarget(t);
    let s = t.get("graphics");
    return s || this;
  }
}
M.className = "BaseColumnSeries";
M.classNames = B.classNames.concat([M.className]);
export {
  M as B
};
