import { computed as h, ref as f, watch as W, onMounted as ce, openBlock as s, createElementBlock as c, normalizeClass as T, normalizeStyle as U, unref as n, createBlock as I, createCommentVNode as y, createSlots as ve, withCtx as F, renderSlot as b, normalizeProps as G, guardReactiveProps as L, createVNode as he, Fragment as Z, renderList as ee, toDisplayString as de } from "vue";
import { u as te } from "./useNestedProp-BN8claGG.js";
import { u as pe, c as fe, t as ye, v as me, o as ge, e as ke, w as ae, X as be, i as _e, f as Ce } from "./index-BbPeL8Gp.js";
import { _ as $e } from "./Title-aSAft5dl.js";
import { u as we, U as xe } from "./usePrinter-DaybDVqP.js";
import Pe from "./vue-ui-skeleton-Bniq21d9.js";
import { _ as Ae } from "./PackageVersion-CxJghxYD.js";
import { P as Oe } from "./PenAndPaper-ZdZEumki.js";
import { u as Ie } from "./useUserOptionState-BIvW1Kz7.js";
import { _ as Fe } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const ze = ["id"], Se = {
  key: 2,
  style: "width:100%;background:transparent;padding-bottom:12px"
}, Ne = ["xmlns", "viewBox"], Me = { key: 0 }, Te = ["d", "stroke-width", "stroke"], Ue = { key: 1 }, 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"
}, Be = {
  key: 6,
  ref: "source",
  dir: "auto"
}, Ee = {
  __name: "vue-ui-tiremarks",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(le, { expose: oe }) {
    const d = le, { vue_ui_tiremarks: se } = pe(), z = h(() => !!d.dataset && Object.keys(d.dataset).length), S = f(fe()), N = f(null), re = f(null), j = f(0), B = f(0), e = h({
      get: () => H(),
      set: (t) => t
    }), { userOptionsVisible: E, setUserOptionsVisibility: X, keepUserOptionState: D } = Ie({ config: e.value });
    function H() {
      const t = te({
        userConfig: d.config,
        defaultConfig: se
      });
      return t.theme ? {
        ...te({
          userConfig: ye.vue_ui_tiremarks[t.theme] || d.config,
          defaultConfig: t
        })
      } : t;
    }
    W(() => d.config, (t) => {
      e.value = H(), 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"
    }), ne = h(() => e.value.userOptions.show && !e.value.style.chart.title.text), u = f(e.value.style.chart.animation.use ? 0 : me(d.dataset.percentage));
    W(() => d.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 o() {
        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(o);
      }
      o();
    }
    function K() {
      ge(d.dataset) && ke({
        componentName: "VueUiTiremarks",
        type: "dataset"
      }), J(d.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)), l = h(() => ({
      height: _.value ? 312 : 56,
      width: _.value ? 56 : 312
    })), ue = f(100);
    h(() => d.dataset.percentage / ue.value);
    const v = h(() => _.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
    }), Q = h(() => {
      const t = [];
      for (let a = 0; a < 100; a += 1) {
        const o = 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) * (l.value.width - i.value.left - i.value.right) / 100 / 3 : 0, p = i.value.left + 4 + $, m = l.value.width - i.value.right - 4 - $, g = l.value.height - i.value.bottom - a * v.value.mark - a * v.value.space - v.value.mark, k = l.value.height - i.value.bottom - a * v.value.mark - a * v.value.space - v.value.mark, w = (m - p) / e.value.style.chart.layout.curveAngleX, x = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100);
          t.push({
            x1: p,
            x2: m,
            y1: g,
            y2: k,
            curve: `M ${p} ${g} C ${p + w} ${g - x}, ${m - w} ${k - x}, ${m} ${k}`,
            color: o
          });
        } else {
          const $ = e.value.style.chart.layout.crescendo ? (100 - a) * (l.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, m = p, g = i.value.top + 4 + $, k = l.value.height - i.value.bottom - 4 - $, w = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100), x = (k - g) / e.value.style.chart.layout.curveAngleX;
          t.push({
            x1: p,
            x2: m,
            y1: g,
            y2: k,
            curve: `M ${p} ${g} C ${p + w} ${g + x}, ${m + w} ${k - x}, ${m} ${k}`,
            color: o
          });
        }
      }
      return t;
    }), C = h(() => {
      let t, r, a;
      const o = e.value.style.chart.percentage.fontSize / 3;
      return _.value ? e.value.style.chart.percentage.verticalPosition === "top" ? (t = l.value.width / 2, r = i.value.top / 2, a = "middle") : e.value.style.chart.percentage.verticalPosition === "bottom" && (t = l.value.width / 2, r = l.value.height - i.value.bottom / 2 + o, a = "middle") : e.value.style.chart.percentage.horizontalPosition === "left" ? (t = 4, r = l.value.height / 2 + o, a = "start") : e.value.style.chart.percentage.horizontalPosition === "right" && (t = l.value.width - i.value.right + 8, r = l.value.height / 2 + o, 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
      };
    }), A = f(!1);
    function ie(t) {
      A.value = t, j.value += 1;
    }
    const O = f(!1);
    function M() {
      O.value = !O.value;
    }
    return oe({
      generatePdf: Y,
      generateImage: q,
      toggleAnnotator: M
    }), (t, r) => (s(), c("div", {
      ref_key: "tiremarksChart",
      ref: N,
      class: T(`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(Oe, {
        key: 0,
        parent: N.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: O.value,
        onClose: M
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : y("", !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)) : y("", !0),
      e.value.style.chart.title.text ? (s(), c("div", Se, [
        (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"]))
      ])) : y("", !0),
      e.value.userOptions.show && z.value && (n(D) || n(E)) ? (s(), I(xe, {
        ref: "details",
        key: `user_options_${j.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: A.value,
        titles: { ...e.value.userOptions.buttonTitles },
        chartElement: N.value,
        position: e.value.userOptions.position,
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: O.value,
        onToggleFullscreen: ie,
        onGeneratePdf: n(Y),
        onGenerateImage: n(q),
        onToggleAnnotator: M,
        style: U({
          visibility: n(D) ? n(E) ? "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: o }) => [
            b(t.$slots, "optionFullscreen", G(L({ toggleFullscreen: a, isFullscreen: o })), void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: F(({ toggleAnnotator: a, isAnnotator: o }) => [
            b(t.$slots, "optionAnnotator", G(L({ toggleAnnotator: a, isAnnotator: o })), 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"])) : y("", !0),
      z.value ? (s(), c("svg", {
        key: 4,
        xmlns: n(be),
        class: T({ "vue-data-ui-fullscreen--on": A.value, "vue-data-ui-fulscreen--off": !A.value }),
        viewBox: `0 0 ${l.value.width} ${l.value.height}`,
        style: U(`max-width:100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`)
      }, [
        he(Ae),
        e.value.style.chart.layout.curved ? (s(), c("g", Me, [
          (s(!0), c(Z, null, ee(Q.value, (a, o) => (s(), c("path", {
            d: a.curve,
            "stroke-width": v.value.mark,
            stroke: u.value >= o ? a.color : e.value.style.chart.layout.inactiveColor,
            "stroke-linecap": "round",
            fill: "none",
            class: T({ "vue-ui-tick-animated": e.value.style.chart.animation.use && o <= u.value })
          }, null, 10, Te))), 256))
        ])) : (s(), c("g", Ue, [
          (s(!0), c(Z, null, ee(Q.value, (a, o) => (s(), c("line", {
            x1: a.x1,
            y1: a.y1,
            x2: a.x2,
            y2: a.y2,
            "stroke-width": v.value.mark,
            stroke: u.value >= o ? 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: 2,
          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, Le)) : y("", !0),
        b(t.$slots, "svg", { svg: l.value }, void 0, !0)
      ], 14, Ne)) : y("", !0),
      t.$slots.watermark ? (s(), c("div", je, [
        b(t.$slots, "watermark", G(L({ isPrinting: n(R) || n(V) })), void 0, !0)
      ])) : y("", !0),
      t.$slots.source ? (s(), c("div", Be, [
        b(t.$slots, "source", {}, void 0, !0)
      ], 512)) : y("", !0),
      z.value ? y("", !0) : (s(), I(Pe, {
        key: 7,
        config: {
          type: "tiremarks",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            tiremarks: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"]))
    ], 46, ze));
  }
}, We = /* @__PURE__ */ Fe(Ee, [["__scopeId", "data-v-d5780415"]]);
export {
  We as default
};
