import { n as cn } from "./utils-DXzSsU1e.js";
import { i as resolveCardPath } from "./registry-CjoawJ_B.js";
import { n as createMissingFallback, t as shouldRender } from "./useDisplayConditions-DNEDur9S.js";
import { computed, createBlock, createCommentVNode, createElementBlock, defineAsyncComponent, defineComponent, guardReactiveProps, normalizeClass, normalizeProps, openBlock, resolveDynamicComponent } from "vue";
//#region src/engine/useCardLoader.ts
var cardModules = /* @__PURE__ */ Object.assign({
	"../components/compositions/cards/CardListCard.vue": () => import("./CardListCard-DXGL9GKo.js").then((n) => n.n),
	"../components/compositions/cards/DataTableCard.vue": () => import("./DataTableCard-T4g6bRiT.js").then((n) => n.n),
	"../components/compositions/cards/ElementDisplayCard.vue": () => import("./ElementDisplayCard-Dr7gYR3X.js").then((n) => n.n),
	"../components/compositions/cards/ElementListCard.vue": () => import("./ElementListCard-CDiWUb_B.js").then((n) => n.n),
	"../components/compositions/cards/GridViewCard.vue": () => import("./GridViewCard-BXs73PQW.js").then((n) => n.n),
	"../components/compositions/cards/InfoCard.vue": () => import("./InfoCard-A-wKCoRP.js").then((n) => n.n),
	"../components/compositions/cards/TabListCard.vue": () => import("./TabListCard-CdWNXO_e.js").then((n) => n.n)
});
var componentCache = /* @__PURE__ */ new Map();
/**
* Resolves the Vue component for a given DisplayCard `cardType`.
* Same lazy-loading + fallback semantics as `getElementComponent`.
*/
function getCardComponent(cardType) {
	const cached = componentCache.get(cardType);
	if (cached) return cached;
	const path = resolveCardPath(cardType);
	if (!path) {
		const fallback = createMissingFallback("card", cardType);
		componentCache.set(cardType, fallback);
		return fallback;
	}
	const importer = cardModules[`../components/compositions/cards/${path}.vue`];
	if (!importer) {
		const fallback = createMissingFallback("card", cardType, path);
		componentCache.set(cardType, fallback);
		return fallback;
	}
	const component = defineAsyncComponent({
		loader: async () => {
			const mod = await importer();
			return mod.default ?? mod;
		},
		errorComponent: createMissingFallback("card", cardType, path),
		delay: 0,
		suspensible: false
	});
	componentCache.set(cardType, component);
	return component;
}
function preloadCard(cardType) {
	const path = resolveCardPath(cardType);
	if (!path) return Promise.resolve();
	const importer = cardModules[`../components/compositions/cards/${path}.vue`];
	return importer ? importer() : Promise.resolve();
}
//#endregion
//#region src/engine/CardRenderer.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = ["data-card-id", "data-card-type"];
//#endregion
//#region src/engine/CardRenderer.vue
var CardRenderer_default = /* @__PURE__ */ defineComponent({
	__name: "CardRenderer",
	props: {
		card: {},
		item: { default: () => ({}) },
		elements: { default: () => ({}) },
		cards: { default: () => ({}) },
		evaluationContext: { default: () => ({}) }
	},
	setup(__props) {
		/**
		* Renders a single DisplayCard by dispatching its JSON definition into
		* the matching composition under `components/compositions/cards/`.
		*
		* The renderer is the bridge layer:
		*   - resolves the composition by `card.cardType` via the registry
		*   - evaluates the card's visibility (`shouldRender`)
		*   - applies responsive layout + classList chrome at the wrapper level
		*   - resolves ID-referenced child lists against the page-level
		*     `elements` / `cards` maps:
		*       - `card.elementList: string[]` → pass as `elements: CardElement[]`
		*       - `card.cardList: string[]`    → pass as `cards: DisplayCard[]`
		*       - `card.tabList: string[]`     → pass as `tabs: DisplayCard[]`
		*       - `card.elementId: string`     → pass as `element: CardElement`
		*   - strips schema-only keys (cardType, conditionParams, columns*, ...)
		*     and passes the rest through as Vue props
		*
		* Compositions don't know about the page-level maps or the JSON schema —
		* they receive resolved children + display props and emit normal Vue
		* events. They're directly mountable in any app.
		*/
		const props = __props;
		const visible = computed(() => shouldRender(props.card, props.item, props.evaluationContext));
		const resolved = computed(() => getCardComponent(props.card.cardType));
		/**
		* Keys that live on every DisplayCard and are NOT meant to flow
		* through to the composition as props. These are either consumed by
		* this renderer (`columns*`, `conditionParams`, `cardType`, ...) or
		* resolved into their concrete child arrays below.
		*/
		const STRIPPED_KEYS = new Set([
			"cardType",
			"conditionParams",
			"conditionGroupLogic",
			"condition",
			"features",
			"permissions",
			"columns",
			"columnsSm",
			"columnsMd",
			"columnsLg",
			"columnsXl",
			"columnsXxl",
			"wrapperClassList",
			"columnClassList",
			"order",
			"elementList",
			"cardList",
			"tabList",
			"elementId"
		]);
		/**
		* Compute the props object to pass to the resolved composition.
		*
		* - Strips schema-only keys (`cardType`, `conditionParams`, ...).
		* - Resolves `elementList` / `cardList` / `tabList` / `elementId` against
		*   the page-level registries and exposes them as concrete arrays /
		*   objects under composition-facing prop names.
		* - Forwards `item` as-is for child renderers to use.
		*/
		const compositionProps = computed(() => {
			const c = props.card;
			const result = {};
			for (const [key, value] of Object.entries(c)) if (!STRIPPED_KEYS.has(key)) result[key] = value;
			result.item = props.item;
			if (Array.isArray(c.elementList)) {
				const ids = c.elementList;
				const out = [];
				for (const id of ids) {
					const el = props.elements[id];
					if (el) out.push(el);
				}
				result.elements = out;
			}
			if (Array.isArray(c.cardList)) {
				const ids = c.cardList;
				const out = [];
				for (const id of ids) {
					const child = props.cards[id];
					if (child) out.push(child);
				}
				result.cards = out;
			}
			if (Array.isArray(c.tabList)) {
				const ids = c.tabList;
				const out = [];
				for (const id of ids) {
					const child = props.cards[id];
					if (child) out.push(child);
				}
				result.tabs = out;
			}
			if (props.card.cardType === "grid-view" && typeof c.gridLayout === "object" && c.gridLayout !== null) {
				const layout = c.gridLayout;
				const elementIds = /* @__PURE__ */ new Set();
				for (const breakpoint of Object.values(layout)) if (Array.isArray(breakpoint)) {
					for (const item of breakpoint) if (item && typeof item === "object" && "i" in item) {
						const id = item.i;
						if (typeof id === "string" && props.elements[id]) elementIds.add(id);
					}
				}
				if (elementIds.size > 0) result.gridElements = Array.from(elementIds).map((id) => props.elements[id]).filter(Boolean);
			}
			const elementId = c.elementId;
			if (typeof elementId === "string" && elementId.length > 0) {
				const el = props.elements[elementId];
				if (el) result.element = el;
			}
			return result;
		});
		const wrapperClass = computed(() => cn("gxp-card", `gxp-card--${props.card.cardType}`, columnClass("col", props.card.columns), columnClass("col-sm", props.card.columnsSm), columnClass("col-md", props.card.columnsMd), columnClass("col-lg", props.card.columnsLg), columnClass("col-xl", props.card.columnsXl), normalizeClasses(props.card.wrapperClassList)));
		function columnClass(prefix, n) {
			if (typeof n !== "number") return;
			const pct = Math.max(0, Math.min(12, n)) / 12;
			return prefix === "col" ? `basis-[${(pct * 100).toFixed(4)}%]` : `${prefix}:basis-[${(pct * 100).toFixed(4)}%]`;
		}
		function normalizeClasses(value) {
			if (!value) return "";
			return Array.isArray(value) ? value.join(" ") : value;
		}
		return (_ctx, _cache) => {
			return visible.value ? (openBlock(), createElementBlock("div", {
				key: 0,
				class: normalizeClass(wrapperClass.value),
				"data-card-id": __props.card.id,
				"data-card-type": __props.card.cardType
			}, [(openBlock(), createBlock(resolveDynamicComponent(resolved.value), normalizeProps(guardReactiveProps(compositionProps.value)), null, 16))], 10, _hoisted_1)) : createCommentVNode("", true);
		};
	}
});
//#endregion
export { getCardComponent as n, preloadCard as r, CardRenderer_default as t };

//# sourceMappingURL=CardRenderer-BVyy_sI2.js.map