"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }


var _chunkSSS7CCRRjs = require('./chunk-SSS7CCRR.js');




var _chunk7UPVCT3Kjs = require('./chunk-7UPVCT3K.js');



var _chunkYYO3RIFOjs = require('./chunk-YYO3RIFO.js');

// src/rendering/components/Page.tsx
var _jsxruntime = require('react/jsx-runtime');
function Page({
  page,
  theme,
  themeTokens: providedTokens,
  siteId,
  resolvedData,
  routeMap,
  wrapBlock,
  registry,
  usePlaceholders = false,
  blockOverrides,
  sdkConfig,
  supabaseUrl,
  dataContext
}) {
  const baseTokens = _nullishCoalesce(providedTokens, () => ( _chunk7UPVCT3Kjs.buildThemeRuntime.call(void 0, theme).tokens));
  const themeTokens = _optionalChain([sdkConfig, 'optionalAccess', _ => _.theme, 'optionalAccess', _2 => _2.palette]) ? { ...baseTokens, palette: { ...baseTokens.palette, ...sdkConfig.theme.palette } } : baseTokens;
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
    _chunk7UPVCT3Kjs.PageRenderer,
    {
      theme,
      page,
      themeTokens,
      usePlaceholders,
      dataContext: {
        siteId,
        resolvedData,
        routes: routeMap,
        occurrenceContext: _nullishCoalesce(_optionalChain([dataContext, 'optionalAccess', _3 => _3.occurrenceContext]), () => ( null)),
        contentEntry: _nullishCoalesce(_optionalChain([dataContext, 'optionalAccess', _4 => _4.contentEntry]), () => ( null)),
        supabaseUrl
      },
      routeMap,
      wrapBlock,
      registry,
      blockOverrides,
      sdkConfig
    }
  );
}

// src/rendering/components/Layout.tsx

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 = _chunk7UPVCT3Kjs.buildThemeRuntime.call(void 0, theme);
  const menuViewModel = _chunkSSS7CCRRjs.buildSimpleMenu.call(void 0, navigation, routes);
  const logoViewModel = _chunkSSS7CCRRjs.buildSimpleLogo.call(void 0, _nullishCoalesce(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 = _chunk7UPVCT3Kjs.renderBlock.call(void 0, _chunkYYO3RIFOjs.siteHeaderManifest, headerContent, {
      theme: themeRuntime.tokens,
      themeConfig: themeWithVariant,
      viewModelOverrides
    });
  } else if (typeof header === "function") {
    headerElement = header(headerData);
  }
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
    headerElement,
    children,
    footer && _chunk7UPVCT3Kjs.renderBlock.call(void 0, _chunkYYO3RIFOjs.siteFooterManifest, layout.footer, {
      theme: themeRuntime.tokens,
      themeConfig: theme,
      viewModelOverrides
    })
  ] });
}




exports.Page = Page; exports.Layout = Layout;
//# sourceMappingURL=chunk-PHS2KWJX.js.map