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