import { useCssVars as we, computed as f, openBlock as i, createElementBlock as v, createVNode as q, renderSlot as m, createElementVNode as C, normalizeStyle as N, pushScopeId as xe, popScopeId as $e, ref as c, watch as te, onMounted as Se, onBeforeUnmount as Fe, createCommentVNode as F, createBlock as L, unref as p, createSlots as Ne, withCtx as h, normalizeProps as X, guardReactiveProps as j, normalizeClass as ae, Fragment as _e, renderList as Pe, toDisplayString as oe, createTextVNode as Te, nextTick as le } from "vue";
import { u as ze, W as Ie, s as Ae, c as se, t as Oe, a as Me, p as E, o as We, e as ne, g as De, f as Be, X as Ee, q as Re, r as Ue } from "./index-CguVaFlt.js";
import { _ as Ve } from "./Title-DbTGPg4G.js";
import { u as Ge, U as Le } from "./usePrinter-ClsMRVJG.js";
import { d as Xe, t as je, u as qe } from "./useResponsive-NZB-WLRF.js";
import He from "./vue-ui-accordion-w15FGKRN.js";
import { D as Ye } from "./DataTable-BwHWRlRZ.js";
import Je from "./BaseIcon-BNFf4B_v.js";
import { _ as ue } from "./_plugin-vue_export-helper-CHgC5LLL.js";
import { u as re } from "./useNestedProp-BbEbJmgv.js";
const Ke = (r) => (xe("data-v-3fd7d274"), r = r(), $e(), r), Qe = { "data-html2canvas-ignore": "" }, Ze = {
  key: 0,
  class: "reset-wrapper"
}, et = {
  key: 1,
  class: "reset-wrapper"
}, tt = { class: "mono-slicer" }, at = /* @__PURE__ */ Ke(() => /* @__PURE__ */ C("div", { class: "slider-track" }, null, -1)), ot = ["min", "max", "value"], lt = {
  __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(r, { emit: I }) {
    const s = r;
    we((b) => ({
      "90ad3208": R.value,
      "4f9eef70": P.value,
      "6e07ae3e": _.value,
      "2fd430a0": r.selectColor,
      "6b8169a4": k.value
    }));
    const R = f(() => s.inputColor), k = f(() => s.background), _ = f(() => `${s.selectColor}33`), P = f(() => s.borderColor);
    function T() {
      I("reset");
    }
    const w = f(() => {
      const b = s.max - s.min, e = 0, x = (s.value - s.min) / b * 100;
      return {
        left: `${e}%`,
        width: `${x - e}%`,
        background: s.selectColor
      };
    });
    return (b, e) => (i(), v("div", Qe, [
      r.value !== r.source ? (i(), v("div", Ze, [
        r.useResetSlot ? m(b.$slots, "reset-action", {
          key: 1,
          reset: T
        }, void 0, !0) : (i(), v("button", {
          key: 0,
          "data-cy-reset": "",
          tabindex: "0",
          role: "button",
          class: "vue-data-ui-refresh-button",
          onClick: T
        }, [
          q(Je, {
            name: "refresh",
            stroke: r.textColor
          }, null, 8, ["stroke"])
        ]))
      ])) : (i(), v("div", et)),
      C("div", tt, [
        at,
        C("div", {
          class: "range-highlight",
          style: N(w.value)
        }, null, 4),
        C("input", {
          type: "range",
          min: r.min,
          max: r.max,
          value: Number(r.value),
          onInput: e[0] || (e[0] = (x) => I("update:value", Number(x.target.value)))
        }, null, 40, ot)
      ])
    ]));
  }
}, st = /* @__PURE__ */ ue(lt, [["__scopeId", "data-v-3fd7d274"]]), nt = ["id"], rt = ["xmlns", "viewBox"], ut = ["transform"], it = ["fill", "font-weight", "x", "y", "font-size", "transform"], ct = {
  key: 3,
  class: "vue-data-ui-watermark"
}, dt = ["innerHTML"], vt = {
  __name: "vue-ui-word-cloud",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: [Array, String],
      default() {
        return [];
      }
    }
  },
  setup(r, { expose: I }) {
    const s = r, { vue_ui_word_cloud: R } = ze(), k = f({
      get() {
        return !!s.dataset && s.dataset.length;
      },
      set(t) {
        return t;
      }
    }), _ = c(typeof s.dataset == "string" ? Ie(s.dataset) : s.dataset.map((t) => ({
      ...t,
      value: Ae(t.value)
    }))), P = c(se()), T = c(0), w = c(null), b = c(null), e = f(() => {
      const t = re({
        userConfig: s.config,
        defaultConfig: R
      });
      return t.theme ? {
        ...re({
          userConfig: Oe.vue_ui_word_cloud[t.theme] || s.config,
          defaultConfig: t
        }),
        customPalette: Me[t.theme] || E
      } : t;
    }), x = c(null), g = c(e.value.style.chart.width), n = c({
      width: g.value,
      height: e.value.style.chart.height / e.value.style.chart.height * g.value,
      maxFontSize: e.value.style.chart.words.maxFontSize,
      minFontSize: e.value.style.chart.words.minFontSize
    }), ie = je(() => {
      const { width: t, height: o } = qe({
        chart: w.value,
        title: e.value.style.chart.title.text ? b.value : null,
        slicer: e.value.style.chart.zoom.show && x.value
      });
      n.value.width = t, n.value.height = o, le(U);
    });
    te(() => g.value, () => {
      ce();
    });
    const ce = Xe(() => {
      n.value.width = Number(g.value), n.value.height = e.value.style.chart.height / e.value.style.chart.height * Number(g.value), U();
    }, 10);
    function de() {
      g.value = e.value.style.chart.width;
    }
    const A = c(null);
    Se(() => {
      We(s.dataset) ? ne({
        componentName: "VueUiWordCloud",
        type: "dataset"
      }) : _.value.forEach((t, o) => {
        De({
          datasetObject: t,
          requiredAttributes: ["name", "value"]
        }).forEach((a) => {
          k.value = !1, ne({
            componentName: "VueUiWordCloud",
            type: "datasetSerieAttribute",
            property: a,
            index: o
          });
        });
      }), e.value.responsive && (A.value = new ResizeObserver(ie), A.value.observe(w.value.parentNode));
    }), Fe(() => {
      A.value && A.value.disconnect();
    });
    const { isPrinting: H, isImaging: Y, generatePdf: J, generateImage: K } = Ge({
      elementId: `wordCloud_${P.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-word-cloud"
    }), O = c({
      showTable: e.value.table.show
    });
    function ve(t, o, a = "Arial") {
      const l = document.createElement("canvas").getContext("2d");
      return l.font = `${o}px ${e.value.style.chart.words.bold ? "bold" : "normal"} ${a}`, {
        width: l.measureText(t).width + e.value.style.chart.words.proximity,
        height: o
      };
    }
    function he(t, o) {
      return t.x < o.x + o.width && t.x + t.width > o.x && t.y < o.y + o.height && t.y + t.height > o.y;
    }
    function me(t, o, a) {
      const u = [], l = { x: -o / 2, y: -a / 2, width: o, height: a }, d = 0, $ = 0;
      return t.forEach((S) => {
        let V = !1;
        for (let B = 0; B < Math.max(o, a) / 2 && !V; B += e.value.style.chart.words.packingWeight)
          for (let G = 0; G < 360 && !V; G += e.value.style.chart.words.packingWeight) {
            const ee = G * Math.PI / 180, ye = d + B * Math.cos(ee) - S.width / 2, be = $ + B * Math.sin(ee) - S.height / 2, y = { ...S, x: ye, y: be }, pe = y.x >= l.x && y.y >= l.y && y.x + y.width <= l.x + l.width && y.y + y.height <= l.y + l.height, Ce = u.some((ke) => he(y, ke));
            pe && !Ce && (u.push(y), V = !0);
          }
      }), u;
    }
    const z = c([]);
    te(() => s.dataset, U, { immediate: !0 });
    function U() {
      const t = _.value.map((l) => l.value), o = Math.max(...t), a = Math.min(...t), u = _.value.map((l, d) => {
        const $ = (l.value - a) / (o - a) * (n.value.maxFontSize - n.value.minFontSize) + n.value.minFontSize, S = ve(l.name, $);
        return {
          ...l,
          id: se(),
          fontSize: $,
          width: S.width,
          height: S.height,
          color: e.value.style.chart.words.usePalette ? e.value.customPalette[d] || e.value.customPalette[d % e.value.customPalette.length] || E[d] || E[d % E.length] : e.value.style.chart.words.color
        };
      });
      z.value = me(u, n.value.width, n.value.height).sort((l, d) => d.fontSize - l.fontSize);
    }
    const M = f(() => {
      const t = z.value.map((a) => ({
        name: a.name,
        color: a.color
      })), o = z.value.map((a) => a.value);
      return { head: t, body: o };
    });
    function Q() {
      le(() => {
        const t = M.value.head.map((u, l) => [[
          u.name
        ], [M.value.body[l]]]), o = [[e.value.style.chart.title.text], [e.value.style.chart.title.subtitle.text], [[""], [e.value.table.columnNames.value]]].concat(t), a = Re(o);
        Ue({ csvContent: a, title: e.value.style.chart.title.text || "vue-ui-word-cloud" });
      });
    }
    const W = f(() => {
      const t = [
        e.value.table.columnNames.series,
        e.value.table.columnNames.value
      ], o = M.value.head.map((l, d) => {
        const $ = Be({ p: e.value.table.td.prefix, v: M.value.body[d], s: e.value.table.td.suffix, r: e.value.table.td.roundingValue });
        return [
          {
            color: l.color,
            name: l.name
          },
          $
        ];
      }), a = {
        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: o,
        config: a
      };
    }), D = c(!1);
    function fe(t) {
      D.value = t, T.value += 1;
    }
    function ge() {
      return z.value;
    }
    function Z() {
      O.value.showTable = !O.value.showTable;
    }
    return I({
      getData: ge,
      generateCsv: Q,
      generatePdf: J,
      generateImage: K,
      toggleTable: Z
    }), (t, o) => (i(), v("div", {
      class: "vue-ui-word-cloud",
      ref_key: "wordCloudChart",
      ref: w,
      id: `wordCloud_${P.value}`,
      style: N(`width: 100%; font-family:${e.value.style.fontFamily};background:${e.value.style.chart.backgroundColor};${e.value.responsive ? "height:100%" : ""}`)
    }, [
      e.value.style.chart.title.text ? (i(), v("div", {
        key: 0,
        ref_key: "chartTitle",
        ref: b,
        style: N(`width:100%;background:${e.value.style.chart.backgroundColor};padding-bottom:24px`)
      }, [
        q(Ve, {
          config: {
            title: {
              ...e.value.style.chart.title
            },
            subtitle: {
              ...e.value.style.chart.title.subtitle
            }
          }
        }, null, 8, ["config"])
      ], 4)) : F("", !0),
      e.value.userOptions.show && k.value ? (i(), L(Le, {
        ref: "details",
        key: `user_option_${T.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: p(H),
        isImaging: p(Y),
        uid: P.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: D.value,
        titles: { ...e.value.userOptions.buttonTitles },
        chartElement: w.value,
        onToggleFullscreen: fe,
        onGeneratePdf: p(J),
        onGenerateCsv: Q,
        onGenerateImage: p(K),
        onToggleTable: Z
      }, Ne({ _: 2 }, [
        t.$slots.optionPdf ? {
          name: "optionPdf",
          fn: h(() => [
            m(t.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        t.$slots.optionCsv ? {
          name: "optionCsv",
          fn: h(() => [
            m(t.$slots, "optionCsv", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        t.$slots.optionImg ? {
          name: "optionImg",
          fn: h(() => [
            m(t.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionTable ? {
          name: "optionTable",
          fn: h(() => [
            m(t.$slots, "optionTable", {}, void 0, !0)
          ]),
          key: "3"
        } : void 0,
        t.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: h(({ toggleFullscreen: a, isFullscreen: u }) => [
            m(t.$slots, "optionFullscreen", X(j({ toggleFullscreen: a, isFullscreen: u })), void 0, !0)
          ]),
          key: "4"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasXls", "hasImg", "hasTable", "hasFullscreen", "isFullscreen", "titles", "chartElement", "onGeneratePdf", "onGenerateImage"])) : F("", !0),
      k.value ? (i(), v("svg", {
        key: 2,
        class: ae({ "vue-data-ui-fullscreen--on": D.value, "vue-data-ui-fulscreen--off": !D.value }),
        xmlns: p(Ee),
        viewBox: `0 0 ${n.value.width <= 0 ? 10 : n.value.width} ${n.value.height <= 0 ? 10 : n.value.height}`,
        style: N(`overflow:visible;background:${e.value.style.chart.backgroundColor};`)
      }, [
        C("g", {
          transform: `translate(${(n.value.width <= 0 ? 10 : n.value.width) / 2}, ${(n.value.height <= 0 ? 10 : n.value.height) / 2})`
        }, [
          (i(!0), v(_e, null, Pe(z.value, (a, u) => (i(), v("g", null, [
            (i(), v("text", {
              fill: a.color,
              "font-weight": e.value.style.chart.words.bold ? "bold" : "normal",
              key: u,
              x: a.x,
              y: a.y,
              "font-size": a.fontSize,
              transform: `translate(${a.width / 2}, ${a.height / 2})`,
              style: N(`animation-delay:${u * e.value.animationDelayMs}ms !important`),
              class: ae({ animated: e.value.useCssAnimation }),
              "text-anchor": "middle",
              "dominant-baseline": "middle"
            }, oe(a.name), 15, it))
          ]))), 256))
        ], 8, ut),
        m(t.$slots, "svg", {
          svg: { height: n.value.height, width: n.value.width }
        }, void 0, !0)
      ], 14, rt)) : F("", !0),
      t.$slots.watermark ? (i(), v("div", ct, [
        m(t.$slots, "watermark", X(j({ isPrinting: p(H) || p(Y) })), void 0, !0)
      ])) : F("", !0),
      C("div", {
        ref_key: "chartSlicer",
        ref: x,
        style: N(`width:100%;background:${e.value.style.chart.backgroundColor}`),
        "data-html2canvas-ignore": ""
      }, [
        e.value.style.chart.zoom.show ? (i(), L(st, {
          key: 0,
          value: g.value,
          "onUpdate:value": o[0] || (o[0] = (a) => g.value = a),
          min: 100,
          max: e.value.style.chart.width * 3,
          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: de
        }, {
          "reset-action": h(({ reset: a }) => [
            m(t.$slots, "reset-action", X(j({ reset: a })), void 0, !0)
          ]),
          _: 3
        }, 8, ["value", "max", "textColor", "inputColor", "selectColor", "useResetSlot", "background", "borderColor", "source"])) : F("", !0)
      ], 4),
      k.value ? (i(), L(He, {
        key: 4,
        hideDetails: "",
        config: {
          open: O.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(() => [
          q(Ye, {
            colNames: W.value.colNames,
            head: W.value.head,
            body: W.value.body,
            config: W.value.config,
            title: `${e.value.style.chart.title.text}${e.value.style.chart.title.subtitle.text ? ` : ${e.value.style.chart.title.subtitle.text}` : ""}`,
            onClose: o[1] || (o[1] = (a) => O.value.showTable = !1)
          }, {
            th: h(({ th: a }) => [
              C("div", {
                innerHTML: a,
                style: { display: "flex", "align-items": "center" }
              }, null, 8, dt)
            ]),
            td: h(({ td: a }) => [
              Te(oe(a.name || a), 1)
            ]),
            _: 1
          }, 8, ["colNames", "head", "body", "config", "title"])
        ]),
        _: 1
      }, 8, ["config"])) : F("", !0)
    ], 12, nt));
  }
}, xt = /* @__PURE__ */ ue(vt, [["__scopeId", "data-v-4e5216cf"]]);
export {
  xt as default
};
