"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/data/executeCodeLoaders.ts
async function executeCodeLoaders(page, context, overrides) {
  const results = {};
  const tasks = [];
  for (const block of page.blocks) {
    const blockId = block.id;
    if (!blockId) continue;
    const blockLoaders = overrides[block.kind];
    if (!blockLoaders) continue;
    const content = _nullishCoalesce(_nullishCoalesce(block.draftContent, () => ( block.content)), () => ( {}));
    for (const [key, loaderFn] of Object.entries(blockLoaders)) {
      tasks.push(
        (async () => {
          try {
            const loaderContext = {
              siteId: _nullishCoalesce(context.siteId, () => ( "")),
              pageId: _nullishCoalesce(context.pageId, () => ( "")),
              blockId,
              blockKind: block.kind,
              content,
              previewStage: _nullishCoalesce(context.previewStage, () => ( "published"))
            };
            const data = await loaderFn(loaderContext);
            if (!results[blockId]) {
              results[blockId] = {};
            }
            results[blockId][key] = data;
          } catch (error) {
            console.warn("[executeCodeLoaders] Loader failed:", {
              blockKind: block.kind,
              loaderKey: key,
              error
            });
          }
        })()
      );
    }
  }
  await Promise.all(tasks);
  return results;
}
function mergeLoaderResults(configResults, codeResults) {
  const merged = { ...configResults };
  for (const [blockId, loaderData] of Object.entries(codeResults)) {
    if (!merged[blockId]) {
      merged[blockId] = {};
    }
    merged[blockId] = { ...merged[blockId], ...loaderData };
  }
  return merged;
}




exports.executeCodeLoaders = executeCodeLoaders; exports.mergeLoaderResults = mergeLoaderResults;
//# sourceMappingURL=chunk-G4CKM4EN.js.map