import { useShellStore } from "../stores/shellStore.mjs";
import getWidgetLayout from "../dashboard/getWidgetLayout.mjs";
import DashboardCardGrid from "../dashboard/DashboardCardGrid.mjs";
import MemoizedDashboardWidget from "../dashboard/DashboardWidget.mjs";
import StaticPageRenderer from "./StaticPageRenderer.mjs";
import { c } from "react-compiler-runtime";
import React from "react";
//#region src/page/Page.jsx
const Page = (props) => {
	const $ = c(19);
	const { gridConfig, widgetConfig, disableMargin, autoHeight, pageTypeId } = props;
	const { getWidget } = useShellStore();
	let t0;
	if ($[0] !== gridConfig) {
		t0 = gridConfig ? JSON.parse(gridConfig) : null;
		$[0] = gridConfig;
		$[1] = t0;
	} else t0 = $[1];
	const gridProperties = t0;
	let widgets;
	if ($[2] !== widgetConfig) {
		widgets = widgetConfig || null;
		if (typeof widgetConfig === "string") widgets = JSON.parse(widgetConfig);
		$[2] = widgetConfig;
		$[3] = widgets;
	} else widgets = $[3];
	let t1;
	if ($[4] !== getWidget || $[5] !== widgets) {
		t1 = () => {
			if (!widgets) return null;
			const normalizeNumber = _temp;
			const layouts = {};
			for (const widget of widgets) {
				if (!widget?.layout) continue;
				for (const breakpoint in widget.layout) {
					if (breakpoint === "__typename" || !widget.layout[breakpoint]) continue;
					layouts[breakpoint] = layouts[breakpoint] || [];
					const { __typename, ...layout } = widget.layout[breakpoint];
					const defaultLayout = getWidgetLayout(getWidget, widget.widgetType);
					const mergedLayout = {
						...defaultLayout,
						...layout,
						i: widget.id
					};
					mergedLayout.x = normalizeNumber(mergedLayout.x, 0);
					mergedLayout.y = normalizeNumber(mergedLayout.y, 0);
					mergedLayout.w = normalizeNumber(mergedLayout.w, defaultLayout?.w ?? 2);
					mergedLayout.h = normalizeNumber(mergedLayout.h, defaultLayout?.h ?? 2);
					const paramResizable = widget?.params?.isResizable;
					mergedLayout.isResizable = typeof paramResizable === "boolean" ? paramResizable : Boolean(mergedLayout.isResizable);
					layouts[breakpoint].push(mergedLayout);
				}
			}
			return layouts;
		};
		$[4] = getWidget;
		$[5] = widgets;
		$[6] = t1;
	} else t1 = $[6];
	const calculateLayouts = t1;
	let t2;
	if ($[7] !== calculateLayouts) {
		t2 = calculateLayouts();
		$[7] = calculateLayouts;
		$[8] = t2;
	} else t2 = $[8];
	const layouts_0 = t2;
	let t3;
	if ($[9] !== widgets) {
		t3 = widgets && widgets.map(_temp2);
		$[9] = widgets;
		$[10] = t3;
	} else t3 = $[10];
	const cards = t3;
	if (!layouts_0) return null;
	if (Number(pageTypeId) === 1) {
		let t4;
		if ($[11] !== cards) {
			t4 = /* @__PURE__ */ React.createElement(StaticPageRenderer, null, cards);
			$[11] = cards;
			$[12] = t4;
		} else t4 = $[12];
		return t4;
	}
	let t4;
	if ($[13] !== autoHeight || $[14] !== cards || $[15] !== disableMargin || $[16] !== gridProperties || $[17] !== layouts_0) {
		t4 = /* @__PURE__ */ React.createElement(DashboardCardGrid, {
			layouts: layouts_0,
			gridProperties,
			disableMargin,
			autoHeight
		}, cards);
		$[13] = autoHeight;
		$[14] = cards;
		$[15] = disableMargin;
		$[16] = gridProperties;
		$[17] = layouts_0;
		$[18] = t4;
	} else t4 = $[18];
	return t4;
};
function _temp(value, fallback) {
	if (typeof value === "number" && Number.isFinite(value)) return value;
	if (typeof value === "string") {
		const parsed = Number(value);
		if (Number.isFinite(parsed)) return parsed;
	}
	return fallback;
}
function _temp2(t0) {
	const { __typename: __typename_0, ...widget_0 } = t0;
	return /* @__PURE__ */ React.createElement(MemoizedDashboardWidget, {
		key: widget_0.id,
		...widget_0
	});
}
//#endregion
export { Page as default };

//# sourceMappingURL=Page.mjs.map