import { vars as e } from "../../theme/themeContract.css.js";
import { chartContainer as t, emptyState as n, tooltip as r, tooltipDate as i, tooltipRow as a, tooltipRowLabel as o, tooltipSwatch as s } from "./metricHistoryChart.css.js";
import { formatAxisTimestamp as c, formatDefaultTimestamp as l, formatDefaultValue as u } from "../../internal/charts/metricHistoryChartHelpers.js";
import { jsx as d, jsxs as f } from "react/jsx-runtime";
import { ResponsiveLine as p } from "@nivo/line";
//#region src/components/charts/MetricHistoryChart.tsx
var m = ({ ariaLabel: m, emptyMessage: h = "No data", formatTimestamp: g = l, formatValue: _ = u, series: v }) => {
	let y = v.filter((e) => e.data.length > 0);
	if (y.length === 0) return /* @__PURE__ */ d("div", {
		className: n,
		children: h
	});
	let b = Object.fromEntries(y.map((e) => [e.id, {
		color: e.color,
		label: e.label,
		unit: e.unit
	}]));
	return /* @__PURE__ */ d("div", {
		className: t,
		children: /* @__PURE__ */ d(p, {
			data: y.map((e) => ({
				id: e.id,
				data: e.data.map((e) => ({
					x: new Date(e.x),
					y: e.y
				}))
			})),
			margin: {
				top: 14,
				right: 16,
				bottom: 74,
				left: 52
			},
			colors: (t) => b[String(t.id)]?.color ?? e.colors.primary,
			xScale: {
				type: "time",
				format: "native",
				precision: "minute",
				useUTC: !1
			},
			xFormat: "time:%Y-%m-%dT%H:%M:%S.%LZ",
			yScale: {
				type: "linear",
				min: "auto",
				max: "auto"
			},
			curve: "monotoneX",
			lineWidth: 2.5,
			pointSize: 4,
			pointBorderWidth: 2,
			pointBorderColor: {
				from: "seriesColor",
				modifiers: [["darker", .2]]
			},
			enableArea: !0,
			areaOpacity: .1,
			enableGridX: !1,
			enableGridY: !0,
			axisTop: null,
			axisRight: null,
			axisBottom: {
				format: (e) => e instanceof Date ? c(e) : "",
				tickSize: 0,
				tickPadding: 10,
				tickValues: "every 15 minutes"
			},
			axisLeft: {
				tickSize: 0,
				tickPadding: 8,
				tickValues: 5,
				format: (e) => typeof e == "number" ? new Intl.NumberFormat(void 0, {
					notation: "compact",
					maximumFractionDigits: 1
				}).format(e) : ""
			},
			enablePoints: !0,
			useMesh: !0,
			legends: [{
				anchor: "bottom",
				direction: "row",
				translateY: 56,
				itemWidth: 110,
				itemHeight: 16,
				itemsSpacing: 8,
				symbolSize: 10,
				symbolShape: "circle",
				itemTextColor: e.colors.textSecondary,
				data: y.map((e) => ({
					id: e.id,
					label: e.label,
					color: e.color
				}))
			}],
			theme: {
				grid: { line: { stroke: e.colors.borderLight } },
				axis: { ticks: { text: {
					fill: e.colors.textMuted,
					fontSize: 12
				} } },
				crosshair: { line: {
					stroke: e.colors.border,
					strokeWidth: 1,
					strokeDasharray: "4 4"
				} },
				tooltip: { container: {
					background: "transparent",
					boxShadow: "none",
					padding: 0
				} }
			},
			sliceTooltip: ({ slice: e }) => {
				let t = e.points[0], n = String(e.id);
				t?.data.x instanceof Date && (n = t.data.x.toISOString());
				let c = [...e.points].map((e) => {
					let t = Number(e.data.y);
					if (typeof e.data.y == "number" && (t = e.data.y), Number.isNaN(t)) return null;
					let n = String(e.seriesId), r = b[n];
					return {
						seriesId: n,
						label: r?.label ?? n,
						value: t,
						color: e.seriesColor,
						unit: r?.unit
					};
				}).filter((e) => e != null);
				return /* @__PURE__ */ f("div", {
					className: r,
					children: [/* @__PURE__ */ d("p", {
						className: i,
						children: g(n)
					}), c.map((e) => /* @__PURE__ */ f("div", {
						className: a,
						children: [/* @__PURE__ */ f("span", {
							className: o,
							children: [/* @__PURE__ */ d("span", {
								className: s,
								style: { backgroundColor: e.color },
								"aria-hidden": !0
							}), /* @__PURE__ */ d("span", { children: e.label })]
						}), /* @__PURE__ */ d("strong", { children: _(e.value, e.unit) })]
					}, `${e.seriesId}-${n}`))]
				});
			},
			enableSlices: "x",
			role: "img",
			ariaLabel: m
		})
	});
};
//#endregion
export { m as MetricHistoryChart, m as default };

//# sourceMappingURL=MetricHistoryChart.js.map