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