import { ref as d, computed as g, onMounted as de, watch as J, onBeforeUnmount as ge, openBlock as r, createElementBlock as o, normalizeClass as K, normalizeStyle as I, unref as u, createBlock as k, createCommentVNode as i, createSlots as fe, withCtx as w, renderSlot as f, normalizeProps as H, guardReactiveProps as M, createVNode as me, Fragment as T, renderList as U, createElementVNode as x, toDisplayString as L } from "vue";
import { u as ye, o as pe, e as Q, g as be, c as ke, l as we, D as xe, d as _e, i as $, f as B, X as Ce, t as Le } from "./index-MWHrTFPq.js";
import { u as Z } from "./useNestedProp-CTDeT4KA.js";
import { _ as $e } from "./Title-C7EOYmwp.js";
import { L as Be } from "./Legend-CUhyETYn.js";
import { u as Oe, U as Ae } from "./usePrinter-CEEgHfhF.js";
import { _ as Pe } from "./PackageVersion-CBKqLhAX.js";
import { P as Fe } from "./PenAndPaper-DtLD2Sq6.js";
import Se from "./vue-ui-skeleton-Bo8ydREb.js";
import { u as Ie } from "./useUserOptionState-BIvW1Kz7.js";
import { _ as He } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Me = ["id"], Te = {
  key: 1,
  ref: "noTitle",
  class: "vue-data-ui-no-title-space",
  style: "height:36px; width: 100%;background:transparent"
}, Ue = ["xmlns", "viewBox"], Ne = ["width", "height"], ze = { key: 1 }, We = ["x", "y", "height", "width", "fill", "stroke"], Ee = ["x", "y", "height", "width", "rx", "fill", "stroke", "stroke-width"], De = ["x", "y", "height", "width", "fill", "stroke", "stroke-width"], Re = ["x", "y", "font-size", "font-weight", "fill"], Ve = ["x", "y", "height", "width", "rx", "fill", "stroke", "stroke-width"], je = { key: 3 }, Ge = ["x", "y", "fill", "font-size", "font-weight"], qe = { key: 4 }, Xe = ["x1", "x2", "y1", "y2", "stroke"], Ye = {
  key: 5,
  class: "vue-data-ui-watermark"
}, Je = {
  class: "vue-ui-bullet-legend-item",
  dir: "auto"
}, Ke = { style: { "margin-right": "2px" } }, Qe = {
  key: 7,
  ref: "source",
  dir: "auto"
}, Ze = {
  __name: "vue-ui-bullet",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(ee, { expose: te }) {
    const n = ee, { vue_ui_bullet: ae } = ye(), O = d(null), le = d(null), N = d(0), se = d(null), re = d(0), m = g({
      get: () => n.dataset.hasOwnProperty("value"),
      set: (t) => t
    }), p = g(() => n.dataset.segments ? Array.isArray(n.dataset.segments) ? n.dataset.segments.length ? !0 : (console.warn(`VueUiBullet: dataset segments is empty. Provide segments with this datastructure:

segments: [
    {
        name: string;
        from: number;
        to: number;
        color?: string;
    },
    {...}
]
        `), m.value = !1, !1) : (console.warn(`VueUiBullet: dataset segments must be an array of objects with this datastructure:

segments: [
    {
        name: string;
        from: number;
        to: number;
        color?: string;
    },
    {...}
] 
        `), m.value = !1, !1) : (console.warn(`VueUiBullet: dataset segments is empty. Provide segments with this datastructure:

segments: [
    {
        name: string;
        from: number;
        to: number;
        color?: string;
    },
    {...}
]
        `), m.value = !1, !1));
    de(z);
    function z() {
      pe(n.dataset) ? Q({
        componentName: "VueUiBullet",
        type: "dataset"
      }) : p.value ? n.dataset.segments.forEach((t, s) => {
        be({
          datasetObject: t,
          requiredAttributes: ["name", "from", "to"]
        }).forEach((l) => {
          m.value = !1, Q({
            componentName: "VueUiBullet segment",
            type: "datasetSerieAttribute",
            property: l,
            index: s
          });
        });
      }) : m.value = !1, e.value.style.chart.animation.show && V(n.dataset.value || 0);
    }
    const A = d(ke());
    function W() {
      const t = Z({
        userConfig: n.config,
        defaultConfig: ae
      });
      return t.theme ? {
        ...Z({
          userConfig: Le.vue_ui_bullet[t.theme] || n.config,
          defaultConfig: t
        })
      } : t;
    }
    const e = g({
      get: () => W(),
      set: (t) => t
    }), { userOptionsVisible: P, setUserOptionsVisibility: E, keepUserOptionState: D } = Ie({ config: e.value });
    J(() => n.config, (t) => {
      e.value = W(), P.value = !e.value.showOnChartHover, z(), N.value += 1;
    }, { deep: !0 });
    const a = g(() => {
      const t = e.value.style.chart.height, s = e.value.style.chart.width, l = e.value.style.chart.padding.left, y = s - e.value.style.chart.padding.right, C = e.value.style.chart.padding.top, v = t - e.value.style.chart.padding.bottom;
      return {
        height: t,
        width: s,
        left: l,
        right: y,
        top: C,
        bottom: v,
        chartWidth: y - l,
        chartHeight: v - C
      };
    }), oe = g(() => {
      if (!p.value) return [];
      const t = [];
      for (let s = 0; s < n.dataset.segments.length; s += 1)
        t.push(we(e.value.style.chart.segments.baseColor, s / n.dataset.segments.length));
      return t;
    }), F = g(() => p.value ? {
      min: Math.min(...n.dataset.segments.map((t) => t.from)),
      max: Math.max(...n.dataset.segments.map((t) => t.to))
    } : { min: 0, max: 1 }), h = d(ne());
    J(() => n.dataset, (t) => {
      e.value.style.chart.animation.show ? V(t.value || 0) : h.value = t.value || 0;
    }, { deep: !0 });
    function ne() {
      return e.value.style.chart.animation.show ? F.value.min : n.dataset.value || 0;
    }
    const R = d(null);
    function V(t) {
      const s = Math.abs(t - h.value) / e.value.style.chart.animation.animationFrames;
      function l() {
        h.value < t ? h.value = Math.min(h.value + s, t) : h.value > t && (h.value = Math.max(h.value - s, t)), h.value !== t && (R.value = requestAnimationFrame(l));
      }
      l();
    }
    ge(() => {
      cancelAnimationFrame(R.value);
    });
    const c = g(() => {
      if (!p.value)
        return [];
      const t = xe(F.value.min, F.value.max, e.value.style.chart.segments.ticks.divisions), s = t.min >= 0 ? 0 : Math.abs(t.min), l = {
        x: a.value.left + (n.dataset.target + s) / (t.max + s) * a.value.chartWidth - e.value.style.chart.target.width / 2
      }, y = {
        width: (h.value + s) / (t.max + s) * a.value.chartWidth
      }, C = t.ticks.map((v) => ({
        value: v,
        y: a.value.bottom + e.value.style.chart.segments.dataLabels.fontSize + 3 + e.value.style.chart.segments.dataLabels.offsetY,
        x: a.value.left + (v + s) / (t.max + s) * a.value.chartWidth
      }));
      return {
        scale: t,
        target: l,
        value: y,
        ticks: C,
        chunks: n.dataset.segments.map((v, ve) => ({
          ...v,
          color: v.color ? _e(v.color) : oe.value[ve],
          x: a.value.left + a.value.chartWidth * ((v.from + s) / (t.max + s)),
          y: a.value.top,
          height: a.value.chartHeight,
          width: a.value.chartWidth * (Math.abs(v.to - v.from) / (t.max + s))
        }))
      };
    }), j = g(() => !c.value || !c.value.chunks || !c.value.chunks.length ? [] : c.value.chunks.map((t) => {
      const s = $(
        e.value.style.chart.segments.dataLabels.formatter,
        t.from,
        B({
          p: e.value.style.chart.segments.dataLabels.prefix,
          v: t.from,
          s: e.value.style.chart.segments.dataLabels.suffix,
          r: e.value.style.chart.segments.dataLabels.rounding
        })
      ), l = $(
        e.value.style.chart.segments.dataLabels.formatter,
        t.to,
        B({
          p: e.value.style.chart.segments.dataLabels.prefix,
          v: t.to,
          s: e.value.style.chart.segments.dataLabels.suffix,
          r: e.value.style.chart.segments.dataLabels.rounding
        })
      );
      return {
        ...t,
        shape: "square",
        value: `${s} - ${l}`
      };
    })), ue = g(() => ({
      cy: "bullet-div-legend",
      backgroundColor: "transparent",
      color: e.value.style.chart.legend.color,
      fontSize: e.value.style.chart.legend.fontSize,
      paddingBottom: 6,
      fontWeight: e.value.style.chart.legend.bold ? "bold" : ""
    })), { isPrinting: G, isImaging: q, generatePdf: X, generateImage: Y } = Oe({
      elementId: `bullet_${A.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-bullet"
    }), ie = g(() => e.value.userOptions.show && !e.value.style.chart.title.text), b = d(!1);
    function he(t) {
      b.value = t, re.value += 1;
    }
    function ce() {
      return c.value;
    }
    const _ = d(!1);
    function S() {
      _.value = !_.value;
    }
    return te({
      getData: ce,
      generatePdf: X,
      generateImage: Y,
      toggleAnnotator: S
    }), (t, s) => (r(), o("div", {
      ref_key: "bulletChart",
      ref: O,
      class: K(`vue-ui-bullet ${b.value ? "vue-data-ui-wrapper-fullscreen" : ""}`),
      style: I(`font-family:${e.value.style.fontFamily};width:100%;background:${e.value.style.chart.backgroundColor}`),
      id: `bullet_${A.value}`,
      onMouseenter: s[0] || (s[0] = () => u(E)(!0)),
      onMouseleave: s[1] || (s[1] = () => u(E)(!1))
    }, [
      e.value.userOptions.buttons.annotator ? (r(), k(Fe, {
        key: 0,
        parent: O.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: _.value,
        onClose: S
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : i("", !0),
      ie.value ? (r(), o("div", Te, null, 512)) : i("", !0),
      e.value.style.chart.title.text ? (r(), o("div", {
        key: 2,
        ref_key: "chartTitle",
        ref: le,
        style: "width:100%;background:transparent;"
      }, [
        (r(), k($e, {
          lineHeight: "1.3rem",
          key: `title_${N.value}`,
          config: {
            title: {
              cy: "bullet-div-title",
              ...e.value.style.chart.title
            },
            subtitle: {
              cy: "bullet-div-subtitle",
              ...e.value.style.chart.title.subtitle
            }
          }
        }, null, 8, ["config"]))
      ], 512)) : i("", !0),
      e.value.userOptions.show && m.value && (u(D) || u(P)) ? (r(), k(Ae, {
        key: 3,
        ref: "details",
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: u(G),
        isImaging: u(q),
        uid: A.value,
        hasTooltip: !1,
        hasPdf: e.value.userOptions.buttons.pdf,
        hasImg: e.value.userOptions.buttons.img,
        hasXls: !1,
        hasTable: !1,
        hasLabel: !1,
        hasFullscreen: e.value.userOptions.buttons.fullscreen,
        isFullscreen: b.value,
        chartElement: O.value,
        position: e.value.userOptions.position,
        titles: { ...e.value.userOptions.buttonTitles },
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: _.value,
        onToggleFullscreen: he,
        onGeneratePdf: u(X),
        onGenerateImage: u(Y),
        onToggleAnnotator: S,
        style: I({
          visibility: u(D) ? u(P) ? "visible" : "hidden" : "visible"
        })
      }, fe({ _: 2 }, [
        t.$slots.optionPdf ? {
          name: "optionPdf",
          fn: w(() => [
            f(t.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        t.$slots.optionImg ? {
          name: "optionImg",
          fn: w(() => [
            f(t.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        t.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: w(({ toggleFullscreen: l, isFullscreen: y }) => [
            f(t.$slots, "optionFullscreen", H(M({ toggleFullscreen: l, isFullscreen: y })), void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: w(({ toggleAnnotator: l, isAnnotator: y }) => [
            f(t.$slots, "optionAnnotator", H(M({ toggleAnnotator: l, isAnnotator: y })), void 0, !0)
          ]),
          key: "3"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "chartElement", "position", "titles", "hasAnnotator", "isAnnotation", "onGeneratePdf", "onGenerateImage", "style"])) : i("", !0),
      m.value ? (r(), o("svg", {
        key: 4,
        xmlns: u(Ce),
        class: K({ "vue-data-ui-fullscreen--on": b.value, "vue-data-ui-fulscreen--off": !b.value, "vue-ui-bullet-svg": !0 }),
        viewBox: `0 0 ${a.value.width} ${a.value.height}`,
        style: I(`width: 100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`)
      }, [
        me(Pe),
        t.$slots["chart-background"] ? (r(), o("foreignObject", {
          key: 0,
          x: 0,
          y: 0,
          width: a.value.width,
          height: a.value.height,
          style: {
            pointerEvents: "none"
          }
        }, [
          f(t.$slots, "chart-background", {}, void 0, !0)
        ], 8, Ne)) : i("", !0),
        p.value ? (r(), o("g", ze, [
          (r(!0), o(T, null, U(c.value.chunks, (l) => (r(), o("rect", {
            x: l.x,
            y: l.y,
            height: l.height,
            width: l.width,
            fill: l.color,
            "stroke-width": 1,
            stroke: e.value.style.chart.backgroundColor
          }, null, 8, We))), 256)),
          e.value.style.chart.target.onTop ? i("", !0) : (r(), o("rect", {
            key: 0,
            x: c.value.target.x,
            y: a.value.top + (a.value.chartHeight - a.value.chartHeight * e.value.style.chart.target.heightRatio) / 2,
            height: a.value.chartHeight * e.value.style.chart.target.heightRatio,
            width: e.value.style.chart.target.width,
            rx: e.value.style.chart.target.rounded ? e.value.style.chart.target.width / 2 : 0,
            fill: e.value.style.chart.target.color,
            stroke: e.value.style.chart.target.stroke,
            "stroke-width": e.value.style.chart.target.strokeWidth
          }, null, 8, Ee)),
          x("rect", {
            x: a.value.left,
            y: a.value.top + (a.value.chartHeight - a.value.chartHeight * e.value.style.chart.valueBar.heightRatio) / 2,
            height: a.value.chartHeight * e.value.style.chart.valueBar.heightRatio,
            width: c.value.value.width,
            fill: e.value.style.chart.valueBar.color,
            stroke: e.value.style.chart.valueBar.stroke,
            "stroke-width": e.value.style.chart.valueBar.strokeWidth
          }, null, 8, De),
          e.value.style.chart.valueBar.label.show ? (r(), o("text", {
            key: 1,
            x: a.value.left + c.value.value.width,
            y: a.value.top - 6 + e.value.style.chart.valueBar.label.offsetY,
            "font-size": e.value.style.chart.valueBar.label.fontSize,
            "font-weight": e.value.style.chart.valueBar.label.bold ? "bold" : "normal",
            fill: e.value.style.chart.valueBar.label.color,
            "text-anchor": "middle"
          }, L(u($)(
            e.value.style.chart.segments.dataLabels.formatter,
            h.value,
            u(B)({
              p: e.value.style.chart.segments.dataLabels.prefix,
              v: h.value,
              s: e.value.style.chart.segments.dataLabels.suffix,
              r: e.value.style.chart.segments.dataLabels.rounding
            })
          )), 9, Re)) : i("", !0),
          e.value.style.chart.target.onTop ? (r(), o("rect", {
            key: 2,
            x: c.value.target.x,
            y: a.value.top + (a.value.chartHeight - a.value.chartHeight * e.value.style.chart.target.heightRatio) / 2,
            height: a.value.chartHeight * e.value.style.chart.target.heightRatio,
            width: e.value.style.chart.target.width,
            rx: e.value.style.chart.target.rounded ? e.value.style.chart.target.width / 2 : 0,
            fill: e.value.style.chart.target.color,
            stroke: e.value.style.chart.target.stroke,
            "stroke-width": e.value.style.chart.target.strokeWidth
          }, null, 8, Ve)) : i("", !0),
          e.value.style.chart.segments.dataLabels.show ? (r(), o("g", je, [
            (r(!0), o(T, null, U(c.value.ticks, (l) => (r(), o("text", {
              x: l.x,
              y: l.y,
              "text-anchor": "middle",
              fill: e.value.style.chart.segments.dataLabels.color,
              "font-size": e.value.style.chart.segments.dataLabels.fontSize + "px",
              "font-weight": e.value.style.chart.segments.dataLabels.bold ? "bold" : "normal"
            }, L(u($)(
              e.value.style.chart.segments.dataLabels.formatter,
              l.value,
              u(B)({
                p: e.value.style.chart.segments.dataLabels.prefix,
                v: l.value,
                s: e.value.style.chart.segments.dataLabels.suffix,
                r: e.value.style.chart.segments.dataLabels.rounding
              })
            )), 9, Ge))), 256))
          ])) : i("", !0),
          e.value.style.chart.segments.dataLabels.show && e.value.style.chart.segments.ticks.show ? (r(), o("g", qe, [
            (r(!0), o(T, null, U(c.value.ticks, (l) => (r(), o("line", {
              x1: l.x,
              x2: l.x,
              y1: a.value.bottom,
              y2: a.value.bottom + 3,
              stroke: e.value.style.chart.segments.ticks.stroke,
              "stroke-width": 1,
              "stroke-linecap": "round"
            }, null, 8, Xe))), 256))
          ])) : i("", !0)
        ])) : i("", !0),
        f(t.$slots, "svg", { svg: a.value }, void 0, !0)
      ], 14, Ue)) : i("", !0),
      t.$slots.watermark ? (r(), o("div", Ye, [
        f(t.$slots, "watermark", H(M({ isPrinting: u(G) || u(q) })), void 0, !0)
      ])) : i("", !0),
      m.value ? i("", !0) : (r(), k(Se, {
        key: 6,
        config: {
          type: "bullet",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            bullet: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"])),
      x("div", {
        ref_key: "chartLegend",
        ref: se
      }, [
        e.value.style.chart.legend.show ? (r(), k(Be, {
          key: 0,
          clickable: !1,
          legendSet: j.value,
          config: ue.value
        }, {
          item: w(({ legend: l }) => [
            x("div", Je, [
              x("span", Ke, L(l.name) + ":", 1),
              x("span", null, L(l.value), 1)
            ])
          ]),
          _: 1
        }, 8, ["legendSet", "config"])) : i("", !0),
        f(t.$slots, "legend", { legend: j.value }, void 0, !0)
      ], 512),
      t.$slots.source ? (r(), o("div", Qe, [
        f(t.$slots, "source", {}, void 0, !0)
      ], 512)) : i("", !0)
    ], 46, Me));
  }
}, ct = /* @__PURE__ */ He(Ze, [["__scopeId", "data-v-f3c3067f"]]);
export {
  ct as default
};
