import { jsx, jsxs } from "react/jsx-runtime";
import { getBlockComponentSSR, normalizeBlockProps } from "../../../lib/blocks/loader.js";
function BlockError({ blockSlug }) {
  return /* @__PURE__ */ jsx("div", { className: "w-full py-12 px-4 bg-destructive/10 border border-destructive/20 rounded", children: /* @__PURE__ */ jsxs("div", { className: "max-w-7xl mx-auto text-center", children: [
    /* @__PURE__ */ jsxs("p", { className: "text-destructive", children: [
      "Failed to load block: ",
      /* @__PURE__ */ jsx("code", { className: "font-mono", children: blockSlug })
    ] }),
    /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground mt-2", children: "This block may not be available or there was an error rendering it." })
  ] }) });
}
function BlockRenderer({ block }) {
  const BlockComponent = getBlockComponentSSR(block.blockSlug);
  if (!BlockComponent) {
    console.warn(`Block component not found for slug: ${block.blockSlug}`);
    return /* @__PURE__ */ jsx(BlockError, { blockSlug: block.blockSlug });
  }
  const normalizedProps = normalizeBlockProps(block.props);
  return /* @__PURE__ */ jsx(BlockComponent, { ...normalizedProps });
}
function PageRenderer({ page }) {
  const blocks = Array.isArray(page.blocks) ? page.blocks : [];
  if (blocks.length === 0) {
    return /* @__PURE__ */ jsx("div", { className: "min-h-screen flex items-center justify-center bg-muted/10", children: /* @__PURE__ */ jsxs("div", { className: "text-center max-w-md mx-auto px-4", children: [
      /* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold mb-2", children: page.title }),
      /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: "This page does not have any content yet." })
    ] }) });
  }
  return /* @__PURE__ */ jsx("div", { className: "min-h-screen", "data-page-id": page.id, "data-page-slug": page.slug, children: blocks.map((block) => /* @__PURE__ */ jsx(
    "div",
    {
      className: "@container w-full",
      "data-block-id": block.id,
      "data-block-slug": block.blockSlug,
      children: /* @__PURE__ */ jsx(BlockRenderer, { block })
    },
    block.id
  )) });
}
export {
  PageRenderer
};
