import { computed as h, ref as b, watch as Z, onMounted as ce, createElementBlock as c, openBlock as s, unref as r, normalizeStyle as G, normalizeClass as L, createBlock as F, createCommentVNode as d, createSlots as ve, withCtx as x, renderSlot as y, normalizeProps as z, guardReactiveProps as S, createVNode as he, Fragment as ee, renderList as te, toDisplayString as de } from "vue";
import { u as ae } from "./useNestedProp-BusTOV-6.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-gC66Se26.js";
import { _ as $e } from "./Title-Co3F59jq.js";
import { u as we, U as Pe } from "./usePrinter-KMFl0n0s.js";
import xe from "./vue-ui-skeleton-7Zfds6H1.js";
import { _ as Oe } from "./PackageVersion-39l3KkzC.js";
import { P as Ae } from "./PenAndPaper-CmcfpltX.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, N = h(() => !!f.dataset && Object.keys(f.dataset).length), M = b(ge()), j = b(null), ne = b(null), E = b(0), R = b(0), e = h({
      get: () => H(),
      set: (t) => t
    }), { userOptionsVisible: T, 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(), T.value = !e.value.userOptions.showOnChartHover, Q(), R.value += 1;
    }, { deep: !0 });
    const { isPrinting: V, isImaging: Y, generatePdf: q, generateImage: J } = we({
      elementId: M.value,
      fileName: e.value.style.chart.title.text || "vue-ui-tiremarks",
      options: e.value.userOptions.print
    }), ue = h(() => e.value.userOptions.show && !e.value.style.chart.title.text), u = b(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
      };
    }), O = 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 - O.value) / 100 * 0.5,
      space: (o.value.height - O.value) / 100 * 0.5
    } : {
      mark: (o.value.width - O.value) / 100 * 0.5,
      space: (o.value.width - O.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 + $, p = o.value.width - i.value.right - 4 - $, m = o.value.height - i.value.bottom - a * v.value.mark - a * v.value.space - v.value.mark, k = o.value.height - i.value.bottom - a * v.value.mark - a * v.value.space - v.value.mark, w = (p - g) / e.value.style.chart.layout.curveAngleX, P = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100);
          t.push({
            x1: g,
            x2: p,
            y1: m,
            y2: k,
            curve: `M ${g} ${m} C ${g + w} ${m - P}, ${p - w} ${k - P}, ${p} ${k}`,
            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, p = g, m = i.value.top + 4 + $, k = o.value.height - i.value.bottom - 4 - $, w = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100), P = (k - m) / e.value.style.chart.layout.curveAngleX;
          t.push({
            x1: g,
            x2: p,
            y1: m,
            y2: k,
            curve: `M ${g} ${m} C ${g + w} ${m + P}, ${p + w} ${k - P}, ${p} ${k}`,
            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
      };
    }), A = b(!1);
    function ie(t) {
      A.value = t, E.value += 1;
    }
    const I = b(!1);
    function U() {
      I.value = !I.value;
    }
    return se({
      generatePdf: q,
      generateImage: J,
      toggleAnnotator: U
    }), (t, n) => (s(), c("div", {
      ref_key: "tiremarksChart",
      ref: j,
      class: L(`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: M.value,
      onMouseenter: n[0] || (n[0] = () => r(B)(!0)),
      onMouseleave: n[1] || (n[1] = () => r(B)(!1))
    }, [
      e.value.userOptions.buttons.annotator ? (s(), F(Ae, {
        key: 0,
        svgRef: r(D),
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: I.value,
        onClose: U
      }, 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(), F($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 && N.value && (r(X) || r(T)) ? (s(), F(Pe, {
        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: M.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: j.value,
        position: e.value.userOptions.position,
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: I.value,
        onToggleFullscreen: ie,
        onGeneratePdf: r(q),
        onGenerateImage: r(J),
        onToggleAnnotator: U,
        style: G({
          visibility: r(X) ? r(T) ? "visible" : "hidden" : "visible"
        })
      }, ve({ _: 2 }, [
        t.$slots.menuIcon ? {
          name: "menuIcon",
          fn: x(({ isOpen: a, color: l }) => [
            y(t.$slots, "menuIcon", z(S({ isOpen: a, color: l })), void 0, !0)
          ]),
          key: "0"
        } : void 0,
        t.$slots.optionPdf ? {
          name: "optionPdf",
          fn: x(() => [
            y(t.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        t.$slots.optionImg ? {
          name: "optionImg",
          fn: x(() => [
            y(t.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: x(({ toggleFullscreen: a, isFullscreen: l }) => [
            y(t.$slots, "optionFullscreen", z(S({ toggleFullscreen: a, isFullscreen: l })), void 0, !0)
          ]),
          key: "3"
        } : void 0,
        t.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: x(({ toggleAnnotator: a, isAnnotator: l }) => [
            y(t.$slots, "optionAnnotator", z(S({ toggleAnnotator: a, isAnnotator: l })), void 0, !0)
          ]),
          key: "4"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "titles", "chartElement", "position", "hasAnnotator", "isAnnotation", "onGeneratePdf", "onGenerateImage", "style"])) : d("", !0),
      N.value ? (s(), c("svg", {
        key: 4,
        ref_key: "svgRef",
        ref: D,
        xmlns: r(be),
        class: L({ "vue-data-ui-fullscreen--on": A.value, "vue-data-ui-fulscreen--off": !A.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}`)
      }, [
        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"
          }
        }, [
          y(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: L({ "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),
        y(t.$slots, "svg", { svg: o.value }, void 0, !0)
      ], 14, Me)) : d("", !0),
      t.$slots.watermark ? (s(), c("div", Re, [
        y(t.$slots, "watermark", z(S({ isPrinting: r(V) || r(Y) })), void 0, !0)
      ])) : d("", !0),
      t.$slots.source ? (s(), c("div", Be, [
        y(t.$slots, "source", {}, void 0, !0)
      ], 512)) : d("", !0),
      N.value ? d("", !0) : (s(), F(xe, {
        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-fac4c918"]]);
export {
  tt as default
};
