import { computed as v, ref as p, watch as J, onMounted as ne, openBlock as r, createElementBlock as u, normalizeClass as G, normalizeStyle as K, createBlock as O, createCommentVNode as g, unref as d, createSlots as ue, withCtx as F, renderSlot as _, normalizeProps as L, guardReactiveProps as M, createVNode as ie, Fragment as Q, renderList as V, toDisplayString as ce } from "vue";
import { u as W } from "./useNestedProp-BYPZJNhi.js";
import { u as ve, c as he, t as de, v as fe, o as pe, e as ge, w as Z, X as me, i as ye, f as ke } from "./index-Cm2_6s9o.js";
import { _ as _e } from "./Title-Coit3NcT.js";
import { u as be, U as Ce } from "./usePrinter-Cx8U1e30.js";
import $e from "./vue-ui-skeleton-BUS6A44x.js";
import { _ as we } from "./PackageVersion-CTMY4zeY.js";
import { P as xe } from "./PenAndPaper-DJ_d10S-.js";
import { _ as Pe } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Ae = ["id"], Ie = {
  key: 2,
  style: "width:100%;background:transparent;padding-bottom:12px"
}, Oe = ["xmlns", "viewBox"], Fe = { key: 0 }, ze = ["d", "stroke-width", "stroke"], Se = { key: 1 }, Ne = ["x1", "y1", "x2", "y2", "stroke-width", "stroke"], Te = ["x", "y", "font-size", "fill", "font-weight", "text-anchor"], Ge = {
  key: 5,
  class: "vue-data-ui-watermark"
}, Le = {
  key: 6,
  ref: "source",
  dir: "auto"
}, Me = {
  __name: "vue-ui-tiremarks",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(ee, { expose: te }) {
    const h = ee, { vue_ui_tiremarks: ae } = ve(), z = v(() => !!h.dataset && Object.keys(h.dataset).length), S = p(he()), N = p(null), le = p(null), U = p(0), j = p(0), e = v({
      get: () => B(),
      set: (t) => t
    });
    function B() {
      const t = W({
        userConfig: h.config,
        defaultConfig: ae
      });
      return t.theme ? {
        ...W({
          userConfig: de.vue_ui_tiremarks[t.theme] || h.config,
          defaultConfig: t
        })
      } : t;
    }
    J(() => h.config, (t) => {
      e.value = B(), Y(), j.value += 1;
    }, { deep: !0 });
    const { isPrinting: E, isImaging: X, generatePdf: D, generateImage: H } = be({
      elementId: S.value,
      fileName: e.value.style.chart.title.text || "vue-ui-tiremarks"
    }), oe = v(() => e.value.userOptions.show && !e.value.style.chart.title.text), s = p(e.value.style.chart.animation.use ? 0 : fe(h.dataset.percentage));
    J(() => h.dataset, (t) => {
      e.value.style.chart.animation.use ? R(t.percentage) : s.value = t.percentage || 0;
    }, { deep: !0 }), ne(() => {
      Y();
    });
    function R(t) {
      let i = e.value.style.chart.animation.speed;
      const a = Math.abs(t - s.value) / (i * 120);
      function o() {
        s.value < t ? s.value = Math.min(s.value + a, t) : s.value > t && (s.value = Math.max(s.value - a, t)), s.value !== t && requestAnimationFrame(o);
      }
      o();
    }
    function Y() {
      pe(h.dataset) && ge({
        componentName: "VueUiTiremarks",
        type: "dataset"
      }), R(h.dataset.percentage || 0);
    }
    const b = v(() => e.value.style.chart.layout.display === "vertical"), n = v(() => {
      const t = {
        top: 48,
        left: 64,
        right: 64,
        bottom: 48
      };
      return b.value ? {
        top: e.value.style.chart.percentage.verticalPosition === "top" ? t.top : 3,
        left: 3,
        right: 3,
        bottom: e.value.style.chart.percentage.verticalPosition === "bottom" ? t.bottom : 3
      } : {
        top: 0,
        bottom: 0,
        left: e.value.style.chart.percentage.horizontalPosition === "left" ? t.left : 3,
        right: e.value.style.chart.percentage.horizontalPosition === "right" ? t.right : 10
      };
    }), P = v(() => Object.values(n.value).reduce((t, i) => t + i, 0)), l = v(() => ({
      height: b.value ? 312 : 56,
      width: b.value ? 56 : 312
    })), re = p(100);
    v(() => h.dataset.percentage / re.value);
    const c = v(() => b.value ? {
      mark: (l.value.height - P.value) / 100 * 0.5,
      space: (l.value.height - P.value) / 100 * 0.5
    } : {
      mark: (l.value.width - P.value) / 100 * 0.5,
      space: (l.value.width - P.value) / 100 * 0.5
    }), q = v(() => {
      const t = [];
      for (let a = 0; a < 100; a += 1) {
        const o = e.value.style.chart.layout.ticks.gradient.show ? Z(e.value.style.chart.layout.activeColor, a / 100 * (e.value.style.chart.layout.ticks.gradient.shiftHueIntensity / 100)) : e.value.style.chart.layout.activeColor;
        if (b.value) {
          const $ = e.value.style.chart.layout.crescendo ? (100 - a) * (l.value.width - n.value.left - n.value.right) / 100 / 3 : 0, f = n.value.left + 4 + $, m = l.value.width - n.value.right - 4 - $, y = l.value.height - n.value.bottom - a * c.value.mark - a * c.value.space - c.value.mark, k = l.value.height - n.value.bottom - a * c.value.mark - a * c.value.space - c.value.mark, w = (m - f) / e.value.style.chart.layout.curveAngleX, x = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100);
          t.push({
            x1: f,
            x2: m,
            y1: y,
            y2: k,
            curve: `M ${f} ${y} C ${f + w} ${y - x}, ${m - w} ${k - x}, ${m} ${k}`,
            color: o
          });
        } else {
          const $ = e.value.style.chart.layout.crescendo ? (100 - a) * (l.value.height - n.value.top - n.value.bottom) / 100 / 3 : 0, f = n.value.left + a * c.value.mark + a * c.value.space - c.value.mark, m = f, y = n.value.top + 4 + $, k = l.value.height - n.value.bottom - 4 - $, w = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100), x = (k - y) / e.value.style.chart.layout.curveAngleX;
          t.push({
            x1: f,
            x2: m,
            y1: y,
            y2: k,
            curve: `M ${f} ${y} C ${f + w} ${y + x}, ${m + w} ${k - x}, ${m} ${k}`,
            color: o
          });
        }
      }
      return t;
    }), C = v(() => {
      let t, i, a;
      const o = e.value.style.chart.percentage.fontSize / 3;
      return b.value ? e.value.style.chart.percentage.verticalPosition === "top" ? (t = l.value.width / 2, i = n.value.top / 2, a = "middle") : e.value.style.chart.percentage.verticalPosition === "bottom" && (t = l.value.width / 2, i = l.value.height - n.value.bottom / 2 + o, a = "middle") : e.value.style.chart.percentage.horizontalPosition === "left" ? (t = 4, i = l.value.height / 2 + o, a = "start") : e.value.style.chart.percentage.horizontalPosition === "right" && (t = l.value.width - n.value.right + 8, i = l.value.height / 2 + o, a = "start"), {
        x: t,
        y: i,
        textAnchor: a,
        bold: e.value.style.chart.percentage.bold,
        fontSize: e.value.style.chart.percentage.fontSize,
        fill: e.value.style.chart.percentage.color
      };
    }), A = p(!1);
    function se(t) {
      A.value = t, U.value += 1;
    }
    const I = p(!1);
    function T() {
      I.value = !I.value;
    }
    return te({
      generatePdf: D,
      generateImage: H,
      toggleAnnotator: T
    }), (t, i) => (r(), u("div", {
      ref_key: "tiremarksChart",
      ref: N,
      class: G(`vue-ui-tiremarks ${e.value.useCssAnimation ? "" : "vue-ui-dna"}`),
      style: K(`font-family:${e.value.style.fontFamily};width:100%; text-align:center;background:${e.value.style.chart.backgroundColor}`),
      id: S.value
    }, [
      e.value.userOptions.buttons.annotator ? (r(), O(xe, {
        key: 0,
        parent: N.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: I.value,
        onClose: T
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : g("", !0),
      oe.value ? (r(), u("div", {
        key: 1,
        ref_key: "noTitle",
        ref: le,
        class: "vue-data-ui-no-title-space",
        style: "height:36px; width: 100%;background:transparent"
      }, null, 512)) : g("", !0),
      e.value.style.chart.title.text ? (r(), u("div", Ie, [
        (r(), O(_e, {
          key: `title_${j.value}`,
          config: {
            title: {
              cy: "wheel-title",
              ...e.value.style.chart.title
            },
            subtitle: {
              cy: "wheel-subtitle",
              ...e.value.style.chart.title.subtitle
            }
          }
        }, null, 8, ["config"]))
      ])) : g("", !0),
      e.value.userOptions.show && z.value ? (r(), O(Ce, {
        ref: "details",
        key: `user_options_${U.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: d(E),
        isImaging: d(X),
        uid: S.value,
        hasPdf: e.value.userOptions.buttons.pdf,
        hasImg: e.value.userOptions.buttons.img,
        hasFullscreen: e.value.userOptions.buttons.fullscreen,
        hasXls: !1,
        isFullscreen: A.value,
        titles: { ...e.value.userOptions.buttonTitles },
        chartElement: N.value,
        position: e.value.userOptions.position,
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: I.value,
        onToggleFullscreen: se,
        onGeneratePdf: d(D),
        onGenerateImage: d(H),
        onToggleAnnotator: T
      }, ue({ _: 2 }, [
        t.$slots.optionPdf ? {
          name: "optionPdf",
          fn: F(() => [
            _(t.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        t.$slots.optionImg ? {
          name: "optionImg",
          fn: F(() => [
            _(t.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        t.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: F(({ toggleFullscreen: a, isFullscreen: o }) => [
            _(t.$slots, "optionFullscreen", L(M({ toggleFullscreen: a, isFullscreen: o })), void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: F(({ toggleAnnotator: a, isAnnotator: o }) => [
            _(t.$slots, "optionAnnotator", L(M({ toggleAnnotator: a, isAnnotator: o })), void 0, !0)
          ]),
          key: "3"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "titles", "chartElement", "position", "hasAnnotator", "isAnnotation", "onGeneratePdf", "onGenerateImage"])) : g("", !0),
      z.value ? (r(), u("svg", {
        key: 4,
        xmlns: d(me),
        class: G({ "vue-data-ui-fullscreen--on": A.value, "vue-data-ui-fulscreen--off": !A.value }),
        viewBox: `0 0 ${l.value.width} ${l.value.height}`,
        style: K(`max-width:100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`)
      }, [
        ie(we),
        e.value.style.chart.layout.curved ? (r(), u("g", Fe, [
          (r(!0), u(Q, null, V(q.value, (a, o) => (r(), u("path", {
            d: a.curve,
            "stroke-width": c.value.mark,
            stroke: s.value >= o ? a.color : e.value.style.chart.layout.inactiveColor,
            "stroke-linecap": "round",
            fill: "none",
            class: G({ "vue-ui-tick-animated": e.value.style.chart.animation.use && o <= s.value })
          }, null, 10, ze))), 256))
        ])) : (r(), u("g", Se, [
          (r(!0), u(Q, null, V(q.value, (a, o) => (r(), u("line", {
            x1: a.x1,
            y1: a.y1,
            x2: a.x2,
            y2: a.y2,
            "stroke-width": c.value.mark,
            stroke: s.value >= o ? a.color : e.value.style.chart.layout.inactiveColor,
            "stroke-linecap": "round"
          }, null, 8, Ne))), 256))
        ])),
        e.value.style.chart.percentage.show ? (r(), u("text", {
          key: 2,
          x: C.value.x,
          y: C.value.y,
          "font-size": C.value.fontSize,
          fill: e.value.style.chart.layout.ticks.gradient.show && e.value.style.chart.percentage.useGradientColor ? d(Z)(e.value.style.chart.layout.activeColor, s.value / 100 * (e.value.style.chart.layout.ticks.gradient.shiftHueIntensity / 100)) : e.value.style.chart.percentage.color,
          "font-weight": C.value.bold ? "bold" : "normal",
          "text-anchor": C.value.textAnchor
        }, ce(d(ye)(
          e.value.style.chart.percentage.formatter,
          s.value,
          d(ke)({
            v: s.value,
            s: "%",
            r: e.value.style.chart.percentage.rounding
          })
        )), 9, Te)) : g("", !0),
        _(t.$slots, "svg", { svg: l.value }, void 0, !0)
      ], 14, Oe)) : g("", !0),
      t.$slots.watermark ? (r(), u("div", Ge, [
        _(t.$slots, "watermark", L(M({ isPrinting: d(E) || d(X) })), void 0, !0)
      ])) : g("", !0),
      t.$slots.source ? (r(), u("div", Le, [
        _(t.$slots, "source", {}, void 0, !0)
      ], 512)) : g("", !0),
      z.value ? g("", !0) : (r(), O($e, {
        key: 7,
        config: {
          type: "tiremarks",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            tiremarks: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"]))
    ], 14, Ae));
  }
}, qe = /* @__PURE__ */ Pe(Me, [["__scopeId", "data-v-93332410"]]);
export {
  qe as default
};
