import { G as f, e as v, l as m } from "./am-chart.H2jnOzFc.js";
class P extends f {
  _beforeChanged() {
    if (super._beforeChanged(), this.isDirty("coordinates")) {
      const i = [], n = this.get("coordinates");
      n && v(n, (e) => {
        i.push({ x: e[0], y: e[1] });
      }), this.set("points", i);
    }
    if (this.isPrivateDirty("points") && (this._clear = !0), this.isDirty("points")) {
      this._clear = !0;
      const i = this.get("points"), n = this._prevSettings.points;
      if (n) {
        if (i) {
          let s = m(i), o = m(n), t = s.length, p = o.length;
          if (t > p) {
            let c = m(s);
            for (let a = 0; a < t; a++) {
              let y = Math.floor(a / t * p);
              c[a] = { x: o[y].x, y: o[y].y };
            }
            o = c;
          } else if (p > t) {
            let c = m(o);
            for (let a = 0; a < p; a++) {
              let y = Math.floor(a / p * t);
              c[a] = { x: s[y].x, y: s[y].y };
            }
            s = c;
          }
          this.setPrivateRaw("previousPoints", o), this.setPrivateRaw("points", s), this.morphAnimation = this.animatePrivate({ key: "morphProgress", from: 0, to: 1, duration: this.get("animationDuration", 0), easing: this.get("animationEasing") }), this._root.events.once("frameended", () => {
            this._markDirtyPrivateKey("morphProgress");
          });
        }
      } else
        this.setPrivateRaw("previousPoints", i), this.setPrivateRaw("points", i);
      let e = 1 / 0, h = -1 / 0, r = 1 / 0, l = -1 / 0;
      if (i)
        for (let s = 1, o = i.length; s < o; s++) {
          const t = i[s];
          e = Math.min(e, t.x), h = Math.max(h, t.x), r = Math.min(r, t.y), l = Math.max(l, t.y);
        }
      this.setPrivate("minX", e), this.setPrivate("maxX", h), this.setPrivate("minY", r), this.setPrivate("maxY", r);
    }
    this.isPrivateDirty("morphProgress") && (this._clear = !0);
  }
  _changed() {
    super._changed(), this._clear && this._draw();
  }
  _draw() {
    const i = this.getPrivate("previousPoints"), n = this.getPrivate("points"), e = this.getPrivate("morphProgress", 1);
    if (n && i) {
      const h = n[0], r = i[0];
      h && this._display.moveTo(r.x + (h.x - r.x) * e, r.y + (h.y - r.y) * e);
      for (let l = 1, s = n.length; l < s; l++) {
        const o = n[l], t = i[l];
        this._display.lineTo(t.x + (o.x - t.x) * e, t.y + (o.y - t.y) * e);
      }
      this._display.closePath();
    }
  }
  _updateSize() {
    this.markDirty(), this._clear = !0;
  }
}
P.className = "Polygon";
P.classNames = f.classNames.concat([P.className]);
export {
  P
};
