import { jsx as e, jsxs as f } from "react/jsx-runtime";
import { BarChart as T, CartesianGrid as $, XAxis as w, YAxis as G, Bar as g, LabelList as c, Cell as P } from "recharts";
import { ChartContainer as R, ChartTooltip as X, ChartTooltipContent as Y, ChartLegend as q, ChartLegendContent as A } from "../ChartPrimitive.js";
import { useCallback as E } from "react";
const H = ({
  id: v,
  chartConfig: h,
  data: d,
  layout: t = "horizontal",
  xAxisOptions: m,
  yAxisOptions: C,
  showLabel: z = !1,
  customBarLabel: s,
  showLegend: N = !1,
  isStack: n = !1,
  isNative: b = !0,
  negativeData: i,
  grid: j = !0,
  activeBar: k,
  tooltipContent: x,
  height: u = 300,
  gridHorizontal: B,
  gridVertical: y = !1,
  displayFields: o,
  hideLegendIcon: I = !1
}) => {
  const p = Object.keys(h), K = o ? p.filter((r) => o == null ? void 0 : o.includes(r)) : p, L = t === "vertical" ? "right" : "top", S = E(
    (r, l) => {
      let a = 5;
      return n && (l === 0 ? a = t === "vertical" ? [4, 0, 0, 4] : [0, 0, 4, 4] : l === r - 1 ? a = t === "vertical" ? [0, 4, 4, 0] : [4, 4, 0, 0] : a = [0, 0, 0, 0]), a;
    },
    [n, t]
  );
  return /* @__PURE__ */ e(
    R,
    {
      id: v,
      config: h,
      className: "w-full",
      ...u && {
        style: { height: u }
      },
      children: /* @__PURE__ */ f(
        T,
        {
          accessibilityLayer: !0,
          data: d,
          layout: t,
          margin: {
            top: 40,
            right: 40,
            bottom: 40,
            left: t === "vertical" ? 0 : 40
          },
          children: [
            j && /* @__PURE__ */ e($, { opacity: 0.8, stroke: "var(--base-border)", vertical: y, horizontal: B }),
            m && /* @__PURE__ */ e(w, { tickLine: !1, axisLine: !1, ...m }),
            C && /* @__PURE__ */ e(G, { tickLine: !1, axisLine: !1, ...C }),
            /* @__PURE__ */ e(X, { cursor: !1, content: /* @__PURE__ */ e(Y, { hideLabel: !0, ...x }) }),
            N && /* @__PURE__ */ e(q, { content: /* @__PURE__ */ e(A, { hideIcon: I }) }),
            b && K.map((r, l) => {
              const a = S(K.length, l);
              return /* @__PURE__ */ f(
                g,
                {
                  dataKey: r,
                  layout: t,
                  fill: `var(--color-${r})`,
                  radius: a,
                  activeBar: k,
                  ...n && { stackId: "a" },
                  children: [
                    z && /* @__PURE__ */ e(c, { position: L, offset: 12, className: "fill-[--base-foreground]", fontSize: 12 }),
                    s && /* @__PURE__ */ e(
                      c,
                      {
                        dataKey: s.dataKey,
                        position: s.position,
                        offset: 8,
                        className: "fill-[var(--base-background)]",
                        fontSize: 12
                      }
                    )
                  ]
                },
                r
              );
            }),
            !b && i ? /* @__PURE__ */ f(g, { dataKey: String(i.dataKey), children: [
              /* @__PURE__ */ e(c, { position: L, dataKey: String(i.valueKey), fillOpacity: 1 }),
              d.map((r) => /* @__PURE__ */ e(P, { fill: Number(r[i.dataKey]) > 0 ? "var(--base-chart-1)" : "var(--base-chart-2)" }, i.valueKey))
            ] }) : null
          ]
        }
      )
    }
  );
};
H.displayName = "BarChart";
export {
  H as default
};
//# sourceMappingURL=BarChart.js.map
