import { o as H } from "./rolldown-runtime.js";
import { i as O, t as D } from "./vendor/react.js";
import { C as E, b as F, g as K, v as M, y as q } from "./vendor/recharts.js";
import { t as U } from "./dist.js";
import { t as V } from "./utils.js";
import { a as $, i as b, n as G, o as I, r as R, t as W } from "./use-reduced-motion2.js";
import { a as X, i as d, r as u, t as Y } from "./LineChart.js";
var v = /* @__PURE__ */ H(O(), 1), t = D(), J = [
  "var(--border)",
  "var(--chart-2)",
  "var(--chart-1)"
], Q = U("relative w-full", {
  variants: { size: {
    sm: "h-40",
    default: "h-60",
    lg: "h-80",
    xl: "h-96"
  } },
  defaultVariants: { size: "default" }
});
function Z({ data: f, series: e, showYAxis: g = !0, showXAxis: j = !0, yAxisLabel: h, xAxisLabel: c, legendPosition: m = "none", yAxisTicks: k, yAxisFormat: C = (l) => l.toLocaleString(), barMode: o = "stacked", barRadius: n = 4, showTooltip: y = !0, size: N, className: _, "aria-label": S, ...L }) {
  const l = W(), { highlightedSeries: x, setHighlightedSeries: p, getOpacity: B, dimTransition: T } = X(l), w = v.useMemo(() => f.map((a) => {
    const s = { label: a.label };
    for (const r of e) {
      const i = d(r.id);
      s[i] = a.values[r.id] ?? 0;
    }
    return s;
  }), [f, e]), z = v.useMemo(() => {
    const a = o === "stacked" ? J : Y, s = {};
    for (const [r, i] of e.entries()) {
      const A = d(i.id);
      s[A] = {
        label: i.label,
        color: i.color || a[r % a.length]
      };
    }
    return s;
  }, [e, o]);
  return /* @__PURE__ */ (0, t.jsx)("div", {
    className: V(Q({ size: N }), _),
    role: "img",
    "aria-label": S || "Bar chart",
    ...L,
    children: /* @__PURE__ */ (0, t.jsxs)("div", {
      className: "flex h-full gap-1",
      children: [h && /* @__PURE__ */ (0, t.jsx)("div", {
        className: "flex items-center justify-center pb-6",
        children: /* @__PURE__ */ (0, t.jsx)("span", {
          className: "text-xs font-medium text-muted-foreground whitespace-nowrap",
          style: {
            writingMode: "vertical-rl",
            transform: "rotate(180deg)"
          },
          children: h
        })
      }), /* @__PURE__ */ (0, t.jsxs)("div", {
        className: "flex-1 flex flex-col min-w-0",
        children: [
          m === "top" && /* @__PURE__ */ (0, t.jsx)("div", {
            className: "flex justify-end pb-2",
            children: /* @__PURE__ */ (0, t.jsx)(u, {
              series: e,
              position: "top",
              onSeriesHover: p,
              highlightedSeries: x
            })
          }),
          /* @__PURE__ */ (0, t.jsxs)("div", {
            className: "flex-1 flex",
            children: [/* @__PURE__ */ (0, t.jsx)(G, {
              config: z,
              className: "flex-1 min-h-0 aspect-auto",
              children: /* @__PURE__ */ (0, t.jsxs)(K, {
                data: w,
                margin: {
                  top: 8,
                  right: 8,
                  bottom: c ? 20 : 0,
                  left: 0
                },
                children: [
                  /* @__PURE__ */ (0, t.jsx)(E, {
                    strokeDasharray: "0",
                    vertical: !1,
                    className: "stroke-border"
                  }),
                  j && /* @__PURE__ */ (0, t.jsx)(q, {
                    dataKey: "label",
                    tickLine: !1,
                    axisLine: !1,
                    tickMargin: 8,
                    tick: {
                      fill: "var(--muted-foreground)",
                      fontSize: 12
                    }
                  }),
                  g && /* @__PURE__ */ (0, t.jsx)(M, {
                    tickLine: !1,
                    axisLine: !1,
                    tickMargin: 8,
                    tick: {
                      fill: "var(--muted-foreground)",
                      fontSize: 12
                    },
                    tickFormatter: C,
                    ticks: k,
                    width: 48
                  }),
                  y && /* @__PURE__ */ (0, t.jsx)($, {
                    content: /* @__PURE__ */ (0, t.jsx)(I, {}),
                    cursor: l ? !1 : { fill: "var(--muted)" }
                  }),
                  m !== "none" && /* @__PURE__ */ (0, t.jsx)(R, { content: /* @__PURE__ */ (0, t.jsx)(b, {}) }),
                  (o === "stacked" ? [...e].reverse() : e).map((a, s) => {
                    const r = d(a.id), i = o === "stacked" && s === e.length - 1;
                    return /* @__PURE__ */ (0, t.jsx)(F, {
                      dataKey: r,
                      stackId: o === "stacked" ? "stack" : void 0,
                      fill: `var(--color-${r})`,
                      radius: o === "stacked" ? i ? [
                        n,
                        n,
                        0,
                        0
                      ] : [
                        0,
                        0,
                        0,
                        0
                      ] : [
                        n,
                        n,
                        n,
                        n
                      ],
                      opacity: B(a.id),
                      style: T,
                      isAnimationActive: !l
                    }, r);
                  })
                ]
              })
            }), m === "right" && /* @__PURE__ */ (0, t.jsx)("div", {
              className: "ps-3 flex items-start pt-2",
              children: /* @__PURE__ */ (0, t.jsx)(u, {
                series: e,
                position: "right",
                onSeriesHover: p,
                highlightedSeries: x
              })
            })]
          }),
          c && /* @__PURE__ */ (0, t.jsx)("div", {
            className: "flex justify-center pt-2",
            children: /* @__PURE__ */ (0, t.jsx)("span", {
              className: "text-xs font-medium text-muted-foreground",
              children: c
            })
          })
        ]
      })]
    })
  });
}
Z.displayName = "BarChart";
export {
  Z as t
};

//# sourceMappingURL=BarChart.js.map