export { validators } from "./validators/index.js";
import { blockSchemas, cardSchemas, constructorBlockSchemaNames, constructorCardSchemaNames, } from "./constants.js";
import { AnimatableProps, BackgroundProps, MenuProps, withTheme } from "./validators/common.js";
import { LogoProps, NavigationHeaderProps } from "./validators/navigation.js";
import { filteredItem } from "./validators/utils.js";
export const getBlocksCases = (blocks) => {
    return Object.values(blocks).reduce((acc, block) => ({
        ...acc,
        ...block,
    }), {});
};
export const defaultComponentsConfigurationSchema = {
    type: 'object',
    properties: {
        ...AnimatableProps,
        logo: withTheme(LogoProps),
        header: NavigationHeaderProps,
        menu: MenuProps,
        background: withTheme(BackgroundProps),
    },
};
export function generateDefaultSchema(config) {
    const { cards = {}, blocks = {}, extensions = {} } = config ?? {};
    const configBlockSchemaNames = Object.keys(blocks).filter((item) => !constructorBlockSchemaNames.includes(item));
    const configCardSchemaNames = Object.keys(cards).filter((item) => !constructorCardSchemaNames.includes(item));
    return {
        $id: 'self',
        definitions: {
            children: filteredItem({
                type: 'object',
                required: ['type'],
                properties: {
                    type: {
                        type: 'string',
                        enum: [...constructorBlockSchemaNames, ...configBlockSchemaNames],
                    },
                },
                select: { $data: '0/type' },
                selectCases: {
                    ...blockSchemas,
                    ...getBlocksCases(blocks),
                },
            }),
            cards: filteredItem({
                type: 'object',
                required: ['type'],
                properties: {
                    type: {
                        type: 'string',
                        enum: [...constructorCardSchemaNames, ...configCardSchemaNames],
                    },
                },
                select: { $data: '0/type' },
                selectCases: {
                    ...cardSchemas,
                    ...getBlocksCases(cards),
                },
            }),
        },
        type: 'object',
        additionalProperties: false,
        required: ['blocks'],
        properties: {
            ...defaultComponentsConfigurationSchema.properties,
            blocks: {
                type: 'array',
                items: {
                    $ref: '#/definitions/children',
                },
            },
            ...extensions,
        },
    };
}
//# sourceMappingURL=index.js.map
