import { t as e } from "../utils-B7XIe3qq.js";
import { Card as t } from "../react/primitives/card.js";
import { Progress as n } from "../react/primitives/progress.js";
import "react";
import { jsx as r, jsxs as i } from "react/jsx-runtime";
//#region src/composites/metrics-card.tsx
function a(e, t) {
	if (typeof e == "string") return e;
	if (!Number.isFinite(e)) return "—";
	switch (t) {
		case "number": return e.toLocaleString();
		case "percent": return `${(Math.abs(e) <= 1 ? e * 100 : e).toFixed(1)}%`;
		case "expo": return e.toExponential(2);
		case "eta":
		case "duration": {
			let t = Math.max(0, Math.round(e)), n = Math.floor(t / 3600), r = Math.floor(t % 3600 / 60), i = t % 60, a = [];
			return n > 0 && a.push(`${String(n)}h`), (n > 0 || r > 0) && a.push(`${String(r)}m`), a.push(`${String(i)}s`), a.join(" ");
		}
		default: return String(e);
	}
}
function o({ title: o, items: s, progress: c, className: l, ...u }) {
	let d = c && c.total > 0 ? Math.min(100, Math.max(0, c.value / c.total * 100)) : null, f = c && c.total > 0 ? `${c.value.toLocaleString()} / ${c.total.toLocaleString()}` : void 0;
	return /* @__PURE__ */ i(t, {
		tone: "shadcn",
		className: e("p-4", l),
		...u,
		children: [
			o && /* @__PURE__ */ r("div", {
				className: "mb-3 text-sm font-semibold text-foreground",
				children: o
			}),
			/* @__PURE__ */ r("dl", {
				className: "grid grid-cols-2 gap-x-4 gap-y-2 sm:grid-cols-3",
				children: s.map((e) => /* @__PURE__ */ i("div", {
					className: "flex flex-col",
					children: [/* @__PURE__ */ r("dt", {
						className: "text-xs text-muted-foreground",
						children: e.label
					}), /* @__PURE__ */ r("dd", {
						className: "text-sm font-semibold tabular-nums text-foreground",
						children: a(e.value, e.format)
					})]
				}, e.label))
			}),
			c && /* @__PURE__ */ r("div", {
				className: "mt-4",
				children: /* @__PURE__ */ r(n, {
					value: d,
					showLabel: d !== null,
					...f ? { secondaryLabel: f } : {}
				})
			})
		]
	});
}
//#endregion
export { o as MetricsCard };

//# sourceMappingURL=metrics-card.js.map