import {
  buildThemeRuntime,
  getDefaultComponentRegistry,
  makeDefaultBlockComponent
} from "./chunk-NKXS4TBK.mjs";
import {
  prefetchBlockData
} from "./chunk-7DS4Q3GA.mjs";
import {
  getBlockDefinition
} from "./chunk-USQF2XTU.mjs";

// src/rendering/components/Block.tsx
import { jsx, jsxs } from "react/jsx-runtime";
async function Block({
  blockKind,
  blockId,
  content,
  theme,
  siteId,
  pageId,
  previewStage,
  client,
  usePlaceholders: _usePlaceholders = false,
  override: OverrideComponent
}) {
  const definition = getBlockDefinition(blockKind);
  if (!definition && !OverrideComponent) {
    return /* @__PURE__ */ jsx("div", { className: "p-4 border border-red-300 bg-red-50 rounded", children: /* @__PURE__ */ jsxs("p", { className: "text-red-800 font-semibold", children: [
      "Unknown block type: ",
      blockKind
    ] }) });
  }
  const themeRuntime = buildThemeRuntime(theme);
  let resolvedData;
  if (client && blockId && definition) {
    const pageOutline = {
      name: "Single Block",
      path: "/block",
      purpose: "Block preview",
      blocks: [{
        id: blockId,
        kind: blockKind,
        purpose: "preview"
      }]
    };
    const allResolvedData = await prefetchBlockData(
      pageOutline,
      { siteId, pageId, previewStage },
      client
    );
    resolvedData = allResolvedData[blockId];
  }
  if (OverrideComponent) {
    return /* @__PURE__ */ jsx(
      OverrideComponent,
      {
        content,
        theme: themeRuntime.tokens,
        themeConfig: theme,
        data: resolvedData,
        blockId: blockId ?? null,
        blockKind
      }
    );
  }
  if (!definition) {
    return /* @__PURE__ */ jsx("div", { className: "p-4 border border-red-300 bg-red-50 rounded", children: /* @__PURE__ */ jsxs("p", { className: "text-red-800 font-semibold", children: [
      "Unknown block type: ",
      blockKind
    ] }) });
  }
  const BlockComponent = makeDefaultBlockComponent({ manifest: definition.manifest });
  const registry = getDefaultComponentRegistry();
  return /* @__PURE__ */ jsx(
    BlockComponent,
    {
      blockId: blockId ?? void 0,
      blockKind,
      theme: themeRuntime.tokens,
      themeConfig: theme,
      content,
      data: resolvedData,
      registry
    }
  );
}

export {
  Block
};
//# sourceMappingURL=chunk-XK2YIISA.mjs.map