import { useCssVars as _e, computed as v, onMounted as Le, ref as c, watch as Te, openBlock as s, createElementBlock as u, normalizeClass as T, normalizeStyle as x, unref as r, createBlock as A, createCommentVNode as f, createSlots as Ae, withCtx as k, renderSlot as y, normalizeProps as H, guardReactiveProps as X, createVNode as Ne, createElementVNode as C, mergeProps as Y, Fragment as M, renderList as V, toDisplayString as B, createTextVNode as Oe, nextTick as ze } from "vue";
import { u as Se, o as Pe, e as fe, g as Fe, c as De, d as Ie, l as Me, i as U, f as E, X as Ve, G as Be, t as Ue, q as Ee, r as Ge, F as q } from "./index-MWHrTFPq.js";
import { u as be } from "./useNestedProp-CTDeT4KA.js";
import { u as Re, U as je } from "./usePrinter-CEEgHfhF.js";
import { _ as He } from "./Title-C7EOYmwp.js";
import { P as Xe } from "./PenAndPaper-DtLD2Sq6.js";
import { D as Ye } from "./DataTable-DtvVWOjy.js";
import qe from "./vue-ui-accordion-BnV2tlGp.js";
import { t as We, u as Je } from "./useResponsive-CoxXLe23.js";
import Ke from "./vue-ui-skeleton-Bo8ydREb.js";
import { u as Qe } from "./useUserOptionState-BIvW1Kz7.js";
import { _ as Ze } from "./PackageVersion-CBKqLhAX.js";
import { _ as et } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const tt = ["id"], at = ["xmlns", "viewBox"], lt = ["width", "height"], st = ["id"], ot = ["stop-color"], nt = ["stop-color"], rt = ["stop-color"], ut = ["stroke", "stroke-width"], it = ["stroke", "stroke-width"], ct = ["x", "y", "font-size", "fill", "font-weight"], vt = ["points", "fill"], dt = ["stroke", "stroke-width", "rx"], ht = ["x", "y", "font-size", "fill", "font-weight"], ft = ["x", "y", "font-size", "fill", "font-weight"], bt = {
  key: 5,
  class: "vue-data-ui-watermark"
}, mt = ["innerHTML"], yt = {
  __name: "vue-ui-funnel",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  setup(me, { expose: ye }) {
    const m = me;
    _e((t) => ({
      "427f8ea6": $e.value
    }));
    const { vue_ui_funnel: ge } = Se(), _ = v(() => !!m.dataset && m.dataset.length);
    Le(W);
    function W() {
      if (Pe(m.dataset) ? fe({
        componentName: "VueUiFunnel",
        type: "dataset"
      }) : m.dataset.forEach((t, l) => {
        Fe({
          datasetObject: t,
          requiredAttributes: ["name", "value"]
        }).forEach((a) => {
          _.value = !1, fe({
            componentName: "VueUiFunnel",
            type: "datasetSerieAttribute",
            property: a,
            index: l
          });
        });
      }), e.value.responsive) {
        const t = We(() => {
          const { width: l, height: a } = Je({
            chart: N.value,
            title: e.value.style.chart.title.text ? te.value : null,
            source: ee.value,
            noTitle: Z.value
          });
          i.value.height = a, i.value.width = l, p.value = ce(), d.value.circles = q({
            relator: Math.min(l, a),
            adjuster: 600,
            source: e.value.style.chart.circles.dataLabels.fontSize,
            threshold: 10,
            fallback: 10
          }), d.value.names = q({
            relator: Math.min(l, a),
            adjuster: 600,
            source: e.value.style.chart.bars.dataLabels.name.fontSize,
            threshold: 10,
            fallback: 10
          }), d.value.values = q({
            relator: Math.min(l, a),
            adjuster: 600,
            source: e.value.style.chart.bars.dataLabels.value.fontSize,
            threshold: 10,
            fallback: 10
          });
        });
        ae.value = new ResizeObserver(t), ae.value.observe(N.value.parentNode);
      }
    }
    const N = c(null), O = c(De()), J = c(0), K = c(0), Q = c(0), Z = c(null), ee = c(null), te = c(null), ae = c(null), w = c(!1);
    function le() {
      const t = be({
        userConfig: m.config,
        defaultConfig: ge
      });
      return t.theme ? {
        ...be({
          userConfig: Ue.vue_ui_funnel[t.theme] || m.config,
          defaultConfig: t
        })
      } : t;
    }
    const e = v({
      get: () => le(),
      set: (t) => t
    }), { userOptionsVisible: G, setUserOptionsVisibility: se, keepUserOptionState: oe } = Qe({ config: e.value });
    Te(() => m.config, (t) => {
      e.value = le(), G.value = !e.value.showOnChartHover, W(), K.value += 1, Q.value += 1, d.value.circles = e.value.style.chart.circles.dataLabels.fontSize, d.value.names = e.value.style.chart.bars.dataLabels.name.fontSize, d.value.values = e.value.style.chart.bars.dataLabels.value.fontSize;
    }, { deep: !0 });
    const { isPrinting: ne, isImaging: re, generatePdf: ue, generateImage: ie } = Re({
      elementId: `funnel_${O.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-funnel"
    }), pe = v(() => e.value.userOptions.show && !e.value.style.chart.title.text), F = c({
      showTable: e.value.table.show
    }), d = c({
      circles: e.value.style.chart.circles.dataLabels.fontSize,
      names: e.value.style.chart.bars.dataLabels.name.fontSize,
      values: e.value.style.chart.bars.dataLabels.value.fontSize
    }), i = v({
      get: () => ({
        height: e.value.style.chart.height,
        width: e.value.style.chart.width
      }),
      set: (t) => t
    }), g = v(() => _.value ? m.dataset.map((t, l) => ({
      ...t,
      color: t.color ? Ie(t.color) : Me(e.value.style.chart.bars.defaultColor, l / m.dataset.length)
    })) : []);
    setTimeout(() => {
      w.value = !0;
    }, g.value.length * 150);
    function ce() {
      const t = e.value.style.chart.padding.left, l = e.value.style.chart.padding.top;
      return {
        left: t,
        top: l,
        right: i.value.width - e.value.style.chart.padding.right,
        bottom: i.value.height - e.value.style.chart.padding.bottom,
        width: i.value.width - t - e.value.style.chart.padding.right,
        height: i.value.height - l - e.value.style.chart.padding.bottom
      };
    }
    const p = c(ce()), L = v(() => p.value.height / m.dataset.length), $ = v(() => L.value * e.value.style.chart.bars.gapRatio), ve = v(() => p.value.width * e.value.style.chart.barCircleSpacingRatio), o = v(() => g.value.map((t, l) => {
      const a = L.value - $.value, n = p.value.top + $.value / 2 * l + (L.value - $.value / 2) * l + $.value / 2, b = t.value / g.value[0].value, h = (p.value.width - a - ve.value) * (t.value / g.value[0].value);
      return {
        ...t,
        cx: p.value.left + a / 2,
        cy: n + a / 2,
        datapointIndex: l,
        fill: t.color,
        height: Math.max(a, 0),
        proportion: b,
        r: Math.max(a / 2, 0),
        width: Math.max(h, 0),
        x: p.value.left + a + ve.value,
        y: n
      };
    })), ke = v(() => {
      const t = o.value.map((l) => `${l.x + l.width},${l.y + (L.value - $.value) / 2}`);
      return `${o.value[0].x},${o.value[0].y + (L.value - $.value) / 2} ${t.toString()} ${o.value.at(-1).x},${o.value.at(-1).y + (L.value - $.value) / 2}`;
    }), Ce = v(() => ({
      x1: o.value[0].cx,
      y1: o.value[0].cy,
      x2: o.value.at(-1).cx,
      y2: o.value.at(-1).cy
    })), z = c(!1);
    function we(t) {
      z.value = t, J.value += 1;
    }
    const $e = v(() => `${g.value.length * 150}ms`), D = c(!1);
    function R() {
      D.value = !D.value;
    }
    function de() {
      F.value.showTable = !F.value.showTable;
    }
    const S = v(() => {
      const t = g.value.map((a) => ({
        name: a.name,
        color: a.color
      })), l = g.value.map((a) => a.value);
      return { head: t, body: l };
    }), I = v(() => {
      const t = [
        e.value.table.columnNames.series,
        e.value.table.columnNames.value,
        e.value.table.columnNames.percentage
      ], l = S.value.head.map((b, h) => {
        const P = U(
          e.value.style.chart.bars.dataLabels.value.formatter,
          S.value.body[h],
          E({
            p: e.value.style.chart.bars.dataLabels.value.prefix,
            v: S.value.body[h],
            s: e.value.style.chart.bars.dataLabels.value.suffix,
            r: e.value.table.td.roundingValue
          }),
          { datapoint: o.value[h] }
        ), j = U(
          e.value.style.chart.circles.dataLabels.formatter,
          o.value[h].proportion * 100,
          E({
            v: o.value[h].proportion * 100,
            s: "%",
            r: e.value.table.td.roundingPercentage
          }),
          { datapoint: o.value[h] }
        );
        return [
          { color: b.color, name: b.name },
          P,
          j
        ];
      }), 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,
          e.value.table.columnNames.percentage
        ],
        head: t,
        body: l,
        config: a
      };
    });
    function he() {
      ze(() => {
        const t = S.value.head.map((n, b) => [[
          n.name
        ], [S.value.body[b]], [o.value[b].proportion * 100]]), l = [[e.value.style.chart.title.text], [e.value.style.chart.title.subtitle.text], [[e.value.table.columnNames.series], [e.value.table.columnNames.value], ["%"]]].concat(t), a = Ee(l);
        Ge({ csvContent: a, title: e.value.style.chart.title.text || "vue-ui-funnel" });
      });
    }
    function xe() {
      return g.value;
    }
    return ye({
      getData: xe,
      generatePdf: ue,
      generateCsv: he,
      generateImage: ie,
      toggleTable: de,
      toggleAnnotator: R
    }), (t, l) => (s(), u("div", {
      ref_key: "funnelChart",
      ref: N,
      class: T(`vue-ui-funnel ${z.value ? "vue-data-ui-wrapper-fullscreen" : ""} ${e.value.useCssAnimation ? "" : "vue-ui-dna"}`),
      style: x(`font-family:${e.value.style.fontFamily};width:100%; ${e.value.responsive ? "height:100%;" : ""} text-align:center;background:${e.value.style.chart.backgroundColor}`),
      id: `funnel_${O.value}`,
      onMouseenter: l[1] || (l[1] = () => r(se)(!0)),
      onMouseleave: l[2] || (l[2] = () => r(se)(!1))
    }, [
      e.value.userOptions.buttons.annotator ? (s(), A(Xe, {
        key: 0,
        parent: N.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: D.value,
        onClose: R
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : f("", !0),
      pe.value ? (s(), u("div", {
        key: 1,
        ref_key: "noTitle",
        ref: Z,
        class: "vue-data-ui-no-title-space",
        style: "height:36px; width: 100%;background:transparent"
      }, null, 512)) : f("", !0),
      e.value.style.chart.title.text ? (s(), u("div", {
        key: 2,
        ref_key: "chartTitle",
        ref: te,
        style: "width:100%;background:transparent;padding-bottom:24px"
      }, [
        (s(), A(He, {
          key: `title_${K.value}`,
          config: {
            title: {
              cy: "funnel-div-title",
              ...e.value.style.chart.title
            },
            subtitle: {
              cy: "funnel-div-subtitle",
              ...e.value.style.chart.title.subtitle
            }
          }
        }, null, 8, ["config"]))
      ], 512)) : f("", !0),
      e.value.userOptions.show && _.value && (r(oe) || r(G)) ? (s(), A(je, {
        ref: "details",
        key: `user_option_${J.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: r(ne),
        isImaging: r(re),
        uid: O.value,
        hasTooltip: !1,
        hasPdf: e.value.userOptions.buttons.pdf,
        hasImg: e.value.userOptions.buttons.img,
        hasXls: e.value.userOptions.buttons.csv,
        hasTable: e.value.userOptions.buttons.table,
        hasLabel: !1,
        hasFullscreen: e.value.userOptions.buttons.fullscreen,
        isFullscreen: z.value,
        chartElement: N.value,
        position: e.value.userOptions.position,
        titles: { ...e.value.userOptions.buttonTitles },
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: D.value,
        onToggleAnnotator: R,
        onToggleFullscreen: we,
        onGeneratePdf: r(ue),
        onGenerateImage: r(ie),
        onToggleTable: de,
        onGenerateCsv: he,
        style: x({
          visibility: r(oe) ? r(G) ? "visible" : "hidden" : "visible"
        })
      }, Ae({ _: 2 }, [
        t.$slots.optionPdf ? {
          name: "optionPdf",
          fn: k(() => [
            y(t.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        t.$slots.optionCsv ? {
          name: "optionCsv",
          fn: k(() => [
            y(t.$slots, "optionCsv", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        t.$slots.optionImg ? {
          name: "optionImg",
          fn: k(() => [
            y(t.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "2"
        } : void 0,
        t.$slots.optionTable ? {
          name: "optionTable",
          fn: k(() => [
            y(t.$slots, "optionTable", {}, void 0, !0)
          ]),
          key: "3"
        } : void 0,
        t.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: k(({ toggleFullscreen: a, isFullscreen: n }) => [
            y(t.$slots, "optionFullscreen", H(X({ toggleFullscreen: a, isFullscreen: n })), void 0, !0)
          ]),
          key: "4"
        } : void 0,
        t.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: k(({ toggleAnnotator: a, isAnnotator: n }) => [
            y(t.$slots, "optionAnnotator", H(X({ toggleAnnotator: a, isAnnotator: n })), void 0, !0)
          ]),
          key: "5"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasImg", "hasXls", "hasTable", "hasFullscreen", "isFullscreen", "chartElement", "position", "titles", "hasAnnotator", "isAnnotation", "onGeneratePdf", "onGenerateImage", "style"])) : f("", !0),
      _.value ? (s(), u("svg", {
        key: 4,
        xmlns: r(Ve),
        class: T({ "vue-data-ui-fullscreen--on": z.value, "vue-data-ui-fulscreen--off": !z.value }),
        viewBox: `0 0 ${i.value.width <= 0 ? 10 : i.value.width} ${i.value.height <= 0 ? 10 : i.value.height}`,
        style: x(`max-width:100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`)
      }, [
        Ne(Ze),
        t.$slots["chart-background"] ? (s(), u("foreignObject", {
          key: 0,
          x: 0,
          y: 0,
          width: i.value.width <= 0 ? 10 : i.value.width,
          height: i.value.height <= 0 ? 10 : i.value.height,
          style: {
            pointerEvents: "none"
          }
        }, [
          y(t.$slots, "chart-background", {}, void 0, !0)
        ], 8, lt)) : f("", !0),
        C("defs", null, [
          C("linearGradient", {
            id: `funnel_area_${O.value}`,
            x1: "0%",
            x2: "100%",
            y1: "0%",
            y2: "0%"
          }, [
            C("stop", {
              offset: "0%",
              "stop-color": e.value.style.chart.backgroundColor,
              "stop-opacity": 0
            }, null, 8, ot),
            C("stop", {
              offset: "20%",
              "stop-color": e.value.style.chart.area.color
            }, null, 8, nt),
            C("stop", {
              offset: "100%",
              "stop-color": e.value.style.chart.area.color
            }, null, 8, rt)
          ], 8, st)
        ]),
        e.value.style.chart.circleLinks.show ? (s(), u("line", Y({ key: 1 }, Ce.value, {
          stroke: e.value.style.chart.circleLinks.color,
          "stroke-width": 12 * e.value.style.chart.circleLinks.widthRatio,
          "stroke-linecap": "round",
          class: {
            animated: e.value.useCssAnimation
          },
          style: {
            strokeDasharray: e.value.useCssAnimation ? p.value.height : 0,
            strokeDashoffset: e.value.useCssAnimation ? p.value.height : 0
          }
        }), null, 16, ut)) : f("", !0),
        (s(!0), u(M, null, V(o.value, ({ cx: a, cy: n, r: b, fill: h }, P) => (s(), u("circle", Y({ cx: a, cy: n, r: b, fill: h }, {
          stroke: e.value.style.chart.circles.stroke,
          "stroke-width": e.value.style.chart.circles.strokeWidth,
          class: {
            animated: e.value.useCssAnimation && !w.value
          },
          style: {
            animationDelay: `${150 * P}ms`
          }
        }), null, 16, it))), 256)),
        (s(!0), u(M, null, V(o.value, (a, n) => (s(), u("text", {
          x: a.cx,
          y: a.cy + d.value.circles / 3 + e.value.style.chart.circles.dataLabels.offsetY,
          "text-anchor": "middle",
          "font-size": d.value.circles,
          fill: e.value.style.chart.circles.dataLabels.adaptColorToBackground ? r(Be)(a.color) : e.value.style.chart.circles.dataLabels.color,
          "font-weight": e.value.style.chart.circles.dataLabels.bold ? "bold" : "normal",
          class: T({
            animated: e.value.useCssAnimation && !w.value
          }),
          style: x({
            animationDelay: `${150 * n}ms`
          })
        }, B(r(U)(
          e.value.style.chart.circles.dataLabels.formatter,
          a.proportion * 100,
          r(E)({
            v: a.proportion * 100,
            s: "%",
            r: e.value.style.chart.circles.dataLabels.rounding
          }),
          { datapoint: a }
        )), 15, ct))), 256)),
        e.value.style.chart.area.show ? (s(), u("polygon", {
          key: 2,
          points: ke.value,
          fill: `url(#funnel_area_${O.value})`,
          class: T({
            animated: e.value.useCssAnimation && !w.value
          }),
          style: x({
            transition: e.value.useCssAnimation ? `all ${150 * g.value.length}ms ease-in` : "none"
          })
        }, null, 14, vt)) : f("", !0),
        (s(!0), u(M, null, V(o.value, ({ x: a, y: n, height: b, width: h, fill: P }, j) => (s(), u("rect", Y({ x: a, y: n, height: b, width: h, fill: P }, {
          stroke: e.value.style.chart.bars.stroke,
          "stroke-width": e.value.style.chart.bars.strokeWidth,
          rx: e.value.style.chart.bars.borderRadius,
          class: {
            animated: e.value.useCssAnimation && !w.value
          },
          style: {
            animationDelay: `${150 * j}ms`
          }
        }), null, 16, dt))), 256)),
        (s(!0), u(M, null, V(o.value, (a, n) => (s(), u("g", null, [
          C("text", {
            x: a.x + a.width + e.value.style.chart.bars.dataLabels.name.offsetX + 12,
            y: a.cy - d.value.names / 2 + e.value.style.chart.bars.dataLabels.name.offsetY,
            "text-anchor": "start",
            "font-size": d.value.names,
            fill: e.value.style.chart.bars.dataLabels.name.color,
            "font-weight": e.value.style.chart.bars.dataLabels.name.bold ? "bold" : "normal",
            class: T({
              animated: e.value.useCssAnimation && !w.value
            }),
            style: x({
              animationDelay: `${150 * n}ms`
            })
          }, B(a.name), 15, ht),
          C("text", {
            x: a.x + a.width + e.value.style.chart.bars.dataLabels.value.offsetX + 12,
            y: a.cy + d.value.values + e.value.style.chart.bars.dataLabels.value.offsetY,
            "text-anchor": "start",
            "font-size": d.value.values,
            fill: e.value.style.chart.bars.dataLabels.value.color,
            "font-weight": e.value.style.chart.bars.dataLabels.value.bold ? "bold" : "normal",
            class: T({
              animated: e.value.useCssAnimation && !w.value
            }),
            style: x({
              animationDelay: `${150 * n}ms`
            })
          }, B(r(U)(
            e.value.style.chart.bars.dataLabels.value.formatter,
            a.value,
            r(E)({
              p: e.value.style.chart.bars.dataLabels.value.prefix,
              v: a.value,
              s: e.value.style.chart.bars.dataLabels.value.suffix,
              r: e.value.style.chart.bars.dataLabels.value.rounding
            }),
            { datapoint: a }
          )), 15, ft)
        ]))), 256)),
        y(t.$slots, "svg", { svg: i.value }, void 0, !0)
      ], 14, at)) : f("", !0),
      t.$slots.watermark ? (s(), u("div", bt, [
        y(t.$slots, "watermark", H(X({ isPrinting: r(ne) || r(re) })), void 0, !0)
      ])) : f("", !0),
      _.value ? f("", !0) : (s(), A(Ke, {
        key: 6,
        config: {
          type: "verticalBar",
          style: {
            backgroundColor: e.value.style.chart.backgroundColor,
            verticalBar: {
              axis: {
                color: "#CCCCCC"
              },
              color: "#CCCCCC"
            }
          }
        }
      }, null, 8, ["config"])),
      t.$slots.source ? (s(), u("div", {
        key: 7,
        ref_key: "source",
        ref: ee,
        dir: "auto"
      }, [
        y(t.$slots, "source", {}, void 0, !0)
      ], 512)) : f("", !0),
      _.value ? (s(), A(qe, {
        key: 8,
        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: k(() => [
          (s(), A(Ye, {
            key: `table_${Q.value}`,
            colNames: I.value.colNames,
            head: I.value.head,
            body: I.value.body,
            config: I.value.config,
            title: `${e.value.style.chart.title.text}${e.value.style.chart.title.subtitle.text ? ` : ${e.value.style.chart.title.subtitle.text}` : ""}`,
            onClose: l[0] || (l[0] = (a) => F.value.showTable = !1)
          }, {
            th: k(({ th: a }) => [
              C("div", {
                innerHTML: a,
                style: { display: "flex", "align-items": "center" }
              }, null, 8, mt)
            ]),
            td: k(({ td: a }) => [
              Oe(B(a.name ? a.name : a), 1)
            ]),
            _: 1
          }, 8, ["colNames", "head", "body", "config", "title"]))
        ]),
        _: 1
      }, 8, ["config"])) : f("", !0)
    ], 46, tt));
  }
}, zt = /* @__PURE__ */ et(yt, [["__scopeId", "data-v-bf9e380b"]]);
export {
  zt as default
};
