import { jsx as c, jsxs as x, Fragment as be } from "react/jsx-runtime";
import { useState as H, useEffect as ve, Fragment as Ye } from "react";
import St from "./Tooltip.js";
import { ResponsiveBar as jt } from "@nivo/bar";
import { injectIntl as Rt } from "react-intl";
import { useTheme as Pt } from "@nivo/theming";
import { line as Ke } from "d3-shape";
import Xe from "./LineLayer.js";
import Ne from "papaparse";
import Yt from "../../layout/FlexWrapDetector.js";
import Ie from "../../utils/deviceType.js";
const Kt = "middle", Xt = "top", T = "#66676d", qe = "#dddddd", qt = "none", ee = "_Color", Zt = ({
  editing: y,
  legends: _,
  marginLeft: Ze,
  marginTop: R,
  marginRight: Ce,
  marginBottom: P,
  options: f,
  intl: b,
  format: p,
  colors: A,
  groupMode: F,
  height: Je,
  showLegends: te,
  legendPosition: v,
  tickRotation: z,
  offsetText: ae,
  tickColor: ne,
  layout: u,
  reverse: S,
  offsetY: Ue,
  csvLineLayerData: ke,
  tooltip: le,
  lineLayerEnabled: re,
  overlays: j,
  maxValue: ie,
  valueScale: Qe,
  colorGenerator: N,
  legendLabel: Le,
  overrideTickColor: Ge,
  fixedMinValue: se,
  fixedMaxValue: ce,
  barPadding: et,
  barLabelPosition: we,
  barInnerPadding: tt,
  tooltipEnabled: at,
  xLabelColor: O,
  barLabelColor: Z,
  legendCheckBack: L,
  legendLabelBack: he,
  legendLabelColor: de,
  highlightXAxisLine: nt,
  showTickLine: Y,
  showRightAxis: lt,
  offsetRight: De,
  offsetBottom: me,
  confidenceIntervals: fe,
  showGroupTotal: rt,
  groupTotalLabel: Me,
  groupTotalFormat: Oe,
  groupTotalMeasure: Fe,
  groupTotalOffset: E,
  groupTotalFixedPosition: C,
  tooltipEnableMarkdown: it,
  xAxisTickValues: st,
  yAxisTickValues: ct,
  mobileCustomization: ht,
  minMaxClamp: Ct,
  reverseLegend: dt,
  enableGridY: mt,
  enableGridX: ft,
  customAxisFormat: I,
  previewMode: V,
  showLegendsInColumns: Jt = !1,
  numberOfLegendColumns: Ut = 4,
  lineXAxisTickMode: ze = "none",
  lineXAxisTickCount: ut = 10,
  lineXAxisTickEvery: ot = 1
}) => {
  var Pe;
  const Ee = ["mobile", "tablet", "midTablet"].includes(
    Ie()
  ), J = ["tablet", "midTablet"].includes(Ie()), U = Ie() === "mobile", ue = 30, oe = 15, d = JSON.parse(
    decodeURIComponent(ht)
  ), Ve = Ee && ((d == null ? void 0 : d.showCustomization) ?? !1), $ = Ve && V !== "Desktop", B = !y && Ve, ye = () => Z === "null" || Z === null || !Z ? "#000000" : Z, [w, yt] = H([]), { colorBy: K } = A, $e = {};
  j.forEach((e, t) => {
    $e[t] = !0;
  });
  const [k, xt] = H($e), [Be, pt] = H(50), [Qt, We] = H(R), [Gt, He] = H(0), [Te, _e] = H(P), [Ae, gt] = H(!1);
  ve(() => {
    let e, t;
    return e = requestAnimationFrame(() => {
      e = requestAnimationFrame(() => {
        t = setTimeout(() => {
          gt(!0);
        }, 50);
      });
    }), () => {
      cancelAnimationFrame(e), clearTimeout(t);
    };
  }, []);
  const X = ((e, t, r, i, a) => {
    let s = [];
    return e.data && (s = t.colorBy === "index" ? e.data.map((l) => {
      let n, h = !0;
      return r.indexOf(l[e.indexBy]) > -1 ? (h = !1, n = i) : n = l[ee] ? l[ee] : a.getColor(l.id, l), {
        enabled: h,
        color: n,
        id: l[e.indexBy],
        label: l[e.indexBy]
      };
    }) : e.keys.map((l) => {
      let n, h = !0;
      return r.indexOf(l) > -1 ? (h = !1, n = i) : n = a.getColorByKey(l), {
        enabled: h,
        color: n,
        id: l,
        label: l
      };
    })), s;
  })(
    f,
    A,
    w,
    qt,
    N
  ), Se = () => (dt && X.reverse(), /* @__PURE__ */ x(be, { children: [
    te && X.map((e) => /* @__PURE__ */ x(
      "div",
      {
        className: `legend item ${e.enabled ? "" : "ignore"}`,
        onClick: () => Ot(e.id),
        children: [
          L && /* @__PURE__ */ c(
            "input",
            {
              className: e.enabled ? "" : "ignore",
              type: "checkbox",
              checked: e.enabled,
              style: {
                backgroundColor: L ? K === "values" ? ne : e.color : "none",
                color: "#000"
              }
            }
          ),
          !L && /* @__PURE__ */ c(
            "input",
            {
              type: "checkbox",
              checked: e.enabled,
              style: {
                color: "#000"
              }
            }
          ),
          L && /* @__PURE__ */ c(
            "span",
            {
              className: "checkmark-with-bg",
              style: { backgroundColor: e.color }
            }
          ),
          !L && /* @__PURE__ */ c("span", { className: "checkmark" }),
          he && /* @__PURE__ */ c(
            "label",
            {
              className: e.enabled ? "" : "ignore",
              style: {
                backgroundColor: K === "values" ? ne : e.color,
                color: de
              },
              children: e.label
            }
          ),
          !he && /* @__PURE__ */ c(
            "label",
            {
              className: e.enabled ? "" : "ignore",
              style: {
                color: de
              },
              children: e.label
            }
          )
        ]
      }
    )),
    K === "values" && /* @__PURE__ */ x("div", { className: "legend item", children: [
      /* @__PURE__ */ c(
        "label",
        {
          className: "range min",
          style: {
            backgroundColor: N.getColorByValue(
              N.minValue
            ),
            color: "#fff"
          }
        }
      ),
      /* @__PURE__ */ c("label", { children: b.formatNumber(
        p.style === "percent" ? N.minValue / 100 : N.minValue,
        {
          ...p,
          minimumFractionDigits: 0
        }
      ) })
    ] }),
    K === "values" && /* @__PURE__ */ x("div", { className: "legend item", children: [
      /* @__PURE__ */ c(
        "label",
        {
          className: "range max",
          style: {
            backgroundColor: N.getColorByValue(
              N.maxValue
            ),
            color: "#fff"
          },
          children: " "
        }
      ),
      /* @__PURE__ */ c("label", { children: b.formatNumber(
        p.style === "percent" ? N.maxValue / 100 : N.maxValue,
        {
          ...p,
          minimumFractionDigits: 0
        }
      ) })
    ] }),
    te && re && j.map((e, t) => /* @__PURE__ */ x("div", { className: "legend item", onClick: () => Ft(t), children: [
      /* @__PURE__ */ c(
        "input",
        {
          className: L && k[t] ? "" : "ignore",
          type: "checkbox",
          checked: k[t],
          style: {
            backgroundColor: k[t] && L === !0 ? e.lineColor : "none",
            color: "#000"
          }
        }
      ),
      /* @__PURE__ */ c(
        "span",
        {
          className: L ? "checkmark-with-bg" : "checkmark",
          style: {
            backgroundColor: k[t] && L === !0 ? e.lineColor : "none"
          }
        }
      ),
      /* @__PURE__ */ c(
        "label",
        {
          className: k[t] ? "" : "ignore",
          style: {
            backgroundColor: k[t] && he === !0 ? e.lineColor : "none",
            color: de
          },
          children: e.title
        }
      )
    ] }))
  ] }));
  ve(() => {
    (() => {
      const r = 5 * Math.max(X.length - 5, 0);
      pt(r);
    })();
  }, [X]), ve(() => {
    We(R), _e(P);
  }, [v, R, P]);
  const bt = {
    bottom: `-${Be}px`
  }, vt = {
    bottom: `-${Be}px`,
    gap: "0px"
    // top: "0px",
  }, Nt = (e) => xe(e, "1 0", qe, "Y"), It = (e) => xe(e, "4 4", T, "X"), kt = (e) => xe(e, "1 0", qe, "X"), Lt = (e) => {
    const t = X.find((r) => r.id === e.value);
    return t ? t.color : "#FFFFFF";
  }, wt = (e) => {
    const { yScale: t, xScale: r, bars: i } = e;
    return /* @__PURE__ */ c(Ye, { children: i.filter((a) => a.data.value != null).map((a) => {
      let s = a.data.indexValue;
      f.dimensionsMetadata && f.dimensionsMetadata.size > 1 && (s = a.data.id);
      const l = fe.filter(
        (n) => n.serieLabel == s
      )[0];
      if (l && l.low && l.high)
        if (u === "horizontal") {
          const n = r(parseFloat(l.low)), h = r(parseFloat(l.high));
          return /* @__PURE__ */ x("g", { children: [
            /* @__PURE__ */ c(
              "line",
              {
                x1: n,
                x2: h,
                y1: a.y + a.height / 2,
                y2: a.y + a.height / 2,
                strokeWidth: 1,
                stroke: T
              }
            ),
            /* @__PURE__ */ c(
              "line",
              {
                x1: n,
                x2: n,
                y1: a.y + a.height / 2 - 3,
                y2: a.y + a.height / 2 + 3,
                strokeWidth: 1,
                stroke: T
              }
            ),
            /* @__PURE__ */ c(
              "line",
              {
                x1: h,
                x2: h,
                y1: a.y + a.height / 2 - 3,
                y2: a.y + a.height / 2 + 3,
                strokeWidth: 1,
                stroke: T
              }
            )
          ] });
        } else {
          const n = t(parseFloat(l.low)), h = t(parseFloat(l.high));
          return /* @__PURE__ */ x("g", { children: [
            /* @__PURE__ */ c(
              "line",
              {
                y1: n,
                y2: h,
                x1: a.x + a.width / 2,
                x2: a.x + a.width / 2,
                strokeWidth: 1,
                stroke: T
              }
            ),
            /* @__PURE__ */ c(
              "line",
              {
                y1: n,
                y2: n,
                x1: a.x + a.width / 2 - 3,
                x2: a.x + a.width / 2 + 3,
                strokeWidth: 1,
                stroke: T
              }
            ),
            /* @__PURE__ */ c(
              "line",
              {
                y1: h,
                y2: h,
                x1: a.x + a.width / 2 - 3,
                x2: a.x + a.width / 2 + 3,
                strokeWidth: 1,
                stroke: T
              }
            )
          ] });
        }
    }) });
  }, xe = (e, t, r, i) => {
    const { yScale: a, innerWidth: s, innerHeight: l } = e;
    let n, h;
    return i == "X" ? (n = [0, s], h = Ke().x((o, W) => W === 0 ? -10 : o).y(() => a(0))) : (n = [0, l], h = Ke().x(() => 0).y((o) => o)), /* @__PURE__ */ c(Ye, { children: /* @__PURE__ */ c(
      "path",
      {
        d: h(n),
        fill: "none",
        stroke: r,
        style: { pointerEvents: "none", strokeDasharray: t }
      }
    ) });
  }, D = (e, t) => w ? (A.colorBy === "index" || A.colorBy === "id" || A.colorBy === "values") && !t ? e.filter((r) => w.indexOf(r[f.indexBy]) === -1) : e ? e.filter((r) => w.indexOf(r) === -1) : [] : e, Dt = (e) => {
    const t = Pt();
    if (!e.value) return "";
    const r = Object.assign({}, e);
    (B || $) && ge.includes(String(r.value)) && (r.value = "");
    let i;
    Ge ? i = ne : i = Lt(e);
    let a = [], s = "";
    if ($ || B) {
      const n = String(r.value).split(" ");
      let h = 25;
      y && V === "Mobile" || U && !y ? h = (d == null ? void 0 : d.mobileMaxTickLength) ?? 25 : y && V === "Tablet" || J && !y ? h = (d == null ? void 0 : d.tabletMaxTickLength) ?? 25 : window.matchMedia("(min-width: 768px) and (max-width: 1250px)").matches && !y && (h = 15), n.forEach((o) => {
        s.length + String(o).length <= h ? s += (s ? " " : "") + o : (a.push(s), s = o);
      }), s && a.push(s);
    } else
      a = [r.value];
    let l = 12;
    return U ? l = (d == null ? void 0 : d.mobileYAxisLineHeight) ?? 12 : J && (l = (d == null ? void 0 : d.tabletYAxisLineHeight) ?? 12), z > 0 && z < 180 ? /* @__PURE__ */ x("g", { transform: `translate(${e.x},${e.y + 30})`, children: [
      Y && /* @__PURE__ */ c(
        "line",
        {
          stroke: i,
          strokeWidth: 1.5,
          y1: -32,
          y2: -12
        }
      ),
      /* @__PURE__ */ c("g", { transform: `translate(0, ${e.y + ae})`, children: a.map((n, h) => /* @__PURE__ */ c(
        "text",
        {
          transform: `rotate(${z})`,
          textAnchor: "start",
          y: typeof e.value == "number" ? 0 : h * l,
          dominantBaseline: "middle",
          style: {
            ...t.axis.ticks.text,
            fill: O === "null" ? "black" : O,
            fontSize: "12px",
            fontFamily: "sans-serif"
          },
          children: n
        },
        n
      )) })
    ] }) : z > 180 && z < 360 ? /* @__PURE__ */ x("g", { transform: `translate(${e.x},${e.y + 30})`, children: [
      Y && /* @__PURE__ */ c(
        "line",
        {
          stroke: i,
          strokeWidth: 1.5,
          y1: -32,
          y2: -12
        }
      ),
      /* @__PURE__ */ c("g", { transform: `translate(0, ${e.y + ae})`, children: a.map((n, h) => /* @__PURE__ */ c(
        "text",
        {
          transform: `rotate(${z})`,
          textAnchor: "end",
          y: typeof e.value == "number" ? 0 : h * l,
          dominantBaseline: "middle",
          style: {
            ...t.axis.ticks.text,
            fill: O === "null" ? "black" : O,
            fontSize: "12px",
            fontFamily: "sans-serif"
          },
          children: n
        },
        h
      )) })
    ] }) : /* @__PURE__ */ x("g", { transform: `translate(${e.x},${e.y + 30})`, children: [
      Y && /* @__PURE__ */ c(
        "line",
        {
          stroke: i,
          strokeWidth: 1.5,
          y1: -32,
          y2: -12
        }
      ),
      /* @__PURE__ */ c("g", { transform: `translate(0, ${e.y + ae})`, children: a.map((n, h) => /* @__PURE__ */ c(
        "text",
        {
          transform: `rotate(${z})`,
          textAnchor: "middle",
          y: typeof e.value == "number" ? 0 : h * l,
          dominantBaseline: "middle",
          style: {
            ...t.axis.ticks.text,
            fill: O === "null" ? "black" : O,
            fontSize: "12px",
            fontFamily: "sans-serif"
          },
          children: n
        },
        h
      )) })
    ] });
  }, Mt = (e) => {
    if (!e.value || ($ || B) && ge.includes(String(e.value)))
      return "";
    let t = e.value;
    if (u === "vertical") {
      const n = I || p;
      t = b.formatNumber(
        n.style === "percent" ? t / 100 : t,
        {
          ...n
        }
      );
    }
    let r = 25;
    y && V === "Mobile" || U && !y ? r = (d == null ? void 0 : d.mobileMaxTickLength) ?? 25 : y && V === "Tablet" || J && !y ? r = (d == null ? void 0 : d.tabletMaxTickLength) ?? 25 : window.matchMedia("(min-width: 768px) and (max-width: 1250px)").matches && !y && (r = 15);
    const i = typeof t == "string" ? t.split(" ") : [t], a = [];
    let s = "";
    i.forEach((n) => {
      s.length + String(n).length <= r ? s += (s ? " " : "") + n : (a.push(s), s = n);
    }), s && a.push(s);
    let l = 12;
    return y && V === "Mobile" || U && !y ? l = (d == null ? void 0 : d.mobileYAxisLineHeight) ?? 12 : (y && V === "Tablet" || J && !y) && (l = (d == null ? void 0 : d.tabletYAxisLineHeight) ?? 12), /* @__PURE__ */ x("g", { transform: `translate(${e.x},${e.y})`, children: [
      /* @__PURE__ */ c("line", { x1: -5, x2: 0, y1: 0, y2: 0, stroke: "#000", strokeWidth: 1 }),
      a.map((n, h) => /* @__PURE__ */ c(
        "text",
        {
          x: -10,
          y: typeof t == "number" ? 0 : h * l,
          textAnchor: "end",
          dominantBaseline: "middle",
          style: {
            fill: O === "null" ? "black" : O,
            fontSize: "12px",
            fontFamily: "sans-serif"
          },
          children: n
        },
        n
      ))
    ] });
  }, Ot = (e) => {
    const t = w.slice();
    if (t.indexOf(e) > -1) {
      const r = t.indexOf(e);
      t.splice(r, 1);
    } else
      t.push(e);
    yt(t);
  }, Ft = (e) => {
    const t = Object.assign({}, k);
    t[e] = !t[e], xt(t);
  }, zt = ({ bars: e }) => /* @__PURE__ */ c("g", { children: e.map((t) => {
    const { width: r, height: i, y: a, x: s, data: l } = t;
    if (u === "horizontal" && i <= oe || u === "vertical" && r <= ue)
      return;
    const n = l.value ? b.formatNumber(
      p.style === "percent" ? l.value / 100 : l.value,
      p
    ) : "", h = n.length;
    let o, W;
    if (u === "vertical" && r >= ue || u === "horizontal" && i >= oe)
      return u === "vertical" ? (o = a - 6, W = s + r / 2 - h * 3.5) : (o = a + i / 2 + 4, W = s + r + 5), /* @__PURE__ */ c(
        "text",
        {
          y: o,
          x: W,
          style: { fill: ye() },
          children: `${n}`
        }
      );
  }) }), Et = (e) => {
    const t = f.data.filter((i) => w.indexOf(i[f.indexBy]) == -1).map((i) => i[f.indexBy]), { bars: r } = e;
    return /* @__PURE__ */ c("g", { children: t.filter(
      (i) => r.filter((a) => a.data.indexValue == i).length > 0
    ).map((i) => {
      var G;
      const a = r.filter((m) => m.data.indexValue == i);
      let s = "right", l = 0, n = 0;
      if (u == "horizontal")
        F === "stacked" ? (C ? l = e.innerWidth - 20 : (l = a.map((m) => m.width).reduce((m, g) => m + g), S && (l = e.innerWidth - l)), n = e.yScale(i) + a[0].height / 2) : (C ? l = e.innerWidth : (l = a.map((m) => m.width).reduce((m, g) => m > g ? m : g), S && (l = e.innerWidth - l)), n = e.yScale(i) + a.map((m) => m.height).reduce((m, g) => m + g) / 2), l = l + parseInt(E) + 5;
      else if (s = "middle", F === "stacked")
        l = e.xScale(i) + a[0].width / 2, C ? n = n - parseInt(E) : S ? n = parseInt(E) + a.map((m) => m.height).reduce((m, g) => m + g) + 14 : n = e.innerHeight - parseInt(E) - a.map((m) => m.height).reduce((m, g) => m + g) - 5;
      else if (l = e.xScale(i) + a.map((m) => m.width).reduce((m, g) => m + g) / 2, S && (n = e.innerHeight), C)
        n = n - parseInt(E);
      else {
        if (a.length % 2 == 1) {
          const m = Math.floor(a.length / 2);
          n = a[m].height;
        } else {
          const m = a.length / 2;
          n = Math.max(
            a[m].height,
            a[m - 1].height
          );
        }
        S ? n = n + 14 + parseInt(E) : n = e.innerHeight - n - parseInt(E) - 5;
      }
      const h = f.data.filter(
        (m) => m[f.indexBy] === i
      )[0];
      let o = h.parent_variables ? h.parent_variables[Fe] : h[Fe];
      const W = K !== "index" ? (G = w == null ? void 0 : w.map((m) => h[m])) == null ? void 0 : G.reduce((m, g) => m + g, 0) : 0;
      return o -= W, /* @__PURE__ */ c("text", { y: n, x: l, style: { fill: ye() }, children: /* @__PURE__ */ x("tspan", { textAnchor: s, children: [
        Me ? Me + " " : "",
        b.formatNumber(
          Oe.style === "percent" ? o / 100 : o,
          Oe
        )
      ] }) });
    }) });
  }, Vt = {
    top: R,
    right: Ce,
    bottom: P,
    left: Ze
  };
  let pe;
  ke && (pe = Ne.parse(ke, {
    header: !1,
    dynamicTyping: !0
  }), Math.max(...pe.data.map((e) => e[1])), Math.min(...pe.data.map((e) => e[1])));
  const je = () => {
    const e = [];
    if (fe && fe.forEach((t) => {
      t.low && e.push(parseFloat(t.low)), t.high && e.push(parseFloat(t.high));
    }), f.data) {
      const t = D(f.data, !1), r = D(f.keys, !0);
      t.forEach((i) => {
        r.forEach((a) => {
          i[a] && e.push(i[a]);
        });
      });
    }
    return re && j && j.forEach((t, r) => {
      if (k[r] !== !1)
        if (t.app === "csv" && t.csvLineLayerData) {
          const i = Ne.parse(t.csvLineLayerData, {
            header: !1,
            dynamicTyping: !0
          });
          i.data && i.data.filter((a) => a[1] !== null && typeof a[1] == "number").forEach((a) => e.push(a[1]));
        } else t.measure[0] && f.data && f.data.forEach((i) => {
          var s;
          const a = (s = i.variables) == null ? void 0 : s[t.measure[0]];
          a !== null && typeof a == "number" && e.push(a);
        });
    }), e;
  }, $t = () => {
    const e = je(), t = e.length > 0 ? Math.max(...e) : 0;
    if (ie === "fixed" && ce !== null && ce !== "")
      return Number(ce);
    if (F === "stacked" && ie !== "fixed") {
      const r = D(f.data, !1), i = D(f.keys, !0);
      let a = i.length > 0 ? i : f.keys;
      const s = Math.max(
        ...r.map((l) => a.map((n) => l[n] ? l[n] : 0)).map((l) => l.length > 0 ? l.reduce((n, h) => n + h, 0) : 0)
      );
      return Math.max(s, t) * 1.1;
    }
    return t * 1.05;
  }, Bt = () => {
    const e = je(), t = e.length > 0 ? Math.min(...e) : 0;
    return ie === "fixed" && se !== null && String(se) !== "" ? Number(se) : t > 0 ? t * 0.9 : t * 1.1;
  }, Wt = Number($t()), Ht = Number(Bt()), Tt = Math.min(0, Ht), _t = Math.max(0, Wt), M = ["grid", "axes", "bars"];
  rt && M.push(Et), M.push(Nt), M.push(kt), re && j && j.forEach((e, t) => {
    if (k[t] == !0 || k[t] == null) {
      const { csvLineLayerData: r, lineColor: i, tooltip: a } = e;
      if (e.app == "csv") {
        const s = Ne.parse(r, {
          header: !1,
          dynamicTyping: !0
        });
        if (s.data && s.data.filter((l) => l[1] !== null).length > 0) {
          s.data = s.data.filter(
            (n) => n[1] !== null
          );
          const l = Xe(
            s,
            i,
            u,
            F,
            D(f.keys, !0),
            a,
            e.title,
            ""
          );
          M.push(l);
        }
      } else if (e.measure[0]) {
        const s = {}, l = f.data.map((o) => [
          o[f.indexBy],
          o.variables[e.measure[0]]
        ]), n = f.metadata.measures ? f.metadata.measures.filter((o) => o.value == e.measure[0]) : [];
        s.data = l;
        const h = Xe(
          s,
          i,
          u,
          F,
          D(f.keys, !0),
          a,
          e.title,
          n.length > 0 ? n[0].label : ""
        );
        M.push(h);
      }
    }
  }), we === Xt && M.push(zt), nt && M.push(It), M.push(wt);
  let Q = parseInt(ct);
  const Re = () => /* @__PURE__ */ c(be, { children: te && Le && /* @__PURE__ */ c("div", { className: "legend item", children: /* @__PURE__ */ c("label", { className: "legend-title", children: Le }) }) }), ge = [];
  if (B || $) {
    Q = Number.parseInt(d.yAxisTickValues);
    const e = new Map(
      Object.entries(((Pe = d == null ? void 0 : d.labels) == null ? void 0 : Pe.xAxis) ?? {})
    );
    for (const [t, r] of e)
      r || ge.push(t);
  }
  let q;
  if (u === "vertical" && (f != null && f.data) && f.data.length > 0) {
    const e = D(f.data, !1), t = [];
    if (e.forEach((r) => {
      const i = r == null ? void 0 : r[f.indexBy];
      i !== void 0 && t.indexOf(i) === -1 && t.push(i);
    }), ze === "count") {
      const r = Math.max(1, parseInt(String(ut)));
      if (t.length > 0 && r > 0)
        if (t.length <= r)
          q = t.slice();
        else {
          const i = (t.length - 1) / (r - 1), a = new Array(r);
          for (let s = 0; s < r; s++)
            a[s] = Math.floor(s * i);
          a[r - 1] = t.length - 1, q = a.map((s) => t[s]);
        }
    } else if (ze === "every") {
      const r = Math.max(1, parseInt(String(ot)));
      if (t.length > 0) {
        const i = [];
        for (let a = 0; a < t.length; a++)
          a % r === 0 && i.push(t[a]);
        i[i.length - 1] !== t[t.length - 1] && i.push(t[t.length - 1]), q = i;
      }
    }
  }
  let At = parseInt(Je + "") - Te;
  return /* @__PURE__ */ c("div", { style: { height: At + "px" }, className: "bar-chart", children: (f == null ? void 0 : f.data) && f.data.length > 0 && /* @__PURE__ */ x(be, { children: [
    /* @__PURE__ */ c(
      jt,
      {
        colorBy: A.colorBy,
        animate: !0,
        enableLabel: we == Kt,
        ...f,
        maxValue: _t,
        minValue: Tt,
        keys: D(f.keys, !0),
        data: D(f.data, !1),
        groupMode: F || "grouped",
        margin: Vt,
        innerPadding: tt,
        valueScale: { type: Qe, clamp: !0 },
        colors: (e) => e && e.data[ee] ? e.data[ee] : N.getColor(e.id, e.data),
        borderColor: "#000",
        reverse: S,
        axisTop: null,
        axisRight: lt ? {
          tickSize: u == "horizontal" && Y || u === "vertical" ? 5 : 0,
          tickPadding: 5,
          tickRotation: 0,
          tickValues: Q,
          legend: _.right,
          legendPosition: "middle",
          legendOffset: parseInt(De),
          format: (e) => {
            if (!e) return "";
            if (u == "vertical") {
              const t = I || p;
              return b.formatNumber(
                t.style === "percent" ? e / 100 : e,
                {
                  ...t
                }
              );
            }
            return e;
          }
        } : null,
        axisBottom: ($ || B) && (d == null ? void 0 : d.xAxisDisabled) === !0 ? null : u === "horizontal" ? {
          legend: _.bottom,
          legendPosition: "middle",
          legendOffset: parseInt(me),
          tickPadding: 5,
          tickRotation: 0,
          tickValues: Q,
          legend: _.right,
          legendPosition: "middle",
          legendOffset: parseInt(De),
          format: (e) => {
            if (!e) return "";
            if (u == "vertical") {
              const t = I || p;
              return b.formatNumber(
                t.style === "percent" ? e / 100 : e,
                {
                  ...t
                }
              );
            }
            return e;
          }
        } : null,
        axisBottom: ($ || B) && (d == null ? void 0 : d.xAxisDisabled) === !0 ? null : u === "horizontal" ? {
          legend: _.bottom,
          legendPosition: "middle",
          legendOffset: parseInt(me),
          tickPadding: 5,
          tickRotation: 0,
          tickValues: parseInt(st),
          format: (e) => {
            if (!e) return "";
            if (u == "horizontal") {
              const t = I || p;
              return b.formatNumber(
                t.style === "percent" ? e / 100 : e,
                {
                  ...t
                }
              );
            }
            return e;
          }
        } : {
          legend: _.bottom,
          legendPosition: "middle",
          legendOffset: parseInt(me),
          ...q ? { tickValues: q } : {},
          renderTick: Dt
        },
        axisLeft: {
          tickSize: u === "horizontal" && Y || u === "vertical" ? 5 : 0,
          tickPadding: 5,
          tickRotation: 0,
          tickValues: Q,
          legend: _.left,
          legendPosition: "middle",
          legendOffset: Number.parseInt(Ue),
          ...$ || B ? { renderTick: Mt } : {
            format: (e) => {
              if (!e) return "";
              if (u === "vertical") {
                const t = I || p;
                return b.formatNumber(
                  t.style === "percent" ? e / 100 : e,
                  {
                    ...t
                  }
                );
              }
              return e;
            }
          }
        },
        enableGridY: mt,
        enableGridX: ft,
        layout: u,
        labelSkipWidth: ue,
        labelSkipHeight: oe,
        padding: et,
        labelTextColor: ye(),
        label: (e) => b.formatNumber(
          p.style === "percent" && e.value ? e.value / 100 : e.value,
          p
        ),
        layers: M,
        onMouseEnter: (e) => {
        },
        onMouseLeave: (e) => {
        },
        motionStiffness: 130,
        motionDamping: 15,
        tooltip: (e) => at && le && le.trim().length > 0 ? /* @__PURE__ */ c(
          St,
          {
            intl: b,
            format: p,
            d: e,
            tooltip: le,
            tooltipEnableMarkdown: it
          }
        ) : null,
        theme: {
          tooltip: {
            basic: {
              whiteSpace: "pre",
              display: "flex",
              alignItems: "center"
            },
            container: {
              background: "transparent",
              boxShadow: ""
            },
            table: {},
            tableCell: { padding: "3px 5px" }
          }
        }
      }
    ),
    (v === "top" || v === "bottom") && Ae && /* @__PURE__ */ c(
      "div",
      {
        className: `legends container has-standard-12-font-size ${v}`,
        style: v === "bottom" ? { marginBottom: `${Te}px` } : {},
        children: /* @__PURE__ */ x("div", { className: "legend-sections", children: [
          /* @__PURE__ */ c("div", { className: "title-section", children: Re() }),
          /* @__PURE__ */ c(
            Yt,
            {
              onWrapChange: (e) => {
                if (v === "top" && Ee) {
                  const t = R + e / 2 * 40;
                  We(t), He(e);
                } else
                  _e(P + e / 2 * 25), He(e);
              },
              className: "legends container has-standard-12-font-size items-section",
              children: Se()
            }
          )
        ] })
      }
    ),
    (v === "right" || v === "left") && Ae && /* @__PURE__ */ x(
      "div",
      {
        className: `legends container has-standard-12-font-size  ${v}`,
        style: v === "right" ? bt : vt,
        children: [
          Re(),
          Se()
        ]
      }
    )
  ] }) });
}, fa = Rt(Zt);
export {
  fa as default
};
