import { z } from 'zod';
/**
 * Schema helper for nested component references within a parent component.
 *
 * Produces a Zod schema for a block entry: `{ id, component, props }`.
 * When `allow` is provided, `component` is constrained to an enum of the
 * listed names. This flows into the generated JSON schema, so the content
 * validator enforces the allowlist at build time.
 *
 * @example
 * ```ts
 * defineComponent({
 *   name: 'tabbed_panels',
 *   schema: z.object({
 *     tabs: z.array(z.object({
 *       id: z.string().min(1),
 *       label: z.string().min(1),
 *       blocks: z.array(blockRef({ allow: ['checklist', 'text_media'] })).min(1),
 *     })),
 *   }),
 * })
 * ```
 */
export function blockRef(options) {
    const allow = options?.allow;
    const componentSchema = allow && allow.length > 0
        ? z.enum(allow)
        : z.string().min(1);
    return z.object({
        id: z.string().min(1),
        component: componentSchema,
        props: z.record(z.string(), z.unknown()),
    });
}
