import { B as BlockKind } from './blockKinds-B6MWzNWp.js';

/**
 * Data loading types for block prefetching.
 * Shared between frontend and SDK implementations.
 */

/**
 * Context for prefetching block data
 */
type PrefetchContext = {
    siteId?: string;
    pageId?: string;
    previewStage?: 'published' | 'preview';
};
/**
 * Resolved block data keyed by block ID and loader key
 *
 * Example:
 * {
 *   'block-123': {
 *     'posts': [...],
 *     'categories': [...]
 *   }
 * }
 */
type ResolvedBlockData = Record<string, Record<string, unknown>>;

/**
 * Code-based data loader types for SDK custom blocks.
 *
 * These types enable SDK sites to define loader functions that fetch
 * data from external APIs (not just CMS endpoints).
 */

/**
 * Context provided to code-based data loaders.
 *
 * Contains block metadata and page context for making informed
 * data fetching decisions.
 */
interface DataLoaderContext {
    /** Site ID from page context */
    siteId: string;
    /** Page ID from page context */
    pageId: string;
    /** Unique block instance ID */
    blockId: string;
    /** Block kind (e.g., 'custom.featured-products') */
    blockKind: BlockKind;
    /**
     * The block's CMS content.
     * Use this to access field values for parameterizing API calls.
     */
    content: Record<string, unknown>;
    /** Whether fetching preview/draft content */
    previewStage: 'published' | 'preview';
}
/**
 * A code-based data loader function.
 *
 * Receives context about the block and returns fetched data.
 * Runs server-side during `loadPage()`.
 *
 * @example
 * ```typescript
 * const productsLoader: DataLoaderFn = async (ctx) => {
 *   const categoryId = ctx.content.categoryId;
 *   const response = await fetch(`https://api.shop.com/products?category=${categoryId}`);
 *   return response.json();
 * };
 * ```
 */
type DataLoaderFn = (context: DataLoaderContext) => Promise<unknown>;
/**
 * Map of loader key to loader function for a block kind.
 *
 * Keys become the property names in the `data` prop passed to the component.
 */
type BlockLoaderMap = Record<string, DataLoaderFn>;
/**
 * Registry of code-based data loaders.
 *
 * Keys are block kinds (e.g., 'custom.featured-products').
 * Values are maps of loader keys to loader functions.
 *
 * @example
 * ```typescript
 * const dataLoaderOverrides: DataLoaderOverrides = {
 *   'custom.featured-products': {
 *     products: async (ctx) => {
 *       return fetchProducts(ctx.content.categoryId);
 *     },
 *   },
 *   'custom.instagram-feed': {
 *     posts: async (ctx) => {
 *       return fetchInstagramPosts(ctx.content.accessToken);
 *     },
 *   },
 * };
 * ```
 */
type DataLoaderOverrides = Record<string, BlockLoaderMap>;

export type { BlockLoaderMap as B, DataLoaderOverrides as D, PrefetchContext as P, ResolvedBlockData as R, DataLoaderContext as a, DataLoaderFn as b };
