import { useCssVars as Le, computed as v, onMounted as Te, ref as c, watch as Ae, createElementBlock as u, openBlock as s, unref as n, normalizeStyle as _, normalizeClass as T, createBlock as A, createCommentVNode as f, createSlots as Ne, withCtx as k, renderSlot as y, normalizeProps as H, guardReactiveProps as X, createVNode as Oe, createElementVNode as C, mergeProps as q, Fragment as M, renderList as R, toDisplayString as V, createTextVNode as ze, nextTick as Se } from "vue";
import { u as Pe, o as Fe, e as fe, g as De, c as Ie, d as Me, l as Re, i as B, f as U, X as Ve, G as Be, F as Y, a as Ue, q as Ee, r as Ge } from "./index-CjXfhpMA.js";
import { u as be } from "./useNestedProp-CmXi5M93.js";
import { u as je, U as He } from "./usePrinter-bLtFFBkj.js";
import { _ as Xe } from "./Title-BfzkycPl.js";
import { P as qe } from "./PenAndPaper-OV0eQPcd.js";
import { D as Ye } from "./DataTable-BfXSoPx-.js";
import We from "./vue-ui-accordion-CEdZMQD4.js";
import { t as Je, u as Ke } from "./useResponsive-BWapHhVH.js";
import Qe from "./vue-ui-skeleton-B1q5j9VT.js";
import { u as Ze } from "./useUserOptionState-BIvW1Kz7.js";
import { _ as et } from "./PackageVersion-ChIRiDpv.js";
import { u as tt } from "./useChartAccessibility-BWojgys7.js";
import { _ as at } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const lt = ["id"], st = ["xmlns", "viewBox"], ot = ["width", "height"], rt = ["id"], nt = ["stop-color"], ut = ["stop-color"], it = ["stop-color"], ct = ["stroke", "stroke-width"], vt = ["stroke", "stroke-width"], dt = ["x", "y", "font-size", "fill", "font-weight"], ht = ["points", "fill"], ft = ["stroke", "stroke-width", "rx"], bt = ["x", "y", "font-size", "fill", "font-weight"], mt = ["x", "y", "font-size", "fill", "font-weight"], yt = {
  key: 5,
  class: "vue-data-ui-watermark"
}, gt = ["innerHTML"], pt = {
  __name: "vue-ui-funnel",
  props: {
    config: {
      type: Object,
      default() {
        return {};
      }
    },
    dataset: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  setup(me, { expose: ye }) {
    Le((t) => ({
      "3ce0aba8": _e.value
    }));
    const { vue_ui_funnel: ge } = Pe(), m = me, x = v(() => !!m.dataset && m.dataset.length);
    Te(W);
    function W() {
      if (Fe(m.dataset) ? fe({
        componentName: "VueUiFunnel",
        type: "dataset"
      }) : m.dataset.forEach((t, l) => {
        De({
          datasetObject: t,
          requiredAttributes: ["name", "value"]
        }).forEach((a) => {
          x.value = !1, fe({
            componentName: "VueUiFunnel",
            type: "datasetSerieAttribute",
            property: a,
            index: l
          });
        });
      }), e.value.responsive) {
        const t = Je(() => {
          const { width: l, height: a } = Ke({
            chart: N.value,
            title: e.value.style.chart.title.text ? te.value : null,
            source: ee.value,
            noTitle: Z.value
          });
          requestAnimationFrame(() => {
            i.value.height = a, i.value.width = l, p.value = ce(), d.value.circles = Y({
              relator: Math.min(l, a),
              adjuster: 600,
              source: e.value.style.chart.circles.dataLabels.fontSize,
              threshold: 10,
              fallback: 10
            }), d.value.names = Y({
              relator: Math.min(l, a),
              adjuster: 600,
              source: e.value.style.chart.bars.dataLabels.name.fontSize,
              threshold: 10,
              fallback: 10
            }), d.value.values = Y({
              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(Ie()), 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: E, setUserOptionsVisibility: se, keepUserOptionState: oe } = Ze({ config: e.value }), { svgRef: pe } = tt({ config: e.value.style.chart.title });
    Ae(() => m.config, (t) => {
      e.value = le(), E.value = !e.value.userOptions.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, z.value.showTable = e.value.table.show;
    }, { deep: !0 });
    const { isPrinting: re, isImaging: ne, generatePdf: ue, generateImage: ie } = je({
      elementId: `funnel_${O.value}`,
      fileName: e.value.style.chart.title.text || "vue-ui-funnel"
    }), ke = v(() => e.value.userOptions.show && !e.value.style.chart.title.text), z = 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(() => x.value ? m.dataset.map((t, l) => ({
      ...t,
      color: t.color ? Me(t.color) : Re(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, r = 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: r + 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: r
      };
    })), Ce = 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}`;
    }), we = v(() => ({
      x1: o.value[0].cx,
      y1: o.value[0].cy,
      x2: o.value.at(-1).cx,
      y2: o.value.at(-1).cy
    })), S = c(!1);
    function $e(t) {
      S.value = t, J.value += 1;
    }
    const _e = v(() => `${g.value.length * 150}ms`), D = c(!1);
    function G() {
      D.value = !D.value;
    }
    function de() {
      z.value.showTable = !z.value.showTable;
    }
    const P = 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 = P.value.head.map((b, h) => {
        const F = B(
          e.value.style.chart.bars.dataLabels.value.formatter,
          P.value.body[h],
          U({
            p: e.value.style.chart.bars.dataLabels.value.prefix,
            v: P.value.body[h],
            s: e.value.style.chart.bars.dataLabels.value.suffix,
            r: e.value.table.td.roundingValue
          }),
          { datapoint: o.value[h] }
        ), j = B(
          e.value.style.chart.circles.dataLabels.formatter,
          o.value[h].proportion * 100,
          U({
            v: o.value[h].proportion * 100,
            s: "%",
            r: e.value.table.td.roundingPercentage
          }),
          { datapoint: o.value[h] }
        );
        return [
          { color: b.color, name: b.name },
          F,
          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() {
      Se(() => {
        const t = P.value.head.map((r, b) => [[
          r.name
        ], [P.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: G
    }), (t, l) => (s(), u("div", {
      ref_key: "funnelChart",
      ref: N,
      class: T(`vue-ui-funnel ${S.value ? "vue-data-ui-wrapper-fullscreen" : ""} ${e.value.useCssAnimation ? "" : "vue-ui-dna"}`),
      style: _(`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] = () => n(se)(!0)),
      onMouseleave: l[2] || (l[2] = () => n(se)(!1))
    }, [
      e.value.userOptions.buttons.annotator ? (s(), A(qe, {
        key: 0,
        parent: N.value,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        active: D.value,
        onClose: G
      }, null, 8, ["parent", "backgroundColor", "color", "active"])) : f("", !0),
      ke.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(Xe, {
          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 && x.value && (n(oe) || n(E)) ? (s(), A(He, {
        ref: "details",
        key: `user_option_${J.value}`,
        backgroundColor: e.value.style.chart.backgroundColor,
        color: e.value.style.chart.color,
        isPrinting: n(re),
        isImaging: n(ne),
        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: S.value,
        chartElement: N.value,
        position: e.value.userOptions.position,
        titles: { ...e.value.userOptions.buttonTitles },
        hasAnnotator: e.value.userOptions.buttons.annotator,
        isAnnotation: D.value,
        onToggleAnnotator: G,
        onToggleFullscreen: $e,
        onGeneratePdf: n(ue),
        onGenerateImage: n(ie),
        onToggleTable: de,
        onGenerateCsv: he,
        style: _({
          visibility: n(oe) ? n(E) ? "visible" : "hidden" : "visible"
        })
      }, Ne({ _: 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: r }) => [
            y(t.$slots, "optionFullscreen", H(X({ toggleFullscreen: a, isFullscreen: r })), void 0, !0)
          ]),
          key: "4"
        } : void 0,
        t.$slots.optionAnnotator ? {
          name: "optionAnnotator",
          fn: k(({ toggleAnnotator: a, isAnnotator: r }) => [
            y(t.$slots, "optionAnnotator", H(X({ toggleAnnotator: a, isAnnotator: r })), 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),
      x.value ? (s(), u("svg", {
        key: 4,
        ref_key: "svgRef",
        ref: pe,
        xmlns: n(Ve),
        class: T({ "vue-data-ui-fullscreen--on": S.value, "vue-data-ui-fulscreen--off": !S.value }),
        viewBox: `0 0 ${i.value.width <= 0 ? 10 : i.value.width} ${i.value.height <= 0 ? 10 : i.value.height}`,
        style: _(`max-width:100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`)
      }, [
        Oe(et),
        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, ot)) : 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, nt),
            C("stop", {
              offset: "20%",
              "stop-color": e.value.style.chart.area.color
            }, null, 8, ut),
            C("stop", {
              offset: "100%",
              "stop-color": e.value.style.chart.area.color
            }, null, 8, it)
          ], 8, rt)
        ]),
        e.value.style.chart.circleLinks.show ? (s(), u("line", q({ key: 1 }, we.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, ct)) : f("", !0),
        (s(!0), u(M, null, R(o.value, ({ cx: a, cy: r, r: b, fill: h }, F) => (s(), u("circle", q({ ref_for: !0 }, { cx: a, cy: r, 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 * F}ms`
          }
        }), null, 16, vt))), 256)),
        (s(!0), u(M, null, R(o.value, (a, r) => (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 ? n(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: _({
            animationDelay: `${150 * r}ms`
          })
        }, V(n(B)(
          e.value.style.chart.circles.dataLabels.formatter,
          a.proportion * 100,
          n(U)({
            v: a.proportion * 100,
            s: "%",
            r: e.value.style.chart.circles.dataLabels.rounding
          }),
          { datapoint: a }
        )), 15, dt))), 256)),
        e.value.style.chart.area.show ? (s(), u("polygon", {
          key: 2,
          points: Ce.value,
          fill: `url(#funnel_area_${O.value})`,
          class: T({
            animated: e.value.useCssAnimation && !w.value
          }),
          style: _({
            transition: e.value.useCssAnimation ? `all ${150 * g.value.length}ms ease-in` : "none"
          })
        }, null, 14, ht)) : f("", !0),
        (s(!0), u(M, null, R(o.value, ({ x: a, y: r, height: b, width: h, fill: F }, j) => (s(), u("rect", q({ ref_for: !0 }, { x: a, y: r, height: b, width: h, fill: F }, {
          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, ft))), 256)),
        (s(!0), u(M, null, R(o.value, (a, r) => (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: _({
              animationDelay: `${150 * r}ms`
            })
          }, V(a.name), 15, bt),
          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: _({
              animationDelay: `${150 * r}ms`
            })
          }, V(n(B)(
            e.value.style.chart.bars.dataLabels.value.formatter,
            a.value,
            n(U)({
              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, mt)
        ]))), 256)),
        y(t.$slots, "svg", { svg: i.value }, void 0, !0)
      ], 14, st)) : f("", !0),
      t.$slots.watermark ? (s(), u("div", yt, [
        y(t.$slots, "watermark", H(X({ isPrinting: n(re) || n(ne) })), void 0, !0)
      ])) : f("", !0),
      x.value ? f("", !0) : (s(), A(Qe, {
        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),
      x.value ? (s(), A(We, {
        key: 8,
        hideDetails: "",
        config: {
          open: z.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) => z.value.showTable = !1)
          }, {
            th: k(({ th: a }) => [
              C("div", {
                innerHTML: a,
                style: { display: "flex", "align-items": "center" }
              }, null, 8, gt)
            ]),
            td: k(({ td: a }) => [
              ze(V(a.name ? a.name : a), 1)
            ]),
            _: 1
          }, 8, ["colNames", "head", "body", "config", "title"]))
        ]),
        _: 1
      }, 8, ["config"])) : f("", !0)
    ], 46, lt));
  }
}, Ft = /* @__PURE__ */ at(pt, [["__scopeId", "data-v-f0e3fa4f"]]);
export {
  Ft as default
};
