import {
  PageRenderer,
  buildRichTextSchema,
  buildThemeRuntime,
  renderBlock
} from "./chunk-NKXS4TBK.mjs";
import {
  siteFooterManifest,
  siteHeaderManifest
} from "./chunk-USQF2XTU.mjs";
import {
  __require
} from "./chunk-BJTO5JO5.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,
  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
      },
      routeMap,
      wrapBlock,
      registry,
      blockOverrides,
      sdkConfig
    }
  );
}

// ../block-form/dist/server/index.mjs
import { z as z18 } from "zod";
import { z } from "zod";
import { z as z2 } from "zod";
import { z as z3 } from "zod";
import { z as z4 } from "zod";
import { z as z5 } from "zod";
import { z as z6 } from "zod";
import { z as z7 } from "zod";
import { z as z8 } from "zod";
import { z as z9 } from "zod";
import { z as z10 } from "zod";
import { z as z11 } from "zod";
import { z as z12 } from "zod";
import { z as z13 } from "zod";
import { z as z14 } from "zod";
import { z as z15 } from "zod";
import { z as z16 } from "zod";
import { z as z17 } from "zod";
var __require2 = /* @__PURE__ */ ((x) => typeof __require !== "undefined" ? __require : typeof Proxy !== "undefined" ? new Proxy(x, {
  get: (a, b) => (typeof __require !== "undefined" ? __require : a)[b]
}) : x)(function(x) {
  if (typeof __require !== "undefined") return __require.apply(this, arguments);
  throw Error('Dynamic require of "' + x + '" is not supported');
});
function buildTextFieldSchema(field) {
  const ui = field?.ui ?? {};
  const inputType = ui?.inputType;
  if (inputType === "email") {
    let s2 = z.string().email("Enter a valid email");
    if (typeof field.maxLength === "number") {
      s2 = s2.max(field.maxLength);
    }
    if (field.required) {
      return s2.min(1, "This field is required");
    }
    return s2.optional().nullable().or(z.literal(""));
  }
  if (inputType === "tel") {
    let s2 = z.string().regex(/^[+()0-9\s\-]{3,}$/, "Enter a valid phone number");
    if (typeof field.maxLength === "number") {
      s2 = s2.max(field.maxLength);
    }
    if (field.required) {
      return s2.min(1, "This field is required");
    }
    return s2.optional().nullable().or(z.literal(""));
  }
  let s = z.string();
  if (typeof field.maxLength === "number") {
    s = s.max(field.maxLength);
  }
  if (ui?.pattern) {
    try {
      const re = new RegExp(ui.pattern);
      s = s.regex(re);
    } catch {
    }
  }
  if (field.required) {
    return s.min(1, "This field is required");
  }
  return s.optional().nullable().or(z.literal(""));
}
function getTextFieldDefault(field) {
  if (field.defaultValue !== void 0 && field.defaultValue !== null) {
    return String(field.defaultValue);
  }
  if (field.required) {
    return field.label;
  }
  return "";
}
function buildNumberFieldSchema(field) {
  const ui = field?.ui ?? {};
  let s = z2.coerce.number();
  if (typeof ui?.min === "number") {
    s = s.min(ui.min);
  }
  if (typeof ui?.max === "number") {
    s = s.max(ui.max);
  }
  if (!field.required) {
    s = s.optional().nullable();
  }
  return s;
}
function getNumberFieldDefault(field) {
  if (field.defaultValue !== void 0) {
    return typeof field.defaultValue === "number" ? field.defaultValue : null;
  }
  return null;
}
function buildSelectFieldSchema(field) {
  const validValues = field.options?.map((opt) => opt.value) ?? [];
  if (validValues.length === 0) {
    return field.required ? z3.string().min(1) : z3.string().optional();
  }
  let schema = z3.enum(validValues);
  if (!field.required) {
    schema = schema.optional();
  }
  return schema;
}
function getSelectFieldDefault(field) {
  if (field.defaultValue !== void 0 && field.defaultValue !== null) {
    return String(field.defaultValue);
  }
  return field.options?.[0]?.value ?? "";
}
function buildBooleanFieldSchema(field) {
  return z4.boolean();
}
function getBooleanFieldDefault(field) {
  if (field.defaultValue !== void 0) {
    return Boolean(field.defaultValue);
  }
  return false;
}
function buildGroupFieldSchema(field, ctx) {
  const shape = {};
  for (const child of field.fields) {
    shape[child.id] = ctx.getFieldSchema(child);
  }
  return z5.object(shape).catchall(z5.unknown()).passthrough();
}
function getGroupFieldDefault(field, ctx) {
  const obj = {};
  for (const child of field.fields) {
    obj[child.id] = ctx.resolve(child);
  }
  return obj;
}
function buildModalFieldSchema(field, ctx) {
  const shape = {};
  const fields = field.schema?.fields ?? field.fields ?? [];
  for (const child of fields) {
    shape[child.id] = ctx.getFieldSchema(child);
  }
  return z6.object(shape).catchall(z6.unknown()).passthrough();
}
function getModalFieldDefault(field, ctx) {
  const obj = {};
  const fields = field.schema?.fields ?? field.fields ?? [];
  for (const child of fields) {
    obj[child.id] = ctx.resolve(child);
  }
  return obj;
}
function buildRepeaterFieldSchema(field, ctx) {
  let itemSchema;
  if (field.polymorphic && field.itemTypes) {
    const itemTypeSchemas = [];
    for (const [typeKey, itemType] of Object.entries(field.itemTypes)) {
      const childShape = {
        _type: z7.literal(typeKey)
      };
      for (const childField of itemType.fields) {
        childShape[childField.id] = ctx.getFieldSchema(childField);
      }
      itemTypeSchemas.push(z7.object(childShape).catchall(z7.unknown()).passthrough());
    }
    itemSchema = itemTypeSchemas.length > 1 ? z7.discriminatedUnion("_type", itemTypeSchemas) : itemTypeSchemas[0] ?? z7.object({ _type: z7.string() }).passthrough();
  } else if (!field.polymorphic && field.fields) {
    const childShape = {};
    for (const childField of field.fields) {
      childShape[childField.id] = ctx.getFieldSchema(childField);
    }
    itemSchema = z7.object(childShape).catchall(z7.unknown()).passthrough();
  } else {
    itemSchema = z7.any();
  }
  if (field.validation) {
    const customValidation = field.validation;
    if (field.required) {
      return customValidation;
    }
    return customValidation.optional();
  }
  let schema = z7.array(itemSchema);
  const minItems = field.minItems ?? 0;
  if (minItems > 0) {
    schema = schema.min(minItems, `Must have at least ${minItems} item(s)`);
  }
  if (field.maxItems !== void 0) {
    schema = schema.max(field.maxItems, `Must have at most ${field.maxItems} item(s)`);
  }
  if (field.required) {
    return schema;
  }
  return schema.optional();
}
function getRepeaterFieldDefault(field, ctx) {
  if (field.defaultValue !== void 0) {
    return Array.isArray(field.defaultValue) ? field.defaultValue : [];
  }
  const minItems = field.minItems ?? 0;
  if (minItems > 0) {
    const items = [];
    for (let i = 0; i < minItems; i++) {
      const item = {};
      if (field.polymorphic && field.itemTypes) {
        const firstType = Object.keys(field.itemTypes)[0];
        if (firstType) {
          item._type = firstType;
          const typeSchema = field.itemTypes[firstType];
          if (typeSchema) {
            for (const childField of typeSchema.fields) {
              item[childField.id] = ctx.resolve(childField);
            }
          }
        }
      } else if (field.fields) {
        for (const childField of field.fields) {
          item[childField.id] = ctx.resolve(childField);
        }
      }
      items.push(item);
    }
    return items;
  }
  return [];
}
var ALLOWED_PROTOCOLS = ["http:", "https:"];
function buildUrlFieldSchema(field) {
  const message = `${field.label} must be a valid URL`;
  const validator = (value) => {
    if (!value) {
      return !field.required;
    }
    if (field.allowRelative && value.startsWith("/")) {
      return true;
    }
    try {
      const parsed = new URL(value);
      return ALLOWED_PROTOCOLS.includes(parsed.protocol);
    } catch {
      return false;
    }
  };
  const base = z8.string().trim().refine(validator, message);
  if (field.required) {
    return base.min(1, { message: `${field.label} is required` });
  }
  return z8.union([base, z8.literal("")]).optional().nullable();
}
function getUrlFieldDefault(field) {
  return field.defaultValue ?? "";
}
function buildTimeFieldSchema(field) {
  const base = z9.string();
  if (field.required) {
    return base.min(1, { message: `${field.label} is required` });
  }
  return z9.union([base, z9.literal(""), z9.null()]).optional().nullable();
}
function getTimeFieldDefault(field) {
  return field.defaultValue ?? null;
}
function buildDateFieldSchema(field) {
  const base = z10.string();
  if (field.required) {
    return base.min(1, { message: `${field.label} is required` });
  }
  return z10.union([base, z10.literal(""), z10.null()]).optional().nullable();
}
function getDateFieldDefault(field) {
  return field.defaultValue ?? null;
}
function buildDateTimeFieldSchema(field) {
  const base = z11.string().refine(
    (val) => {
      if (!val) return true;
      const date = new Date(val);
      return !isNaN(date.getTime());
    },
    { message: `${field.label} must be a valid date-time` }
  );
  if (field.required) {
    return base.min(1, { message: `${field.label} is required` });
  }
  return z11.union([base, z11.literal(""), z11.null()]).optional().nullable();
}
function getDateTimeFieldDefault(field) {
  return field.defaultValue ?? null;
}
var SLUG_PATTERN = /^(?:[a-z0-9]+(?:-[a-z0-9]+)*)(?:\/(?:[a-z0-9]+(?:-[a-z0-9]+)*))*$/;
function buildSlugFieldSchema(field) {
  const base = z12.string().regex(SLUG_PATTERN, `${field.label} must use lowercase letters, numbers, and dashes`);
  const withLength = field.maxLength ? base.max(field.maxLength, { message: `${field.label} must be at most ${field.maxLength} characters` }) : base;
  if (field.required) {
    return withLength.min(1, { message: `${field.label} is required` });
  }
  return z12.union([withLength, z12.literal("")]).optional().nullable();
}
function getSlugFieldDefault(field) {
  return field.defaultValue ?? "";
}
function buildLinkFieldSchema(field) {
  const nullableString = z13.union([z13.string().min(1), z13.null()]);
  const internal = z13.object({
    kind: z13.literal("internal"),
    routeId: z13.string().min(1),
    entityId: z13.string().min(1).optional(),
    entityType: z13.enum(["page", "content"]).optional(),
    href: nullableString.optional(),
    title: nullableString.optional(),
    typeLabel: nullableString.optional(),
    contentTypeKey: nullableString.optional(),
    contentTypeName: nullableString.optional(),
    updatedAt: nullableString.optional()
  }).passthrough();
  const external = z13.object({
    kind: z13.literal("external"),
    href: z13.string().min(1)
  }).passthrough();
  const custom = z13.object({
    kind: z13.literal("url"),
    href: z13.string().min(1)
  }).passthrough();
  const linkSchema = z13.union([internal, external, custom]);
  if (field.required) {
    return linkSchema;
  }
  return z13.union([linkSchema, z13.null()]).optional();
}
function getLinkFieldDefault(_field) {
  return null;
}
function buildRichTextFieldSchema(config) {
  return buildRichTextSchema({
    required: config.required,
    label: config.label
  });
}
var EMPTY_RICH_TEXT_DOC = {
  type: "doc",
  content: [
    {
      type: "paragraph"
    }
  ]
};
function getRichTextFieldDefaultValue(_config) {
  return EMPTY_RICH_TEXT_DOC;
}
var MediaValueSchema = z14.object({
  kind: z14.enum(["image", "video"]),
  url: z14.string().url(),
  alt: z14.string().optional(),
  caption: z14.string().optional(),
  credit: z14.string().optional(),
  width: z14.number().optional(),
  height: z14.number().optional(),
  size: z14.number().optional(),
  mimeType: z14.string().optional()
});
function buildMediaFieldSchema(config) {
  let schema = MediaValueSchema.nullable();
  if (config.required) {
    schema = schema.refine((val) => val !== null, {
      message: `${config.label} is required`
    });
  }
  return schema;
}
function getMediaFieldDefaultValue(_config) {
  return null;
}
function buildTabGroupFieldSchema(field, ctx) {
  const shape = {};
  for (const tab of field.tabs) {
    for (const child of tab.fields) {
      shape[child.id] = ctx.getFieldSchema(child);
    }
  }
  if (field.activeTabField) {
    const tabIds = field.tabs.map((t) => t.id);
    if (tabIds.length > 0) {
      shape[field.activeTabField] = z15.enum(tabIds);
    }
  }
  return z15.object(shape).catchall(z15.unknown()).passthrough();
}
function getTabGroupFieldDefault(field, ctx) {
  const defaults = {};
  for (const tab of field.tabs) {
    for (const child of tab.fields) {
      defaults[child.id] = ctx.resolve(child);
    }
  }
  if (field.activeTabField && field.tabs.length > 0) {
    defaults[field.activeTabField] = field.tabs[0].id;
  }
  return defaults;
}
function buildPresetOrCustomFieldSchema(field, _ctx) {
  const presetValues = field.presets.map((p) => p.value);
  return z16.string();
}
function getPresetOrCustomFieldDefault(field, _ctx) {
  if (field.defaultValue !== void 0 && field.defaultValue !== null) {
    return String(field.defaultValue);
  }
  return field.presets[0]?.value ?? "";
}
function buildReferenceFieldSchema(field, _ctx) {
  return z17.string();
}
function getReferenceFieldDefault(field, _ctx) {
  if (field.defaultValue !== void 0 && field.defaultValue !== null) {
    return String(field.defaultValue);
  }
  if (field.required) {
    return `placeholder-${field.id}`;
  }
  return "";
}
var SCHEMA_BUILDERS = {
  text: buildTextFieldSchema,
  number: buildNumberFieldSchema,
  select: buildSelectFieldSchema,
  boolean: buildBooleanFieldSchema,
  group: buildGroupFieldSchema,
  modal: buildModalFieldSchema,
  repeater: buildRepeaterFieldSchema,
  url: buildUrlFieldSchema,
  time: buildTimeFieldSchema,
  date: buildDateFieldSchema,
  datetime: buildDateTimeFieldSchema,
  slug: buildSlugFieldSchema,
  link: buildLinkFieldSchema,
  richText: buildRichTextFieldSchema,
  media: buildMediaFieldSchema,
  tabGroup: buildTabGroupFieldSchema,
  presetOrCustom: buildPresetOrCustomFieldSchema,
  reference: buildReferenceFieldSchema
};
var DEFAULT_VALUE_BUILDERS = {
  text: getTextFieldDefault,
  number: getNumberFieldDefault,
  select: getSelectFieldDefault,
  boolean: getBooleanFieldDefault,
  group: getGroupFieldDefault,
  modal: getModalFieldDefault,
  repeater: getRepeaterFieldDefault,
  url: getUrlFieldDefault,
  time: getTimeFieldDefault,
  date: getDateFieldDefault,
  datetime: getDateTimeFieldDefault,
  slug: getSlugFieldDefault,
  link: getLinkFieldDefault,
  richText: getRichTextFieldDefaultValue,
  media: getMediaFieldDefaultValue,
  tabGroup: getTabGroupFieldDefault,
  presetOrCustom: getPresetOrCustomFieldDefault,
  reference: getReferenceFieldDefault
};
function buildFieldSchema(field, ctx) {
  const builder = SCHEMA_BUILDERS[field.type];
  if (!builder) {
    console.warn(`No schema builder registered for field type: ${field.type}`);
    return __require2("zod").z.any();
  }
  return builder(field, ctx);
}
function getFieldDefault(field, ctx) {
  const getDefault = DEFAULT_VALUE_BUILDERS[field.type];
  if (!getDefault) {
    console.warn(`No default value builder registered for field type: ${field.type}`);
    return field.defaultValue;
  }
  return getDefault(field, ctx);
}
var DEFAULT_ROLE = "author";
var rolePriority = {
  author: 0,
  designer: 1,
  admin: 2
};
function createManifestFormAdapter(manifest, options) {
  const role = options?.role ?? DEFAULT_ROLE;
  const fields = (manifest.fields ?? []).map((field) => transformField(field, role)).filter(Boolean);
  const schema = buildValidationSchema(fields);
  return { fields, schema };
}
function transformField(field, role) {
  if (!isFieldVisible(field, role)) {
    return void 0;
  }
  if (field.type !== "group" && field.type !== "repeater") {
    return field;
  }
  if (field.type === "group") {
    const children = (field.schema?.fields ?? []).map((child) => transformField(child, role)).filter(Boolean);
    if (!children.length) {
      return void 0;
    }
    const { schema: _schema, ...rest } = field;
    return { ...rest, fields: children };
  }
  if (field.type === "repeater") {
    if (field.polymorphic && field.itemTypes) {
      const itemTypes = {};
      for (const [typeKey, itemType] of Object.entries(field.itemTypes)) {
        const children2 = (itemType.fields ?? []).map((child) => transformField(child, role)).filter(Boolean);
        if (children2.length > 0) {
          itemTypes[typeKey] = {
            label: itemType.label,
            icon: itemType.icon,
            fields: children2
          };
        }
      }
      if (Object.keys(itemTypes).length === 0) {
        return void 0;
      }
      const { schema: _schema2, ...rest2 } = field;
      return { ...rest2, itemTypes };
    }
    const children = (field.schema?.fields ?? []).map((child) => transformField(child, role)).filter(Boolean);
    if (!children.length) {
      return void 0;
    }
    const { schema: _schema3, polymorphic: _polymorphic, itemTypes: _itemTypes, ...rest } = field;
    return { ...rest, fields: children };
  }
  return void 0;
}
function isFieldVisible(field, role) {
  if (role === "admin") {
    return true;
  }
  const allowed = field.visibleRoles;
  if (!allowed || allowed.length === 0) {
    return true;
  }
  return allowed.some((visibility) => rolePriority[role] >= rolePriority[visibility]);
}
function buildValidationSchema(fields) {
  const shape = {};
  const ctx = {
    getFieldSchema: (field) => buildFieldSchema(field, ctx)
  };
  for (const field of fields) {
    shape[field.id] = buildFieldSchema(field, ctx);
  }
  return z18.object(shape).catchall(z18.unknown()).passthrough();
}
function createManifestDefaultValues(manifest, data = {}, options = {}) {
  const { fields } = createManifestFormAdapter(manifest, {
    role: options.role,
    ...options.adapterOptions
  });
  const ctx = {
    resolve: (field) => getFieldDefault(field, ctx)
  };
  const result = {};
  for (const field of fields) {
    const rawValue = data[field.id];
    result[field.id] = ensureFieldValue(field, rawValue, ctx);
  }
  return result;
}
function ensureFieldValue(field, rawValue, ctx) {
  if (field.type === "repeater") {
    if (rawValue === void 0) {
      rawValue = getFieldDefault(field, ctx);
    }
    const items = Array.isArray(rawValue) ? rawValue : [];
    return items.map((item) => ensureRepeaterItem(field, item, ctx));
  }
  if (rawValue === void 0) {
    return getFieldDefault(field, ctx);
  }
  return rawValue;
}
function ensureRepeaterItem(field, value, ctx) {
  const itemData = typeof value === "object" && value !== null ? { ...value } : {};
  if (field.polymorphic && field.itemTypes) {
    const itemType = typeof itemData._type === "string" ? itemData._type : Object.keys(field.itemTypes)[0];
    const typeSchema = field.itemTypes[itemType];
    if (!typeSchema) return itemData;
    for (const child of typeSchema.fields) {
      if (child.type === "group" && child?.ui?.flattenInRepeater) {
        const group = child;
        for (const gc of group.fields) {
          itemData[gc.id] = ensureFieldValue(gc, itemData[gc.id], ctx);
        }
      } else {
        itemData[child.id] = ensureFieldValue(child, itemData[child.id], ctx);
      }
    }
    return itemData;
  }
  if (!field.polymorphic && field.fields) {
    for (const child of field.fields) {
      if (child.type === "group" && child?.ui?.flattenInRepeater) {
        const group = child;
        for (const gc of group.fields) {
          itemData[gc.id] = ensureFieldValue(gc, itemData[gc.id], ctx);
        }
      } else {
        itemData[child.id] = ensureFieldValue(child, itemData[child.id], ctx);
      }
    }
  }
  return itemData;
}

// ../site-renderer/dist/index.mjs
function selectPrimaryMenu(menus) {
  if (!menus.length) {
    return null;
  }
  const primary = menus.find((menu) => menu.isPrimary);
  return primary ?? menus[0] ?? null;
}
function buildMenuViewModel(menu) {
  if (!menu) {
    return { items: [], ctaItem: null };
  }
  const flatItems = menu.items.filter((item) => item.parentId === null && item.urlType !== "dropdown").sort((a, b) => a.orderIndex - b.orderIndex);
  const items = [];
  let ctaItem = null;
  for (const item of flatItems) {
    const viewItem = {
      id: item.id,
      label: item.label,
      link: convertNavigationLink(item),
      target: null,
      rel: null,
      active: false
      // TODO: Compute active state based on current route
    };
    if (!ctaItem && Boolean(item.isCta)) {
      ctaItem = { ...viewItem, variant: "primary" };
      continue;
    }
    items.push(viewItem);
  }
  return { items, ctaItem };
}
function buildLogoViewModel(logo, fallbackTitle) {
  if (!logo) {
    return null;
  }
  if (!logo.url && !logo.assetId) {
    return null;
  }
  const alt = logo.alt && logo.alt.trim().length > 0 ? logo.alt : fallbackTitle ?? "Site logo";
  const viewModel = {
    type: "image",
    src: logo.url ?? "",
    // Empty string when url is null - media node uses assetId instead
    alt,
    assetId: logo.assetId ?? void 0,
    width: logo.width ?? void 0,
    height: logo.height ?? void 0
  };
  return viewModel;
}
function convertNavigationLink(item) {
  const payload = item.url ?? null;
  if (!payload) return null;
  const kind = typeof payload.kind === "string" ? payload.kind : null;
  if (kind === "external" || kind === "url") {
    const href = typeof payload.href === "string" ? payload.href : null;
    return href ? { kind, href } : null;
  }
  if (kind === "internal") {
    const routeId = typeof payload.routeId === "string" ? payload.routeId : null;
    const entityId = typeof payload.entityId === "string" ? payload.entityId : null;
    const entityType = typeof payload.entityType === "string" && (payload.entityType === "page" || payload.entityType === "content") ? payload.entityType : null;
    const href = typeof payload.href === "string" ? payload.href : null;
    const title = typeof payload.title === "string" ? payload.title : null;
    const typeLabel = typeof payload.typeLabel === "string" ? payload.typeLabel : null;
    if (!routeId || !entityId || !entityType || !href || !title || !typeLabel) {
      return null;
    }
    return {
      kind: "internal",
      routeId,
      entityId,
      entityType,
      href,
      title,
      typeLabel,
      contentTypeKey: typeof payload.contentTypeKey === "string" ? payload.contentTypeKey : null,
      contentTypeName: typeof payload.contentTypeName === "string" ? payload.contentTypeName : null,
      updatedAt: typeof payload.updatedAt === "string" ? payload.updatedAt : null
    };
  }
  return null;
}
var HEADER_DEFAULTS = createManifestDefaultValues(siteHeaderManifest);
var FOOTER_DEFAULTS = createManifestDefaultValues(siteFooterManifest);

// 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 menu = selectPrimaryMenu(navigation);
  const menuViewModel = buildMenuViewModel(menu);
  const logoViewModel = buildLogoViewModel(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-SFQ7VF3G.mjs.map