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