import { computed as h, ref as k, watch as W, onMounted as ie, openBlock as s, createElementBlock as c, normalizeClass as U, normalizeStyle as G, unref as n, createBlock as I, createCommentVNode as d, createSlots as ce, withCtx as F, renderSlot as b, normalizeProps as L, guardReactiveProps as j, createVNode as ve, Fragment as Z, renderList as ee, toDisplayString as he } from "vue";
import { u as te } from "./useNestedProp-CTDeT4KA.js";
import { u as de, c as fe, t as pe, v as ye, o as ge, e as me, w as ae, X as ke, i as be, f as _e } from "./index-MWHrTFPq.js";
import { _ as Ce } from "./Title-C7EOYmwp.js";
import { u as $e, U as we } from "./usePrinter-CEEgHfhF.js";
import xe from "./vue-ui-skeleton-Bo8ydREb.js";
import { _ as Pe } from "./PackageVersion-CBKqLhAX.js";
import { P as Oe } from "./PenAndPaper-DtLD2Sq6.js";
import { u as Ae } from "./useUserOptionState-BIvW1Kz7.js";
import { _ as Ie } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Fe = ["id"], ze = {
  key: 2,
  style: "width:100%;background:transparent;padding-bottom:12px"
}, Se = ["xmlns", "viewBox"], Ne = ["width", "height"], Me = { key: 1 }, Te = ["d", "stroke-width", "stroke"], Ue = { key: 2 }, Ge = ["x1", "y1", "x2", "y2", "stroke-width", "stroke"], Le = ["x", "y", "font-size", "fill", "font-weight", "text-anchor"], je = {
  key: 5,
  class: "vue-data-ui-watermark"
}, Ee = {
  key: 6,
  ref: "source",
  dir: "auto"
}, Be = {
  __name: "vue-ui-tiremarks",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(oe, { expose: le }) {
    const f = oe, { vue_ui_tiremarks: se } = de(), z = h(() => !!f.dataset && Object.keys(f.dataset).length), S = k(fe()), N = k(null), re = k(null), E = k(0), B = k(0), e = h({
      get: () => H(),
      set: (t) => t
    }), { userOptionsVisible: M, setUserOptionsVisibility: X, keepUserOptionState: D } = Ae({ config: e.value });
    function H() {
      const t = te({
        userConfig: f.config,
        defaultConfig: se
      });
      return t.theme ? {
        ...te({
          userConfig: pe.vue_ui_tiremarks[t.theme] || f.config,
          defaultConfig: t
        })
      } : t;
    }
    W(() => f.config, (t) => {
      e.value = H(), M.value = !e.value.showOnChartHover, K(), B.value += 1;
    }, { deep: !0 });
    const { isPrinting: R, isImaging: V, generatePdf: Y, generateImage: q } = $e({
      elementId: S.value,
      fileName: e.value.style.chart.title.text || "vue-ui-tiremarks"
    }), ne = h(() => e.value.userOptions.show && !e.value.style.chart.title.text), u = k(e.value.style.chart.animation.use ? 0 : ye(f.dataset.percentage));
    W(() => f.dataset, (t) => {
      e.value.style.chart.animation.use ? J(t.percentage) : u.value = t.percentage || 0;
    }, { deep: !0 }), ie(() => {
      K();
    });
    function J(t) {
      let r = e.value.style.chart.animation.speed;
      const a = Math.abs(t - u.value) / (r * 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 K() {
      ge(f.dataset) && me({
        componentName: "VueUiTiremarks",
        type: "dataset"
      }), J(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, r) => t + r, 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
    }), Q = h(() => {
      const t = [];
      for (let a = 0; a < 100; a += 1) {
        const l = e.value.style.chart.layout.ticks.gradient.show ? ae(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, p = i.value.left + 4 + $, y = o.value.width - i.value.right - 4 - $, g = 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 - p) / e.value.style.chart.layout.curveAngleX, x = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100);
          t.push({
            x1: p,
            x2: y,
            y1: g,
            y2: m,
            curve: `M ${p} ${g} C ${p + w} ${g - 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, p = i.value.left + a * v.value.mark + a * v.value.space - v.value.mark, y = p, g = i.value.top + 4 + $, m = o.value.height - i.value.bottom - 4 - $, w = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100), x = (m - g) / e.value.style.chart.layout.curveAngleX;
          t.push({
            x1: p,
            x2: y,
            y1: g,
            y2: m,
            curve: `M ${p} ${g} C ${p + w} ${g + x}, ${y + w} ${m - x}, ${y} ${m}`,
            color: l
          });
        }
      }
      return t;
    }), C = h(() => {
      let t, r, a;
      const l = e.value.style.chart.percentage.fontSize / 3;
      return _.value ? e.value.style.chart.percentage.verticalPosition === "top" ? (t = o.value.width / 2, r = i.value.top / 2, a = "middle") : e.value.style.chart.percentage.verticalPosition === "bottom" && (t = o.value.width / 2, r = o.value.height - i.value.bottom / 2 + l, a = "middle") : e.value.style.chart.percentage.horizontalPosition === "left" ? (t = 4, r = o.value.height / 2 + l, a = "start") : e.value.style.chart.percentage.horizontalPosition === "right" && (t = o.value.width - i.value.right + 8, r = o.value.height / 2 + l, a = "start"), {
        x: t,
        y: r,
        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 ue(t) {
      O.value = t, E.value += 1;
    }
    const A = k(!1);
    function T() {
      A.value = !A.value;
    }
    return le({
      generatePdf: Y,
      generateImage: q,
      toggleAnnotator: T
    }), (t, r) => (s(), c("div", {
      ref_key: "tiremarksChart",
      ref: N,
      class: U(`vue-ui-tiremarks ${e.value.useCssAnimation ? "" : "vue-ui-dna"}`),
      style: G(`font-family:${e.value.style.fontFamily};width:100%; text-align:center;background:${e.value.style.chart.backgroundColor}`),
      id: S.value,
      onMouseenter: r[0] || (r[0] = () => n(X)(!0)),
      onMouseleave: r[1] || (r[1] = () => n(X)(!1))
    }, [
      e.value.userOptions.buttons.annotator ? (s(), I(Oe, {
        key: 0,
        parent: N.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: A.value,
        onClose: T
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : d("", !0),
      ne.value ? (s(), c("div", {
        key: 1,
        ref_key: "noTitle",
        ref: re,
        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", ze, [
        (s(), I(Ce, {
          key: `title_${B.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 && (n(D) || n(M)) ? (s(), I(we, {
        ref: "details",
        key: `user_options_${E.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: n(R),
        isImaging: n(V),
        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: N.value,
        position: e.value.userOptions.position,
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: A.value,
        onToggleFullscreen: ue,
        onGeneratePdf: n(Y),
        onGenerateImage: n(q),
        onToggleAnnotator: T,
        style: G({
          visibility: n(D) ? n(M) ? "visible" : "hidden" : "visible"
        })
      }, ce({ _: 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", L(j({ 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", L(j({ 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,
        xmlns: n(ke),
        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: G(`max-width:100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`)
      }, [
        ve(Pe),
        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, Ne)) : d("", !0),
        e.value.style.chart.layout.curved ? (s(), c("g", Me, [
          (s(!0), c(Z, null, ee(Q.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, Te))), 256))
        ])) : (s(), c("g", Ue, [
          (s(!0), c(Z, null, ee(Q.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, Ge))), 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 ? n(ae)(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
        }, he(n(be)(
          e.value.style.chart.percentage.formatter,
          u.value,
          n(_e)({
            v: u.value,
            s: "%",
            r: e.value.style.chart.percentage.rounding
          })
        )), 9, Le)) : d("", !0),
        b(t.$slots, "svg", { svg: o.value }, void 0, !0)
      ], 14, Se)) : d("", !0),
      t.$slots.watermark ? (s(), c("div", je, [
        b(t.$slots, "watermark", L(j({ isPrinting: n(R) || n(V) })), void 0, !0)
      ])) : d("", !0),
      t.$slots.source ? (s(), c("div", Ee, [
        b(t.$slots, "source", {}, void 0, !0)
      ], 512)) : d("", !0),
      z.value ? d("", !0) : (s(), I(xe, {
        key: 7,
        config: {
          type: "tiremarks",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            tiremarks: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"]))
    ], 46, Fe));
  }
}, We = /* @__PURE__ */ Ie(Be, [["__scopeId", "data-v-60aa805a"]]);
export {
  We as default
};
