import {
  buildSimpleLogo,
  buildSimpleMenu
} from "./chunk-PMHLZ3FW.mjs";
import {
  PageRenderer,
  buildThemeRuntime,
  renderBlock
} from "./chunk-LNOUXALA.mjs";
import {
  siteFooterManifest,
  siteHeaderManifest
} from "./chunk-BYBJA6SP.mjs";

// src/rendering/components/Page.tsx
import { jsx } from "react/jsx-runtime";
function Page({
  page,
  theme,
  themeTokens: providedTokens,
  siteId,
  resolvedData,
  routeMap,
  wrapBlock,
  registry,
  usePlaceholders = false,
  blockOverrides,
  sdkConfig,
  supabaseUrl,
  dataContext
}) {
  const baseTokens = providedTokens ?? buildThemeRuntime(theme).tokens;
  const themeTokens = sdkConfig?.theme?.palette ? { ...baseTokens, palette: { ...baseTokens.palette, ...sdkConfig.theme.palette } } : baseTokens;
  return /* @__PURE__ */ jsx(
    PageRenderer,
    {
      theme,
      page,
      themeTokens,
      usePlaceholders,
      dataContext: {
        siteId,
        resolvedData,
        routes: routeMap,
        occurrenceContext: dataContext?.occurrenceContext ?? null,
        contentEntry: dataContext?.contentEntry ?? null,
        supabaseUrl
      },
      routeMap,
      wrapBlock,
      registry,
      blockOverrides,
      sdkConfig
    }
  );
}

// src/rendering/components/Layout.tsx
import { Fragment, jsxs } from "react/jsx-runtime";
async function Layout({
  siteData: providedSiteData,
  client,
  siteId,
  slug,
  domain,
  children,
  header = true,
  footer = true,
  headerVariant
}) {
  let siteData = providedSiteData;
  if (!siteData) {
    if (!client) {
      throw new Error("Layout: must provide either siteData or client");
    }
    if (!siteId && !slug && !domain) {
      throw new Error("Layout: must provide siteId, slug, or domain when using client");
    }
    siteData = await client.getSite({ id: siteId, slug, domain });
  }
  const { site, theme, navigation, layout, routes } = siteData;
  const themeRuntime = buildThemeRuntime(theme);
  const menuViewModel = buildSimpleMenu(navigation, routes);
  const logoViewModel = buildSimpleLogo(layout.logo ?? null, site.title);
  const headerData = {
    menu: menuViewModel,
    logo: logoViewModel,
    site,
    theme,
    routes
  };
  const headerContent = headerVariant ? { ...layout.header, variant: headerVariant } : layout.header;
  const themeWithVariant = headerVariant ? {
    ...theme,
    header: { ...theme.header, variant: headerVariant }
  } : theme;
  const viewModelOverrides = {
    $root: {
      siteId: site.id,
      routes,
      theme: themeWithVariant
    },
    site,
    menu: menuViewModel,
    content: {
      logo: logoViewModel
    }
  };
  let headerElement = null;
  if (header === true) {
    headerElement = renderBlock(siteHeaderManifest, headerContent, {
      theme: themeRuntime.tokens,
      themeConfig: themeWithVariant,
      viewModelOverrides
    });
  } else if (typeof header === "function") {
    headerElement = header(headerData);
  }
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    headerElement,
    children,
    footer && renderBlock(siteFooterManifest, layout.footer, {
      theme: themeRuntime.tokens,
      themeConfig: theme,
      viewModelOverrides
    })
  ] });
}

export {
  Page,
  Layout
};
//# sourceMappingURL=chunk-2HXHFSMI.mjs.map