import { cn } from "./index3.js";
import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent } from "./index46.js";
import { useReducedMotion } from "./index47.js";
import { WrapperChartLegend } from "./index49.js";
import { cva } from "class-variance-authority";
import * as React from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts";
//#region src/components/molecules/charts/HorizontalBarChart/HorizontalBarChart.tsx
var horizontalBarChartVariants = cva("relative w-full", {
	variants: { size: {
		sm: "h-40",
		default: "h-60",
		lg: "h-80",
		xl: "h-96"
	} },
	defaultVariants: { size: "default" }
});
function HorizontalBarChart({ data, series, showXAxis = true, showYAxis = true, xAxisLabel, legendPosition = "none", xAxisTicks, xAxisFormat = (v) => v.toLocaleString(), barRadius = 4, barColor = "var(--chart-1)", showTooltip = true, size, className, "aria-label": ariaLabel, ...props }) {
	const prefersReducedMotion = useReducedMotion();
	const chartData = React.useMemo(() => data.map((d) => ({
		label: d.label,
		value: d.value
	})), [data]);
	const chartConfig = React.useMemo(() => ({ value: {
		label: series?.[0]?.label || "Value",
		color: series?.[0]?.color || barColor
	} }), [series, barColor]);
	const maxValue = React.useMemo(() => Math.max(...data.map((d) => d.value)), [data]);
	return /* @__PURE__ */ jsx("div", {
		className: cn(horizontalBarChartVariants({ size }), className),
		role: "img",
		"aria-label": ariaLabel || "Horizontal bar chart",
		...props,
		children: /* @__PURE__ */ jsxs("div", {
			className: "flex h-full flex-col",
			children: [
				legendPosition === "top" && series && /* @__PURE__ */ jsx("div", {
					className: "flex justify-end pb-2",
					children: /* @__PURE__ */ jsx(WrapperChartLegend, {
						series,
						position: "top"
					})
				}),
				/* @__PURE__ */ jsxs("div", {
					className: "flex-1 flex",
					children: [/* @__PURE__ */ jsx(ChartContainer, {
						config: chartConfig,
						className: "flex-1 min-h-0 aspect-auto",
						children: /* @__PURE__ */ jsxs(BarChart, {
							data: chartData,
							layout: "vertical",
							margin: {
								top: 8,
								right: 8,
								bottom: xAxisLabel ? 20 : 0,
								left: 0
							},
							children: [
								/* @__PURE__ */ jsx(CartesianGrid, {
									strokeDasharray: "0",
									horizontal: false,
									className: "stroke-border"
								}),
								showYAxis && /* @__PURE__ */ jsx(YAxis, {
									dataKey: "label",
									type: "category",
									tickLine: false,
									axisLine: false,
									tickMargin: 8,
									tick: {
										fill: "var(--muted-foreground)",
										fontSize: 12
									},
									width: 60
								}),
								showXAxis && /* @__PURE__ */ jsx(XAxis, {
									type: "number",
									tickLine: false,
									axisLine: false,
									tickMargin: 8,
									tick: {
										fill: "var(--muted-foreground)",
										fontSize: 12
									},
									tickFormatter: xAxisFormat,
									ticks: xAxisTicks,
									domain: [0, maxValue]
								}),
								showTooltip && /* @__PURE__ */ jsx(ChartTooltip, {
									content: /* @__PURE__ */ jsx(ChartTooltipContent, {}),
									cursor: {
										fill: "var(--muted)",
										className: "transition-opacity duration-200 ease-smooth motion-reduce:transition-none"
									}
								}),
								legendPosition !== "none" && /* @__PURE__ */ jsx(ChartLegend, { content: /* @__PURE__ */ jsx(ChartLegendContent, {}) }),
								/* @__PURE__ */ jsx(Bar, {
									dataKey: "value",
									fill: "var(--color-value)",
									radius: [
										0,
										barRadius,
										barRadius,
										0
									],
									isAnimationActive: !prefersReducedMotion,
									animationDuration: 300,
									animationEasing: "ease-in-out"
								})
							]
						})
					}), legendPosition === "right" && series && /* @__PURE__ */ jsx("div", {
						className: "ps-3 flex items-start pt-2",
						children: /* @__PURE__ */ jsx(WrapperChartLegend, {
							series,
							position: "right"
						})
					})]
				}),
				xAxisLabel && /* @__PURE__ */ jsx("div", {
					className: "flex justify-center pt-2",
					children: /* @__PURE__ */ jsx("span", {
						className: "text-xs font-medium text-muted-foreground",
						children: xAxisLabel
					})
				})
			]
		})
	});
}
HorizontalBarChart.displayName = "HorizontalBarChart";
//#endregion
export { HorizontalBarChart, horizontalBarChartVariants };

//# sourceMappingURL=index52.js.map