import { useCssVars as Ee, computed as y, createElementBlock as v, openBlock as r, createElementVNode as S, renderSlot as i, createVNode as ne, normalizeStyle as q, ref as n, watch as se, onMounted as Ge, onBeforeUnmount as Le, unref as d, createBlock as P, createCommentVNode as w, createSlots as Xe, withCtx as m, normalizeProps as M, guardReactiveProps as _, normalizeClass as ke, Fragment as je, renderList as qe, toDisplayString as we, createTextVNode as He, nextTick as $e } from "vue";
import { u as Ye, a4 as Je, v as Ke, c as xe, t as Qe, p as j, a as Ze, o as et, e as Te, g as tt, f as ot, X as at, q as lt, r as st, x as nt } from "./index-CjXfhpMA.js";
import { _ as rt } from "./Title-BfzkycPl.js";
import { u as ut, U as it } from "./usePrinter-bLtFFBkj.js";
import { d as ct, t as dt, u as vt } from "./useResponsive-BWapHhVH.js";
import ht from "./vue-ui-accordion-CEdZMQD4.js";
import { D as mt } from "./DataTable-BfXSoPx-.js";
import ft from "./BaseIcon-C8FyAN0p.js";
import { _ as Fe } from "./_plugin-vue_export-helper-CHgC5LLL.js";
import { u as Se } from "./useNestedProp-CmXi5M93.js";
import { _ as pt } from "./PackageVersion-ChIRiDpv.js";
import { _ as gt } from "./Tooltip-p85hmQvg.js";
import { P as yt } from "./PenAndPaper-OV0eQPcd.js";
import { u as bt } from "./useUserOptionState-BIvW1Kz7.js";
import { u as Ct } from "./useChartAccessibility-BWojgys7.js";
const kt = { "data-html2canvas-ignore": "" }, wt = {
  key: 0,
  class: "reset-wrapper"
}, $t = {
  key: 1,
  class: "reset-wrapper"
}, xt = { class: "mono-slicer" }, Tt = ["min", "max", "value"], St = {
  __name: "MonoSlicer",
  props: {
    min: {
      type: Number,
      default: 0
    },
    max: {
      type: Number,
      default: 0
    },
    inputColor: {
      type: String,
      default: "#1A1A1A"
    },
    background: {
      type: String,
      default: "#FFFFFF"
    },
    borderColor: {
      type: String,
      default: "#FFFFFF"
    },
    selectColor: {
      type: String,
      default: "#4A4A4A"
    },
    textColor: {
      type: String,
      default: "#1A1A1A"
    },
    useResetSlot: {
      type: Boolean,
      default: !1
    },
    value: {
      type: Number,
      default: 0
    },
    source: {
      type: Number,
      default: 0
    }
  },
  emits: ["update:value", "reset"],
  setup(f, { emit: H }) {
    Ee((T) => ({
      "782b8172": h.value,
      "102109e6": I.value,
      "642212d7": x.value,
      "1f5369d4": f.selectColor,
      "22b98ab8": F.value
    }));
    const p = f, h = y(() => p.inputColor), F = y(() => p.background), x = y(() => `${p.selectColor}33`), I = y(() => p.borderColor), R = H;
    function C() {
      R("reset");
    }
    const V = y(() => {
      const T = p.max - p.min, b = 0, N = (p.value - p.min) / T * 100;
      return {
        left: `${b}%`,
        width: `${N - b}%`,
        background: p.selectColor
      };
    });
    return (T, b) => (r(), v("div", kt, [
      f.value !== f.source ? (r(), v("div", wt, [
        f.useResetSlot ? i(T.$slots, "reset-action", {
          key: 1,
          reset: C
        }, void 0, !0) : (r(), v("button", {
          key: 0,
          "data-cy-reset": "",
          tabindex: "0",
          role: "button",
          class: "vue-data-ui-refresh-button",
          onClick: C
        }, [
          ne(ft, {
            name: "refresh",
            stroke: f.textColor
          }, null, 8, ["stroke"])
        ]))
      ])) : (r(), v("div", $t)),
      S("div", xt, [
        b[1] || (b[1] = S("div", { class: "slider-track" }, null, -1)),
        S("div", {
          class: "range-highlight",
          style: q(V.value)
        }, null, 4),
        S("input", {
          type: "range",
          min: f.min,
          max: f.max,
          value: Number(f.value),
          onInput: b[0] || (b[0] = (N) => R("update:value", Number(N.target.value)))
        }, null, 40, Tt)
      ])
    ]));
  }
}, Ft = /* @__PURE__ */ Fe(St, [["__scopeId", "data-v-b4e6aee9"]]), Nt = ["id"], zt = ["xmlns", "viewBox"], At = ["width", "height"], Ot = ["transform"], Pt = ["fill", "font-weight", "x", "y", "font-size", "transform", "onMouseover"], Mt = {
  key: 4,
  class: "vue-data-ui-watermark"
}, _t = ["innerHTML"], It = {
  __name: "vue-ui-word-cloud",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: [Array, String],
      default() {
        return [];
      }
    }
  },
  setup(f, { expose: H }) {
    const { vue_ui_word_cloud: p } = Ye(), h = f, F = y({
      get() {
        return !!h.dataset && h.dataset.length;
      },
      set(t) {
        return t;
      }
    }), x = n(typeof h.dataset == "string" ? Je(h.dataset) : h.dataset.map((t, a) => ({
      ...t,
      value: Ke(t.value)
    }))), I = n(xe()), R = n(0), C = n(null), V = n(null), T = n(null), b = n(0), N = n(0), Y = n(!1), e = y({
      get: () => ie(),
      set: (t) => t
    }), { userOptionsVisible: J, setUserOptionsVisibility: re, keepUserOptionState: ue } = bt({ config: e.value }), { svgRef: Ne } = Ct({ config: e.value.style.chart.title });
    function ie() {
      const t = Se({
        userConfig: h.config,
        defaultConfig: p
      });
      return t.theme ? {
        ...Se({
          userConfig: Ze.vue_ui_word_cloud[t.theme] || h.config,
          defaultConfig: t
        }),
        customPalette: Qe[t.theme] || j
      } : t;
    }
    se(() => h.config, (t) => {
      e.value = ie(), J.value = !e.value.userOptions.showOnChartHover, de(), b.value += 1, N.value += 1, K(), c.value.showTable = e.value.table.show, c.value.showTooltip = e.value.style.chart.tooltip.show;
    }, { deep: !0 });
    const ce = n(null), z = n(0), s = n({
      width: e.value.style.chart.width,
      height: e.value.style.chart.height,
      maxFontSize: e.value.style.chart.words.maxFontSize,
      minFontSize: e.value.style.chart.words.minFontSize
    }), ze = dt(() => {
      const { width: t, height: a } = vt({
        chart: C.value,
        title: e.value.style.chart.title.text ? V.value : null,
        slicer: e.value.style.chart.zoom.show && ce.value,
        source: T.value
      });
      requestAnimationFrame(() => {
        s.value.width = t, s.value.height = a, $e(Z);
      });
    });
    se(() => z.value, () => {
      Ae();
    });
    const Ae = ct(() => {
      Z();
    }, 10);
    function K() {
      z.value = Q.value;
    }
    const B = n(null);
    Ge(() => {
      de(), K();
    });
    function de() {
      et(h.dataset) ? Te({
        componentName: "VueUiWordCloud",
        type: "dataset"
      }) : x.value.forEach((t, a) => {
        tt({
          datasetObject: t,
          requiredAttributes: ["name", "value"]
        }).forEach((o) => {
          F.value = !1, Te({
            componentName: "VueUiWordCloud",
            type: "datasetSerieAttribute",
            property: o,
            index: a
          });
        });
      }), e.value.responsive && (B.value = new ResizeObserver(ze), B.value.observe(C.value.parentNode));
    }
    Le(() => {
      B.value && B.value.disconnect();
    });
    const { isPrinting: ve, isImaging: he, generatePdf: me, generateImage: fe } = ut({
      elementId: `wordCloud_${I.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-word-cloud"
    }), c = n({
      showTable: e.value.table.show,
      showTooltip: e.value.style.chart.tooltip.show
    });
    function Oe(t, a, o = "Arial") {
      const l = document.createElement("canvas").getContext("2d");
      return l.font = `${a}px ${e.value.style.chart.words.bold ? "bold" : "normal"} ${o}`, {
        width: l.measureText(t).width + e.value.style.chart.words.proximity,
        height: a
      };
    }
    function Pe(t, a) {
      return t.x < a.x + a.width && t.x + t.width > a.x && t.y < a.y + a.height && t.y + t.height > a.y;
    }
    function Me(t, a, o) {
      const u = [], l = { x: -a / 2, y: -o / 2, width: a, height: o }, g = 0, k = 0;
      return t.forEach((O) => {
        let ae = !1;
        for (let X = 0; X < Math.max(a, o) / 2 && !ae; X += e.value.style.chart.words.packingWeight)
          for (let le = 0; le < 360 && !ae; le += e.value.style.chart.words.packingWeight) {
            const Ce = le * Math.PI / 180, We = g + X * Math.cos(Ce) - O.width / 2, Ue = k + X * Math.sin(Ce) - O.height / 2, $ = { ...O, x: We, y: Ue }, Ve = $.x >= l.x && $.y >= l.y && $.x + $.width <= l.x + l.width && $.y + $.height <= l.y + l.height, Be = u.some((De) => Pe($, De));
            Ve && !Be && (u.push($), ae = !0);
          }
      }), u;
    }
    const W = n([]);
    se(() => h.dataset, Z, { immediate: !0 });
    const Q = y(() => Math.round(Math.min(...x.value.map((t) => t.value)))), pe = y(() => Math.round(Math.max(...x.value.map((t) => t.value))));
    function Z() {
      const t = [...x.value].filter((l) => l.value >= z.value).map((l) => l.value), a = Math.max(...t), o = Math.min(...t), u = [...x.value].filter((l) => l.value >= z.value).map((l, g) => {
        let k = (l.value - o) / (a - o) * (s.value.maxFontSize - s.value.minFontSize) + s.value.minFontSize;
        k = isNaN(k) ? s.value.minFontSize : k;
        const O = Oe(l.name, k);
        return {
          ...l,
          id: xe(),
          fontSize: k,
          width: O.width,
          height: O.height,
          color: e.value.style.chart.words.usePalette ? e.value.customPalette[g] || e.value.customPalette[g % e.value.customPalette.length] || j[g] || j[g % j.length] : e.value.style.chart.words.color
        };
      });
      W.value = Me(u, s.value.width, s.value.height).sort((l, g) => g.fontSize - l.fontSize);
    }
    const D = y(() => {
      const t = W.value.map((o) => ({
        name: o.name,
        color: o.color
      })), a = W.value.map((o) => o.value);
      return { head: t, body: a };
    });
    function ge() {
      $e(() => {
        const t = D.value.head.map((u, l) => [[
          u.name
        ], [D.value.body[l]]]), a = [[e.value.style.chart.title.text], [e.value.style.chart.title.subtitle.text], [[""], [e.value.table.columnNames.value]]].concat(t), o = lt(a);
        st({ csvContent: o, title: e.value.style.chart.title.text || "vue-ui-word-cloud" });
      });
    }
    const E = y(() => {
      const t = [
        e.value.table.columnNames.series,
        e.value.table.columnNames.value
      ], a = D.value.head.map((l, g) => {
        const k = ot({ p: e.value.table.td.prefix, v: D.value.body[g], s: e.value.table.td.suffix, r: e.value.table.td.roundingValue });
        return [
          {
            color: l.color,
            name: l.name
          },
          k
        ];
      }), o = {
        th: {
          backgroundColor: e.value.table.th.backgroundColor,
          color: e.value.table.th.color,
          outline: e.value.table.th.outline
        },
        td: {
          backgroundColor: e.value.table.td.backgroundColor,
          color: e.value.table.td.color,
          outline: e.value.table.td.outline
        },
        breakpoint: e.value.table.responsiveBreakpoint
      };
      return {
        colNames: [
          e.value.table.columnNames.series,
          e.value.table.columnNames.value
        ],
        head: t,
        body: a,
        config: o
      };
    }), G = n(!1);
    function _e(t) {
      G.value = t, R.value += 1;
    }
    function Ie() {
      return W.value;
    }
    function ye() {
      c.value.showTable = !c.value.showTable;
    }
    function be() {
      c.value.showTooltip = !c.value.showTooltip;
    }
    const L = n(!1);
    function ee() {
      L.value = !L.value;
    }
    H({
      getData: Ie,
      generateCsv: ge,
      generatePdf: me,
      generateImage: fe,
      toggleTable: ye,
      toggleTooltip: be,
      toggleAnnotator: ee
    });
    const A = n(null), U = n(!1), te = n(""), oe = n(null);
    function Re(t) {
      if (!c.value.showTooltip) return;
      A.value = t.id, oe.value = { datapoint: t, config: e.value };
      const a = e.value.style.chart.tooltip.customFormat;
      if (U.value = !1, nt(a))
        try {
          const o = a({
            datapoint: t,
            config: e.value
          });
          typeof o == "string" && (te.value = o, U.value = !0);
        } catch {
          console.warn("Custom format cannot be applied."), U.value = !1;
        }
      if (!U.value) {
        let o = `<svg viewBox="0 0 10 10" height="${e.value.style.chart.tooltip.fontSize}"><circle cx="5" cy="5" r="5" fill="${t.color}"/></svg><span>${t.name}:</span><b>${(t.value || 0).toFixed(e.value.style.chart.tooltip.roundingValue)}</b>`;
        te.value = `<div dir="auto" style="display:flex; gap:4px; align-items:center; jsutify-content:center;">${o}</div>`;
      }
      Y.value = !0;
    }
    return (t, a) => (r(), v("div", {
      class: "vue-ui-word-cloud",
      ref_key: "wordCloudChart",
      ref: C,
      id: `wordCloud_${I.value}`,
      style: q(`width: 100%; font-family:${e.value.style.fontFamily};background:${e.value.style.chart.backgroundColor};${e.value.responsive ? "height:100%" : ""}`),
      onMouseenter: a[3] || (a[3] = () => d(re)(!0)),
      onMouseleave: a[4] || (a[4] = () => d(re)(!1))
    }, [
      e.value.userOptions.buttons.annotator ? (r(), P(yt, {
        key: 0,
        parent: C.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: L.value,
        onClose: ee
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : w("", !0),
      e.value.style.chart.title.text ? (r(), v("div", {
        key: 1,
        ref_key: "chartTitle",
        ref: V,
        style: "width:100%;background:transparent;padding-bottom:24px"
      }, [
        (r(), P(rt, {
          key: `title_${b.value}`,
          config: {
            title: {
              ...e.value.style.chart.title
            },
            subtitle: {
              ...e.value.style.chart.title.subtitle
            }
          }
        }, null, 8, ["config"]))
      ], 512)) : w("", !0),
      e.value.userOptions.show && F.value && (d(ue) || d(J)) ? (r(), P(it, {
        ref: "details",
        key: `user_option_${R.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: d(ve),
        isImaging: d(he),
        uid: I.value,
        hasPdf: e.value.userOptions.buttons.pdf,
        hasXls: e.value.userOptions.buttons.csv,
        hasImg: e.value.userOptions.buttons.img,
        hasTable: e.value.userOptions.buttons.table,
        hasFullscreen: e.value.userOptions.buttons.fullscreen,
        isFullscreen: G.value,
        titles: { ...e.value.userOptions.buttonTitles },
        chartElement: C.value,
        position: e.value.userOptions.position,
        hasTooltip: e.value.style.chart.tooltip.show && e.value.userOptions.buttons.tooltip,
        isTooltip: c.value.showTooltip,
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: L.value,
        onToggleFullscreen: _e,
        onGeneratePdf: d(me),
        onGenerateCsv: ge,
        onGenerateImage: d(fe),
        onToggleTable: ye,
        onToggleTooltip: be,
        onToggleAnnotator: ee,
        style: q({
          visibility: d(ue) ? d(J) ? "visible" : "hidden" : "visible"
        })
      }, Xe({ _: 2 }, [
        t.$slots.optionPdf ? {
          name: "optionPdf",
          fn: m(() => [
            i(t.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        t.$slots.optionCsv ? {
          name: "optionCsv",
          fn: m(() => [
            i(t.$slots, "optionCsv", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        t.$slots.optionImg ? {
          name: "optionImg",
          fn: m(() => [
            i(t.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionTable ? {
          name: "optionTable",
          fn: m(() => [
            i(t.$slots, "optionTable", {}, void 0, !0)
          ]),
          key: "3"
        } : void 0,
        t.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: m(({ toggleFullscreen: o, isFullscreen: u }) => [
            i(t.$slots, "optionFullscreen", M(_({ toggleFullscreen: o, isFullscreen: u })), void 0, !0)
          ]),
          key: "4"
        } : void 0,
        t.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: m(({ toggleAnnotator: o, isAnnotator: u }) => [
            i(t.$slots, "optionAnnotator", M(_({ toggleAnnotator: o, isAnnotator: u })), void 0, !0)
          ]),
          key: "5"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasXls", "hasImg", "hasTable", "hasFullscreen", "isFullscreen", "titles", "chartElement", "position", "hasTooltip", "isTooltip", "hasAnnotator", "isAnnotation", "onGeneratePdf", "onGenerateImage", "style"])) : w("", !0),
      F.value ? (r(), v("svg", {
        key: 3,
        ref_key: "svgRef",
        ref: Ne,
        class: ke({ "vue-data-ui-fullscreen--on": G.value, "vue-data-ui-fulscreen--off": !G.value }),
        xmlns: d(at),
        viewBox: `0 0 ${s.value.width <= 0 ? 10 : s.value.width} ${s.value.height <= 0 ? 10 : s.value.height}`,
        style: "overflow:visible;background:transparent;"
      }, [
        ne(pt),
        t.$slots["chart-background"] ? (r(), v("foreignObject", {
          key: 0,
          x: 0,
          y: 0,
          width: s.value.width <= 0 ? 10 : s.value.width,
          height: s.value.height <= 0 ? 10 : s.value.height,
          style: {
            pointerEvents: "none"
          }
        }, [
          i(t.$slots, "chart-background", {}, void 0, !0)
        ], 8, At)) : w("", !0),
        S("g", {
          transform: `translate(${(s.value.width <= 0 ? 10 : s.value.width) / 2}, ${(s.value.height <= 0 ? 10 : s.value.height) / 2})`
        }, [
          (r(!0), v(je, null, qe(W.value, (o, u) => (r(), v("g", null, [
            (r(), v("text", {
              fill: o.color,
              "font-weight": e.value.style.chart.words.bold ? "bold" : "normal",
              key: u,
              x: o.x,
              y: o.y,
              "font-size": o.fontSize,
              transform: `translate(${o.width / 2}, ${o.height / 2})`,
              class: ke({ animated: e.value.useCssAnimation, "word-selected": A.value && A.value === o.id && c.value.showTooltip, "word-not-selected": A.value && A.value !== o.id && c.value.showTooltip }),
              "text-anchor": "middle",
              "dominant-baseline": "central",
              onMouseover: (l) => Re(o),
              onMouseleave: a[0] || (a[0] = (l) => {
                A.value = null, Y.value = !1;
              }),
              style: q(`animation-delay:${u * e.value.animationDelayMs}ms !important;`)
            }, we(o.name), 47, Pt))
          ]))), 256))
        ], 8, Ot),
        i(t.$slots, "svg", {
          svg: { height: s.value.height, width: s.value.width }
        }, void 0, !0)
      ], 10, zt)) : w("", !0),
      t.$slots.watermark ? (r(), v("div", Mt, [
        i(t.$slots, "watermark", M(_({ isPrinting: d(ve) || d(he) })), void 0, !0)
      ])) : w("", !0),
      ne(gt, {
        show: c.value.showTooltip && Y.value,
        backgroundColor: e.value.style.chart.tooltip.backgroundColor,
        color: e.value.style.chart.tooltip.color,
        fontSize: e.value.style.chart.tooltip.fontSize,
        borderRadius: e.value.style.chart.tooltip.borderRadius,
        borderColor: e.value.style.chart.tooltip.borderColor,
        borderWidth: e.value.style.chart.tooltip.borderWidth,
        backgroundOpacity: e.value.style.chart.tooltip.backgroundOpacity,
        position: e.value.style.chart.tooltip.position,
        offsetY: e.value.style.chart.tooltip.offsetY,
        parent: C.value,
        content: te.value,
        isCustom: U.value
      }, {
        "tooltip-before": m(() => [
          i(t.$slots, "tooltip-before", M(_({ ...oe.value })), void 0, !0)
        ]),
        "tooltip-after": m(() => [
          i(t.$slots, "tooltip-after", M(_({ ...oe.value })), void 0, !0)
        ]),
        _: 3
      }, 8, ["show", "backgroundColor", "color", "fontSize", "borderRadius", "borderColor", "borderWidth", "backgroundOpacity", "position", "offsetY", "parent", "content", "isCustom"]),
      S("div", {
        ref_key: "chartSlicer",
        ref: ce,
        style: "width:100%;background:transparent",
        "data-html2canvas-ignore": ""
      }, [
        e.value.style.chart.zoom.show && Q.value < pe.value ? (r(), P(Ft, {
          key: 0,
          value: z.value,
          "onUpdate:value": a[1] || (a[1] = (o) => z.value = o),
          min: Q.value,
          max: pe.value,
          textColor: e.value.style.chart.color,
          inputColor: e.value.style.chart.zoom.color,
          selectColor: e.value.style.chart.zoom.highlightColor,
          useResetSlot: e.value.style.chart.zoom.useResetSlot,
          background: e.value.style.chart.zoom.color,
          borderColor: e.value.style.chart.backgroundColor,
          source: e.value.style.chart.width,
          onReset: K
        }, {
          "reset-action": m(({ reset: o }) => [
            i(t.$slots, "reset-action", M(_({ reset: o })), void 0, !0)
          ]),
          _: 3
        }, 8, ["value", "min", "max", "textColor", "inputColor", "selectColor", "useResetSlot", "background", "borderColor", "source"])) : w("", !0)
      ], 512),
      t.$slots.source ? (r(), v("div", {
        key: 5,
        ref_key: "source",
        ref: T,
        dir: "auto"
      }, [
        i(t.$slots, "source", {}, void 0, !0)
      ], 512)) : w("", !0),
      F.value ? (r(), P(ht, {
        key: 6,
        hideDetails: "",
        config: {
          open: c.value.showTable,
          maxHeight: 1e4,
          body: {
            backgroundColor: e.value.style.chart.backgroundColor,
            color: e.value.style.chart.color
          },
          head: {
            backgroundColor: e.value.style.chart.backgroundColor,
            color: e.value.style.chart.color
          }
        }
      }, {
        content: m(() => [
          (r(), P(mt, {
            key: `table_${N.value}`,
            colNames: E.value.colNames,
            head: E.value.head,
            body: E.value.body,
            config: E.value.config,
            title: `${e.value.style.chart.title.text}${e.value.style.chart.title.subtitle.text ? ` : ${e.value.style.chart.title.subtitle.text}` : ""}`,
            onClose: a[2] || (a[2] = (o) => c.value.showTable = !1)
          }, {
            th: m(({ th: o }) => [
              S("div", {
                innerHTML: o,
                style: { display: "flex", "align-items": "center" }
              }, null, 8, _t)
            ]),
            td: m(({ td: o }) => [
              He(we(o.name || o), 1)
            ]),
            _: 1
          }, 8, ["colNames", "head", "body", "config", "title"]))
        ]),
        _: 1
      }, 8, ["config"])) : w("", !0)
    ], 44, Nt));
  }
}, Kt = /* @__PURE__ */ Fe(It, [["__scopeId", "data-v-09b6d459"]]);
export {
  Kt as default
};
