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