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