import { S as d, a as e } from "./am-chart.H2jnOzFc.js";
class a extends d {
  constructor() {
    super(...arguments), this._display = this._root._renderer.makePicture(void 0);
  }
  _changed() {
    if (super._changed(), this.isDirty("width")) {
      const i = this.get("width");
      this._display.width = e(i) ? i : void 0;
    }
    if (this.isDirty("height")) {
      const i = this.get("height");
      this._display.height = e(i) ? i : void 0;
    }
    if (this.isDirty("shadowColor")) {
      this._display.clear();
      const i = this.get("shadowColor");
      this._display.shadowColor = i ?? void 0;
    }
    this.isDirty("shadowBlur") && (this._display.clear(), this._display.shadowBlur = this.get("shadowBlur")), this.isDirty("shadowOffsetX") && (this._display.clear(), this._display.shadowOffsetX = this.get("shadowOffsetX")), this.isDirty("shadowOffsetY") && (this._display.clear(), this._display.shadowOffsetY = this.get("shadowOffsetY")), this.isDirty("shadowOpacity") && (this._display.clear(), this._display.shadowOpacity = this.get("shadowOpacity")), (this.isDirty("src") || this.isDirty("cors")) && (this._display.clear(), this._load());
  }
  _load() {
    const i = this.get("src");
    if (i) {
      const t = new Image();
      t.crossOrigin = this.get("cors", "anonymous"), t.src = i;
      const s = this.events;
      t.decode().then(() => {
        this._display.image = t, this._updateSize(), !s.isDisposed() && s.isEnabled("loaded") && s.dispatch("loaded", { type: "loaded", target: this });
      }).catch((h) => {
        !s.isDisposed() && s.isEnabled("loaderror") && s.dispatch("loaderror", { type: "loaderror", target: this });
      });
    }
  }
  _updateSize() {
    super._updateSize();
    const i = this._display.image;
    if (i) {
      let t = this.getPrivate("width", this.get("width")), s = this.getPrivate("height", this.get("height"));
      const h = i.width && i.height ? i.width / i.height : 0;
      e(t) && e(s) ? (this._display.width = t, this._display.height = s) : e(t) && h ? s = t / h : e(s) && h ? t = s * h : (t = i.width, s = i.height), e(t) && (this._display.width = t), e(s) && (this._display.height = s), this.markDirtyBounds(), this.markDirty();
    }
  }
}
a.className = "Picture";
a.classNames = d.classNames.concat([a.className]);
export {
  a as P
};
