import { n as cn } from "./utils-DXzSsU1e.js";
import { n as CardTitle_default, o as CardContent_default, r as CardHeader_default, s as Card_default } from "./card-X74FuL7B.js";
import { a as TableCell_default, c as Table_default, n as TableHeader_default, r as TableHead_default, s as TableBody_default, t as TableRow_default } from "./table-d-2vl8Cn.js";
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, normalizeClass, openBlock, renderList, toDisplayString, unref, withCtx } from "vue";
//#region src/components/compositions/elements/card/DatatableCard.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = {
	key: 1,
	class: "text-sm text-muted-foreground"
};
//#endregion
//#region src/components/compositions/elements/card/DatatableCard.vue
var DatatableCard_default = /* @__PURE__ */ defineComponent({
	__name: "DatatableCard",
	props: {
		label: {},
		title: {},
		showCard: {
			type: Boolean,
			default: true
		},
		tableColumns: { default: () => [] },
		rows: { default: () => [] },
		dataRoute: {},
		item: { default: () => ({}) },
		name: {},
		classList: {}
	},
	setup(__props) {
		/**
		* `card.datatable` element composition.
		*
		* Renders a simple sortable data table. Column definitions come from
		* `tableColumns`; row data is either supplied via `item[name]` or fetched
		* from `dataRoute`. Full pagination/filter support is handled by the
		* platform's DataTableCard when used in the card-tier — this element-tier
		* variant is intentionally lightweight for inline embedding.
		*/
		const props = __props;
		const heading = computed(() => props.title ?? props.label);
		const resolvedRows = computed(() => {
			if (props.rows && props.rows.length > 0) return props.rows;
			const name = props.name;
			if (name && props.item[name]) {
				const val = props.item[name];
				if (Array.isArray(val)) return val;
			}
			return [];
		});
		function cellValue(row, col) {
			const val = row[col.key];
			return val !== void 0 && val !== null ? String(val) : "—";
		}
		return (_ctx, _cache) => {
			return props.showCard !== false ? (openBlock(), createBlock(unref(Card_default), {
				key: 0,
				class: normalizeClass(unref(cn)(props.classList))
			}, {
				default: withCtx(() => [heading.value ? (openBlock(), createBlock(unref(CardHeader_default), { key: 0 }, {
					default: withCtx(() => [createVNode(unref(CardTitle_default), null, {
						default: withCtx(() => [createTextVNode(toDisplayString(heading.value), 1)]),
						_: 1
					})]),
					_: 1
				})) : createCommentVNode("", true), createVNode(unref(CardContent_default), null, {
					default: withCtx(() => [props.tableColumns.length ? (openBlock(), createBlock(unref(Table_default), { key: 0 }, {
						default: withCtx(() => [createVNode(unref(TableHeader_default), null, {
							default: withCtx(() => [createVNode(unref(TableRow_default), null, {
								default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(props.tableColumns, (col) => {
									return openBlock(), createBlock(unref(TableHead_default), { key: col.key }, {
										default: withCtx(() => [createTextVNode(toDisplayString(col.label), 1)]),
										_: 2
									}, 1024);
								}), 128))]),
								_: 1
							})]),
							_: 1
						}), createVNode(unref(TableBody_default), null, {
							default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(resolvedRows.value, (row, i) => {
								return openBlock(), createBlock(unref(TableRow_default), { key: i }, {
									default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(props.tableColumns, (col) => {
										return openBlock(), createBlock(unref(TableCell_default), { key: col.key }, {
											default: withCtx(() => [createTextVNode(toDisplayString(cellValue(row, col)), 1)]),
											_: 2
										}, 1024);
									}), 128))]),
									_: 2
								}, 1024);
							}), 128)), !resolvedRows.value.length ? (openBlock(), createBlock(unref(TableRow_default), { key: 0 }, {
								default: withCtx(() => [createVNode(unref(TableCell_default), {
									colspan: props.tableColumns.length || 1,
									class: "text-center text-muted-foreground"
								}, {
									default: withCtx(() => [createTextVNode(toDisplayString(props.dataRoute ? `Data fetched from: ${props.dataRoute}` : "No data."), 1)]),
									_: 1
								}, 8, ["colspan"])]),
								_: 1
							})) : createCommentVNode("", true)]),
							_: 1
						})]),
						_: 1
					})) : (openBlock(), createElementBlock("p", _hoisted_1, "No columns configured."))]),
					_: 1
				})]),
				_: 1
			}, 8, ["class"])) : (openBlock(), createElementBlock("div", {
				key: 1,
				class: normalizeClass(unref(cn)(props.classList))
			}, [props.tableColumns.length ? (openBlock(), createBlock(unref(Table_default), { key: 0 }, {
				default: withCtx(() => [createVNode(unref(TableHeader_default), null, {
					default: withCtx(() => [createVNode(unref(TableRow_default), null, {
						default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(props.tableColumns, (col) => {
							return openBlock(), createBlock(unref(TableHead_default), { key: col.key }, {
								default: withCtx(() => [createTextVNode(toDisplayString(col.label), 1)]),
								_: 2
							}, 1024);
						}), 128))]),
						_: 1
					})]),
					_: 1
				}), createVNode(unref(TableBody_default), null, {
					default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(resolvedRows.value, (row, i) => {
						return openBlock(), createBlock(unref(TableRow_default), { key: i }, {
							default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(props.tableColumns, (col) => {
								return openBlock(), createBlock(unref(TableCell_default), { key: col.key }, {
									default: withCtx(() => [createTextVNode(toDisplayString(cellValue(row, col)), 1)]),
									_: 2
								}, 1024);
							}), 128))]),
							_: 2
						}, 1024);
					}), 128))]),
					_: 1
				})]),
				_: 1
			})) : createCommentVNode("", true)], 2));
		};
	}
});
//#endregion
export { DatatableCard_default as default };

//# sourceMappingURL=DatatableCard-DEBu_qR8.js.map