import { ref as d, computed as g, onMounted as de, watch as J, onBeforeUnmount as ge, openBlock as r, createElementBlock as n, normalizeClass as K, normalizeStyle as S, unref as u, createBlock as k, createCommentVNode as i, createSlots as fe, withCtx as w, renderSlot as y, normalizeProps as I, guardReactiveProps as H, createVNode as me, Fragment as M, renderList as T, 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-BbPeL8Gp.js";
import { u as Z } from "./useNestedProp-BN8claGG.js";
import { _ as $e } from "./Title-aSAft5dl.js";
import { L as Be } from "./Legend-BLaZxMge.js";
import { u as Ae, U as Pe } from "./usePrinter-DaybDVqP.js";
import { _ as Oe } from "./PackageVersion-CxJghxYD.js";
import { P as Fe } from "./PenAndPaper-ZdZEumki.js";
import Se from "./vue-ui-skeleton-Bniq21d9.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 = { key: 0 }, ze = ["x", "y", "height", "width", "fill", "stroke"], We = ["x", "y", "height", "width", "rx", "fill", "stroke", "stroke-width"], Ee = ["x", "y", "height", "width", "fill", "stroke", "stroke-width"], De = ["x", "y", "font-size", "font-weight", "fill"], Re = ["x", "y", "height", "width", "rx", "fill", "stroke", "stroke-width"], Ve = { key: 3 }, Ge = ["x", "y", "fill", "font-size", "font-weight"], je = { key: 4 }, qe = ["x1", "x2", "y1", "y2", "stroke"], Xe = {
  key: 5,
  class: "vue-data-ui-watermark"
}, Ye = {
  class: "vue-ui-bullet-legend-item",
  dir: "auto"
}, Je = { style: { "margin-right": "2px" } }, Ke = {
  key: 7,
  ref: "source",
  dir: "auto"
}, Qe = {
  __name: "vue-ui-bullet",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(ee, { expose: te }) {
    const o = ee, { vue_ui_bullet: ae } = ye(), A = d(null), le = d(null), U = d(0), se = d(null), re = d(0), f = g({
      get: () => o.dataset.hasOwnProperty("value"),
      set: (t) => t
    }), p = g(() => o.dataset.segments ? Array.isArray(o.dataset.segments) ? o.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;
    },
    {...}
]
        `), f.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;
    },
    {...}
] 
        `), f.value = !1, !1) : (console.warn(`VueUiBullet: dataset segments is empty. Provide segments with this datastructure:

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