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