import { B as D, s as E, c as C, g as F, ai as H, G as A, C as u, aj as k, ak as L, a as K, w as W, d as z, b as G, r as T, x as V, H as X } from "./am-chart.H2jnOzFc.js";
import { T as m } from "./Triangle.BaOef7HV.js";
import { E as Y } from "./EditableLabel.BWeq6fgX.js";
import { S as M } from "./Slice.DiEswWa6.js";
import { C as j } from "./Circle.DBa5Ok8V.js";
class _ extends D {
  _afterNew() {
    super._afterNew(), this.addTag("confirm"), E("keyboardevents") && this._disposers.push(C(document, "keydown", (t) => {
      const e = F(t);
      this.get("active") && e == "Escape" && this._cancel();
    })), this._disposers.push(C(document, "click", () => {
      this._ignoreClick || this._cancel(), this._ignoreClick = !1;
    })), this.events.on("click", () => {
      this.get("active") || (this._ignoreClick = !0), this._confirm();
    });
  }
  _cancel() {
    this.get("active") && (this.events.dispatch("cancelled", {
      type: "cancelled",
      target: this
    }), this.set("active", !1));
  }
  _confirm() {
    this.get("active") && (this.events.dispatch("confirmed", {
      type: "confirmed",
      target: this
    }), this.set("active", !1), this.isFocus() && this.setTimeout(() => {
      this.set("active", !1), H();
    }, 10));
  }
  _prepareChildren() {
    super._prepareChildren();
  }
}
_.className = "ConfirmButton";
_.classNames = D.classNames.concat([_.className]);
class c extends A {
  _beforeChanged() {
    super._beforeChanged(), this.isDirty("points") && (this._clear = !0);
  }
  static makeOrthogonal(t) {
    if (t.length > 1) {
      const e = [];
      for (let n = 0; n < t.length - 1; n++) {
        const a = t[n], i = t[n + 1];
        e.push(a), a.x !== i.x && a.y !== i.y && e.push({ x: i.x, y: a.y });
      }
      e.push(t[t.length - 1]), t = e;
    }
    return t;
  }
  /**
   * Handles changes and redraws the orthogonal line with optional rounded corners.
   */
  _changed() {
    if (super._changed(), this._clear) {
      const t = this._display;
      let e = this.get("points", []);
      if (e.length === 0)
        return;
      e = c.makeOrthogonal(e), t.moveTo(e[0].x, e[0].y);
      for (let n = 1; n < e.length; n++) {
        let a = this.get("cornerRadius", 0);
        const i = e[n - 1], s = e[n], r = e[n + 1], d = s.y === i.y && s.x !== i.x, p = s.x === i.x && s.y !== i.y, h = r && (d && r.y !== s.y || p && r.x !== s.x);
        if (a > 0 && r && h) {
          if (p) {
            a = Math.min(a, Math.abs(s.x - r.x) / 2, Math.abs(s.y - i.y) / 2);
            const o = Math.sign(s.y - i.y);
            t.lineTo(s.x, s.y - a * o);
            const l = r.x < s.x ? -1 : 1;
            t.arcTo(s.x, s.y, s.x + a * l, s.y, a);
          } else if (d) {
            a = Math.min(a, Math.abs(s.y - r.y) / 2, Math.abs(s.x - i.x) / 2);
            const o = Math.sign(s.x - i.x);
            t.lineTo(s.x - a * o, s.y);
            const l = r.y < s.y ? -1 : 1;
            t.arcTo(s.x, s.y, s.x, s.y + a * l, a);
          }
        } else
          t.lineTo(s.x, s.y);
      }
    }
  }
}
c.className = "OrthogonalLine";
c.classNames = A.classNames.concat([c.className]);
class b extends u {
  constructor() {
    super(...arguments), this.line = this.children.push(c.new(this._root, { themeTags: ["line"] })), this.hitLine = this.children.push(c.new(this._root, { themeTags: ["hit"] })), this.startArrow = this.children.push(m.new(this._root, {
      themeTags: ["start", "arrow"]
    })), this.endArrow = this.children.push(m.new(this._root, {
      themeTags: ["end", "arrow"]
    }));
  }
  _afterNew() {
    this.addTag("link"), super._afterNew();
  }
  _updateChildren() {
    if (super._updateChildren(), this.isDirty("points")) {
      let t = c.makeOrthogonal(this.get("points", []));
      this.line.set("points", t), this.hitLine.set("points", t);
      const e = this.startArrow, n = this.endArrow, a = t.length;
      if (a > 1) {
        const [i, s] = t;
        e.setAll({
          x: i.x,
          y: i.y,
          rotation: k(i, s) - 90
        });
        const r = t[a - 1], d = t[a - 2];
        n.setAll({
          x: r.x,
          y: r.y,
          rotation: k(d, r) + 90
        });
      } else if (a === 1) {
        const [i] = t;
        e.setAll({ x: i.x, y: i.y, rotation: 0 }), n.setAll({ x: i.x, y: i.y, rotation: 0 });
      }
    }
  }
}
b.className = "Link";
b.classNames = u.classNames.concat([b.className]);
class x extends L {
  _beforeChanged() {
    super._beforeChanged(), this.isDirty("gap") && (this._clear = !0);
  }
  _draw() {
    super._draw();
    const t = this.get("width", 100), e = this.get("height", 100), n = this.get("gap", 0), a = this.get("strokeWidth", 1);
    if (!n)
      this._display.moveTo(0, 0), this._display.lineTo(t, 0);
    else {
      let r = n + a, d = e / r, p = this.get("angle", 0) * Math.PI / 180;
      if (p === 0)
        for (let h = -d; h < d * 2; h++) {
          const o = Math.round(h * r - r / 2) + 0.5;
          this._display.moveTo(-t, o), this._display.lineTo(t * 2, o);
        }
      else {
        const h = Math.cos(p), o = Math.sin(p), l = Math.sqrt(t * t + e * e) * 2, S = r / Math.max(Math.abs(h), Math.abs(o)), N = Math.ceil(l / S) * 2;
        for (let y = -N; y < N; y++) {
          const f = y * r, B = f * o - l * h, O = f * h + l * o, P = f * o + l * h, R = f * h - l * o;
          this._display.moveTo(B, O), this._display.lineTo(P, R);
        }
      }
    }
    this._display.lineStyle(a, this.get("color"), this.get("colorOpacity"));
    let i = this.get("strokeDasharray");
    K(i) && (i < 0.5 ? i = [0] : i = [i]), this._display.setLineDash(i);
    const s = this.get("strokeDashoffset");
    s && this._display.setLineDashOffset(s), this._display.endStroke();
  }
}
x.className = "LinePattern";
x.classNames = L.classNames.concat([x.className]);
class v extends u {
  constructor() {
    super(...arguments), this.label = this.children.push(Y.new(this._root, {})), this.buttonsContainer = this.children.push(u.new(this._root, { themeTags: ["buttons"] })), this.upButton = this.buttonsContainer.children.push(m.new(this._root, { themeTags: ["upbutton"] })), this.downButton = this.buttonsContainer.children.push(m.new(this._root, { themeTags: ["downbutton"] }));
  }
  _afterNew() {
    this.addTag("numericstepper"), this.set("layout", this._root.horizontalLayout), this.label.adapters.add("text", (t) => (t && t.replace(/\D/g, ""), t === "" && (t = "0"), t)), this.set("background", W.new(this._root, {
      fillOpacity: 0,
      fill: z(16777215)
    })), this.buttonsContainer.states.create("hidden", {
      opacity: 0,
      visible: !0
    }), this.events.on("pointerover", () => {
      this.buttonsContainer.set("active", !0);
    }), this.events.on("pointerout", () => {
      this.buttonsContainer.set("active", !1);
    }), this.label.on("text", (t) => {
      if (t) {
        const e = parseFloat(t);
        isNaN(e) || this.set("value", e);
      }
    }), this.upButton.events.on("click", () => {
      this.set("value", this.get("value", 0) + 1);
    }), this.downButton.events.on("click", () => {
      this.set("value", Math.max(0, this.get("value", 0) - 1));
    }), super._afterNew();
  }
  _updateChildren() {
    super._updateChildren();
    const t = this.get("value", 0), e = this.label;
    if (this.isDirty("value") && e.set("text", t.toString()), this.isDirty("disabled")) {
      const n = this.get("disabled", !1);
      this.set("interactive", !n), this.upButton.set("interactive", !n), this.downButton.set("interactive", !n), n ? (this.label.set("editOn", "none"), this.buttonsContainer.hide(0)) : (this.label.set("editOn", "click"), this.buttonsContainer.show(0));
    }
  }
}
v.className = "NumericStepper";
v.classNames = u.classNames.concat([v.className]);
class w extends u {
  constructor() {
    super(...arguments), this.circle = this.children.push(j.new(this._root, {
      themeTags: ["background"]
    })), this.label = this.children.push(G.new(this._root, {})), this.slice = this.children.push(M.new(this._root, { isMeasured: !1 })), this.backgroundSlice = this.children.push(M.new(this._root, { themeTags: ["background"] }));
  }
  _afterNew() {
    this.addTag("progresspie"), super._afterNew();
  }
  _updateChildren() {
    if (super._updateChildren(), this.isDirty("width") || this.isDirty("height") || this.isDirty("radius") || this.isDirty("innerRadius")) {
      const t = this.innerWidth(), e = this.innerHeight(), n = T(this.get("radius", V), Math.min(t, e) / 2), a = T(this.get("innerRadius", X(80)), n);
      this.slice.setAll({
        radius: n,
        innerRadius: a
      }), this.backgroundSlice.setAll({
        radius: n,
        innerRadius: a
      }), this.circle.set("radius", n);
    }
    if (this.isDirty("value")) {
      const t = this.get("value", 0);
      this.slice.set("arc", t * 360), this.backgroundSlice.set("arc", 360), this.label.setAll({
        text: this.getNumberFormatter().format(t * 100, this.get("numberFormat", "#'"))
      }), this.root.events.once("frameended", () => {
        this.label.markDirtyKey("text");
      });
    }
  }
}
w.className = "ProgressPie";
w.classNames = u.classNames.concat([w.className]);
export {
  _ as C,
  x as L,
  v as N,
  c as O,
  w as P,
  b as a
};
