import { ref as d, computed as g, onMounted as ce, watch as V, onBeforeUnmount as he, openBlock as r, createElementBlock as n, normalizeClass as q, normalizeStyle as X, createBlock as k, createCommentVNode as u, unref as v, createSlots as ve, withCtx as w, renderSlot as y, normalizeProps as I, guardReactiveProps as O, createVNode as de, Fragment as H, renderList as T, createElementVNode as x, toDisplayString as L } from "vue";
import { u as ge, o as fe, e as Y, g as me, c as ye, l as pe, D as be, d as ke, i as $, f as B, X as we, t as xe } from "./index-Cm2_6s9o.js";
import { u as J } from "./useNestedProp-BYPZJNhi.js";
import { _ as _e } from "./Title-Coit3NcT.js";
import { L as Ce } from "./Legend-DRozxv9L.js";
import { u as Le, U as $e } from "./usePrinter-Cx8U1e30.js";
import { _ as Be } from "./PackageVersion-CTMY4zeY.js";
import { P as Ae } from "./PenAndPaper-DJ_d10S-.js";
import Pe from "./vue-ui-skeleton-BUS6A44x.js";
import { _ as Fe } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Se = ["id"], Ie = {
  key: 1,
  ref: "noTitle",
  class: "vue-data-ui-no-title-space",
  style: "height:36px; width: 100%;background:transparent"
}, Oe = ["xmlns", "viewBox"], He = { key: 0 }, Te = ["x", "y", "height", "width", "fill", "stroke"], Ne = ["x", "y", "height", "width", "rx", "fill", "stroke", "stroke-width"], ze = ["x", "y", "height", "width", "fill", "stroke", "stroke-width"], Me = ["x", "y", "font-size", "font-weight", "fill"], Ue = ["x", "y", "height", "width", "rx", "fill", "stroke", "stroke-width"], We = { key: 3 }, Ee = ["x", "y", "fill", "font-size", "font-weight"], De = { key: 4 }, Re = ["x1", "x2", "y1", "y2", "stroke"], Ge = {
  key: 5,
  class: "vue-data-ui-watermark"
}, je = {
  class: "vue-ui-bullet-legend-item",
  dir: "auto"
}, Ve = { style: { "margin-right": "2px" } }, qe = {
  key: 7,
  ref: "source",
  dir: "auto"
}, Xe = {
  __name: "vue-ui-bullet",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  setup(K, { expose: Q }) {
    const o = K, { vue_ui_bullet: Z } = ge(), A = d(null), ee = d(null), N = d(0), te = d(null), ae = 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));
    ce(z);
    function z() {
      fe(o.dataset) ? Y({
        componentName: "VueUiBullet",
        type: "dataset"
      }) : p.value ? o.dataset.segments.forEach((t, s) => {
        me({
          datasetObject: t,
          requiredAttributes: ["name", "from", "to"]
        }).forEach((a) => {
          f.value = !1, Y({
            componentName: "VueUiBullet segment",
            type: "datasetSerieAttribute",
            property: a,
            index: s
          });
        });
      }) : f.value = !1, e.value.style.chart.animation.show && W(o.dataset.value || 0);
    }
    const P = d(ye());
    function M() {
      const t = J({
        userConfig: o.config,
        defaultConfig: Z
      });
      return t.theme ? {
        ...J({
          userConfig: xe.vue_ui_bullet[t.theme] || o.config,
          defaultConfig: t
        })
      } : t;
    }
    const e = g({
      get: () => M(),
      set: (t) => t
    });
    V(() => o.config, (t) => {
      e.value = M(), z(), N.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, h = t - e.value.style.chart.padding.bottom;
      return {
        height: t,
        width: s,
        left: a,
        right: m,
        top: C,
        bottom: h,
        chartWidth: m - a,
        chartHeight: h - C
      };
    }), le = g(() => {
      if (!p.value) return [];
      const t = [];
      for (let s = 0; s < o.dataset.segments.length; s += 1)
        t.push(pe(e.value.style.chart.segments.baseColor, s / o.dataset.segments.length));
      return t;
    }), F = 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 }), i = d(se());
    V(() => o.dataset, (t) => {
      e.value.style.chart.animation.show ? W(t.value || 0) : i.value = t.value || 0;
    }, { deep: !0 });
    function se() {
      return e.value.style.chart.animation.show ? F.value.min : o.dataset.value || 0;
    }
    const U = d(null);
    function W(t) {
      const s = Math.abs(t - i.value) / e.value.style.chart.animation.animationFrames;
      function a() {
        i.value < t ? i.value = Math.min(i.value + s, t) : i.value > t && (i.value = Math.max(i.value - s, t)), i.value !== t && (U.value = requestAnimationFrame(a));
      }
      a();
    }
    he(() => {
      cancelAnimationFrame(U.value);
    });
    const c = g(() => {
      if (!p.value)
        return [];
      const t = be(F.value.min, F.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: (i.value + s) / (t.max + s) * l.value.chartWidth
      }, C = t.ticks.map((h) => ({
        value: h,
        y: l.value.bottom + e.value.style.chart.segments.dataLabels.fontSize + 3 + e.value.style.chart.segments.dataLabels.offsetY,
        x: l.value.left + (h + s) / (t.max + s) * l.value.chartWidth
      }));
      return {
        scale: t,
        target: a,
        value: m,
        ticks: C,
        chunks: o.dataset.segments.map((h, ie) => ({
          ...h,
          color: h.color ? ke(h.color) : le.value[ie],
          x: l.value.left + l.value.chartWidth * ((h.from + s) / (t.max + s)),
          y: l.value.top,
          height: l.value.chartHeight,
          width: l.value.chartWidth * (Math.abs(h.to - h.from) / (t.max + s))
        }))
      };
    }), E = 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
        })
      ), 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}`
      };
    })), re = 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: D, isImaging: R, generatePdf: G, generateImage: j } = Le({
      elementId: `bullet_${P.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-bullet"
    }), oe = g(() => e.value.userOptions.show && !e.value.style.chart.title.text), b = d(!1);
    function ne(t) {
      b.value = t, ae.value += 1;
    }
    function ue() {
      return c.value;
    }
    const _ = d(!1);
    function S() {
      _.value = !_.value;
    }
    return Q({
      getData: ue,
      generatePdf: G,
      generateImage: j,
      toggleAnnotator: S
    }), (t, s) => (r(), n("div", {
      ref_key: "bulletChart",
      ref: A,
      class: q(`vue-ui-bullet ${b.value ? "vue-data-ui-wrapper-fullscreen" : ""}`),
      style: X(`font-family:${e.value.style.fontFamily};width:100%;background:${e.value.style.chart.backgroundColor}`),
      id: `bullet_${P.value}`
    }, [
      e.value.userOptions.buttons.annotator ? (r(), k(Ae, {
        key: 0,
        parent: A.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: _.value,
        onClose: S
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : u("", !0),
      oe.value ? (r(), n("div", Ie, null, 512)) : u("", !0),
      e.value.style.chart.title.text ? (r(), n("div", {
        key: 2,
        ref_key: "chartTitle",
        ref: ee,
        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)) : u("", !0),
      e.value.userOptions.show && f.value ? (r(), k($e, {
        key: 3,
        ref: "details",
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: v(D),
        isImaging: v(R),
        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: ne,
        onGeneratePdf: v(G),
        onGenerateImage: v(j),
        onToggleAnnotator: S
      }, ve({ _: 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(O({ 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(O({ 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"])) : u("", !0),
      f.value ? (r(), n("svg", {
        key: 4,
        xmlns: v(we),
        class: q({ "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: X(`width: 100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`)
      }, [
        de(Be),
        p.value ? (r(), n("g", He, [
          (r(!0), n(H, null, T(c.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, Te))), 256)),
          e.value.style.chart.target.onTop ? u("", !0) : (r(), n("rect", {
            key: 0,
            x: c.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, Ne)),
          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: 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, ze),
          e.value.style.chart.valueBar.label.show ? (r(), n("text", {
            key: 1,
            x: l.value.left + c.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(v($)(
            e.value.style.chart.segments.dataLabels.formatter,
            i.value,
            v(B)({
              p: e.value.style.chart.segments.dataLabels.prefix,
              v: i.value,
              s: e.value.style.chart.segments.dataLabels.suffix,
              r: e.value.style.chart.segments.dataLabels.rounding
            })
          )), 9, Me)) : u("", !0),
          e.value.style.chart.target.onTop ? (r(), n("rect", {
            key: 2,
            x: c.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, Ue)) : u("", !0),
          e.value.style.chart.segments.dataLabels.show ? (r(), n("g", We, [
            (r(!0), n(H, null, T(c.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(v($)(
              e.value.style.chart.segments.dataLabels.formatter,
              a.value,
              v(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, Ee))), 256))
          ])) : u("", !0),
          e.value.style.chart.segments.dataLabels.show && e.value.style.chart.segments.ticks.show ? (r(), n("g", De, [
            (r(!0), n(H, null, T(c.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, Re))), 256))
          ])) : u("", !0)
        ])) : u("", !0),
        y(t.$slots, "svg", { svg: l.value }, void 0, !0)
      ], 14, Oe)) : u("", !0),
      t.$slots.watermark ? (r(), n("div", Ge, [
        y(t.$slots, "watermark", I(O({ isPrinting: v(D) || v(R) })), void 0, !0)
      ])) : u("", !0),
      f.value ? u("", !0) : (r(), k(Pe, {
        key: 6,
        config: {
          type: "bullet",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            bullet: {
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"])),
      x("div", {
        ref_key: "chartLegend",
        ref: te
      }, [
        e.value.style.chart.legend.show ? (r(), k(Ce, {
          key: 0,
          clickable: !1,
          legendSet: E.value,
          config: re.value
        }, {
          item: w(({ legend: a }) => [
            x("div", je, [
              x("span", Ve, L(a.name) + ":", 1),
              x("span", null, L(a.value), 1)
            ])
          ]),
          _: 1
        }, 8, ["legendSet", "config"])) : u("", !0),
        y(t.$slots, "legend", { legend: E.value }, void 0, !0)
      ], 512),
      t.$slots.source ? (r(), n("div", qe, [
        y(t.$slots, "source", {}, void 0, !0)
      ], 512)) : u("", !0)
    ], 14, Se));
  }
}, rt = /* @__PURE__ */ Fe(Xe, [["__scopeId", "data-v-cfe188c3"]]);
export {
  rt as default
};
