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