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