import { computed as h, ref as k, watch as W, onMounted as ce, createElementBlock as c, openBlock as s, unref as n, normalizeStyle as U, normalizeClass as G, createBlock as I, createCommentVNode as d, createSlots as ve, withCtx as F, renderSlot as b, normalizeProps as L, guardReactiveProps as j, createVNode as he, Fragment as Z, renderList as ee, toDisplayString as de } from "vue";
import { u as te } from "./useNestedProp-CmXi5M93.js";
import { u as fe, c as ye, a as ge, v as pe, o as me, e as ke, w as ae, X as be, i as _e, f as Ce } from "./index-CjXfhpMA.js";
import { _ as $e } from "./Title-BfzkycPl.js";
import { u as we, U as xe } from "./usePrinter-bLtFFBkj.js";
import Pe from "./vue-ui-skeleton-B1q5j9VT.js";
import { _ as Oe } from "./PackageVersion-ChIRiDpv.js";
import { P as Ae } from "./PenAndPaper-OV0eQPcd.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"], Be = {
  key: 5,
  class: "vue-data-ui-watermark"
}, Xe = {
  key: 6,
  ref: "source",
  dir: "auto"
}, De = {
  __name: "vue-ui-tiremarks",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(oe, { expose: le }) {
    const { vue_ui_tiremarks: se } = fe(), f = oe, z = h(() => !!f.dataset && Object.keys(f.dataset).length), S = k(ye()), 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 } = Ie({ config: e.value }), { svgRef: ne } = Fe({ config: e.value.style.chart.title });
    function H() {
      const t = te({
        userConfig: f.config,
        defaultConfig: se
      });
      return t.theme ? {
        ...te({
          userConfig: ge.vue_ui_tiremarks[t.theme] || f.config,
          defaultConfig: t
        })
      } : t;
    }
    W(() => f.config, (t) => {
      e.value = H(), M.value = !e.value.userOptions.showOnChartHover, K(), B.value += 1;
    }, { deep: !0 });
    const { isPrinting: R, isImaging: V, generatePdf: Y, generateImage: q } = 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));
    W(() => f.dataset, (t) => {
      e.value.style.chart.animation.use ? J(t.percentage) : u.value = t.percentage || 0;
    }, { deep: !0 }), ce(() => {
      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() {
      me(f.dataset) && ke({
        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, y = i.value.left + 4 + $, g = 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 = (g - y) / e.value.style.chart.layout.curveAngleX, x = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100);
          t.push({
            x1: y,
            x2: g,
            y1: p,
            y2: m,
            curve: `M ${y} ${p} C ${y + w} ${p - x}, ${g - w} ${m - x}, ${g} ${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, y = i.value.left + a * v.value.mark + a * v.value.space - v.value.mark, g = y, 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: y,
            x2: g,
            y1: p,
            y2: m,
            curve: `M ${y} ${p} C ${y + w} ${p + x}, ${g + w} ${m - x}, ${g} ${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 ie(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: G(`vue-ui-tiremarks ${e.value.useCssAnimation ? "" : "vue-ui-dna"}`),
      style: U(`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(Ae, {
        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),
      ue.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", Ne, [
        (s(), I($e, {
          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(xe, {
        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: ie,
        onGeneratePdf: n(Y),
        onGenerateImage: n(q),
        onToggleAnnotator: T,
        style: U({
          visibility: n(D) ? n(M) ? "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", 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,
        ref_key: "svgRef",
        ref: ne,
        xmlns: n(be),
        class: G({ "vue-data-ui-fullscreen--on": O.value, "vue-data-ui-fulscreen--off": !O.value }),
        viewBox: `0 0 ${o.value.width} ${o.value.height}`,
        style: U(`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(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: G({ "vue-ui-tick-animated": e.value.style.chart.animation.use && l <= u.value })
          }, null, 10, Ge))), 256))
        ])) : (s(), c("g", Le, [
          (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, 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 ? 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
        }, de(n(_e)(
          e.value.style.chart.percentage.formatter,
          u.value,
          n(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", Be, [
        b(t.$slots, "watermark", L(j({ isPrinting: n(R) || n(V) })), void 0, !0)
      ])) : d("", !0),
      t.$slots.source ? (s(), c("div", Xe, [
        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(De, [["__scopeId", "data-v-85afd94d"]]);
export {
  tt as default
};
