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