"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const lodash_1 = tslib_1.__importDefault(require("lodash"));
const FormGenerator_1 = tslib_1.__importDefault(require("../../../form-generator-v2/FormGenerator.js"));
const MessageCard_1 = require("../../components/MessageCard/index.js");
const messages_1 = require("../../constants/messages.js");
const useMainEditorStore_1 = require("../../hooks/useMainEditorStore.js");
const utils_1 = require("../../utils/index.js");
const cn_1 = require("../../utils/cn.js");
const b = (0, cn_1.editorCn)('block-config-form');
const BlockConfigForm = ({ className }) => {
    const { selectedBlock, content, blocks, subBlocks, updateField } = (0, useMainEditorStore_1.useMainEditorStore)();
    const currentBlockPath = selectedBlock ? (0, utils_1.generateChildrenPathFromArray)(selectedBlock) : '[]';
    const currentConfig = lodash_1.default.get(content.blocks, currentBlockPath || '');
    const currentSchema = [...blocks, ...subBlocks].find(({ type }) => type === currentConfig?.type);
    const onUpdateByKey = (key, value) => {
        updateField('blocks' + currentBlockPath + '.' + key, value);
    };
    if (!currentConfig) {
        return ((0, jsx_runtime_1.jsx)("div", { className: b({ empty: true }, className), children: (0, jsx_runtime_1.jsx)(MessageCard_1.MessageCard, { title: messages_1.MESSAGES.NO_BLOCK_SELECTED.title, description: messages_1.MESSAGES.NO_BLOCK_SELECTED.description, theme: "info" }) }));
    }
    if (!currentSchema) {
        return ((0, jsx_runtime_1.jsx)("div", { className: b({ empty: true }, className), children: (0, jsx_runtime_1.jsx)(MessageCard_1.MessageCard, { title: messages_1.MESSAGES.UNSUPPORTED_BLOCK.title, description: messages_1.MESSAGES.UNSUPPORTED_BLOCK.description, theme: "warning" }) }));
    }
    return ((0, jsx_runtime_1.jsxs)("div", { className: b(null, className), children: [(0, jsx_runtime_1.jsx)("div", { className: b('title'), children: currentSchema.schema.name }), (0, jsx_runtime_1.jsx)("div", { className: b('form'), children: currentSchema.schema.inputs && ((0, jsx_runtime_1.jsx)(FormGenerator_1.default, { contentConfig: currentConfig, blockConfig: currentSchema.schema.inputs, onUpdateByKey: onUpdateByKey })) })] }));
};
exports.default = BlockConfigForm;
//# sourceMappingURL=BlockConfigForm.js.map
