import { cx as e } from "../../theme/tools.js";
import { DataTable as t } from "./DataTable.js";
import { card as n, cardActionContent as r, cardActions as i, cardBadges as a, cardHeader as o, cardMetaGrid as s, cardMetaItem as c, cardMetaLabel as l, cardMetaValue as u, cardSubtitle as d, cardTitle as f, cardTitleGroup as p, cards as m, cardsOnly as h, cardsViewport as g, containedRoot as _, tableOnly as v } from "./ResponsiveRecordList.css.js";
import { useEffect as y, useState as b } from "react";
import { Fragment as x, jsx as S, jsxs as C } from "react/jsx-runtime";
//#region src/components/data-table/ResponsiveRecordList.tsx
var w = "(max-width: 767px)", T = (e, t) => e == null ? null : e.cell(t), E = (e, t) => e.find((e) => e.mobileRole === t) ?? null, D = (e) => e.mobileRole === "hidden" ? !1 : e.mobileRole === "meta" ? !0 : e.mobileRole == null ? e.priority === "important" || e.priority === "secondary" : !1, O = () => {
	let [e, t] = b(() => typeof window > "u" ? !1 : window.matchMedia(w).matches);
	return y(() => {
		if (typeof window > "u") return () => {};
		let e = window.matchMedia(w), n = () => {
			t(e.matches);
		};
		return n(), e.addEventListener("change", n), () => {
			e.removeEventListener("change", n);
		};
	}, []), e;
}, k = ({ columns: y, rows: b, getRowId: w, mode: k = "auto", density: A = "compact", renderAction: j, className: M, bodyScrollMode: N, ...P }) => {
	let F = N === "contained", I = O(), L = null, R, z = null;
	F && (L = _, R = g, z = g);
	let B = E(y, "title") ?? y.find((e) => e.isPrimary === !0 || e.priority === "primary") ?? y[0] ?? null, V = E(y, "subtitle"), H = y.filter((e) => e.mobileRole === "badge" || e.mobileRole === "status"), U = y.filter((e) => e !== B && e !== V && D(e)), W = /* @__PURE__ */ S(x, { children: P.emptyState ?? null });
	if (b.length > 0 && (W = /* @__PURE__ */ S("div", {
		className: m,
		children: b.map((e, t) => {
			let m = w(e, t), h = T(B, e), g = T(V, e), _ = j?.(e), v = null;
			g != null && g !== "" && (v = /* @__PURE__ */ S("div", {
				className: d,
				children: g
			}));
			let y = null;
			_ != null && (y = /* @__PURE__ */ S("div", {
				className: i,
				children: /* @__PURE__ */ S("div", {
					className: r,
					children: _
				})
			}));
			let b = null;
			H.length > 0 && (b = /* @__PURE__ */ S("div", {
				className: a,
				children: H.map((t) => /* @__PURE__ */ S("span", { children: t.cell(e) }, t.id))
			}));
			let x = null;
			return U.length > 0 && (x = /* @__PURE__ */ S("dl", {
				className: s,
				children: U.map((t) => /* @__PURE__ */ C("div", {
					className: c,
					children: [/* @__PURE__ */ S("dt", {
						className: l,
						children: t.header
					}), /* @__PURE__ */ S("dd", {
						className: u,
						children: t.cell(e)
					})]
				}, t.id))
			})), /* @__PURE__ */ C("article", {
				className: n({ density: A }),
				children: [
					/* @__PURE__ */ C("div", {
						className: o,
						children: [/* @__PURE__ */ C("div", {
							className: p,
							children: [/* @__PURE__ */ S("div", {
								className: f,
								children: h
							}), v]
						}), y]
					}),
					b,
					x
				]
			}, m);
		})
	})), k === "cards") return /* @__PURE__ */ S("div", {
		className: e(M, L),
		children: /* @__PURE__ */ C("div", {
			className: R,
			children: [W, P.bodyFooterNode]
		})
	});
	if (k === "table") return /* @__PURE__ */ S(t, {
		...P,
		rows: b,
		columns: y,
		getRowId: w,
		className: M,
		density: A,
		bodyScrollMode: N,
		bodyFooterNode: P.bodyFooterNode
	});
	let G = P.bodyFooterNode, K = null;
	return I && (G = null, K = P.bodyFooterNode), /* @__PURE__ */ C("div", {
		className: e(M, L),
		children: [/* @__PURE__ */ S(t, {
			...P,
			rows: b,
			columns: y,
			getRowId: w,
			density: A,
			className: v,
			bodyScrollMode: N,
			bodyFooterNode: G
		}), /* @__PURE__ */ C("div", {
			className: e(h, z),
			children: [W, K]
		})]
	});
};
//#endregion
export { k as ResponsiveRecordList, k as default };

//# sourceMappingURL=ResponsiveRecordList.js.map