import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import _ from 'lodash';
import FormGenerator from "../../../form-generator-v2/FormGenerator.js";
import { MessageCard } from "../../components/MessageCard/index.js";
import { MESSAGES } from "../../constants/messages.js";
import { useMainEditorStore } from "../../hooks/useMainEditorStore.js";
import { generateChildrenPathFromArray } from "../../utils/index.js";
import { editorCn } from "../../utils/cn.js";
import './BlockConfigForm.css';
const b = editorCn('block-config-form');
const BlockConfigForm = ({ className }) => {
    const { selectedBlock, content, blocks, subBlocks, updateField } = useMainEditorStore();
    const currentBlockPath = selectedBlock ? generateChildrenPathFromArray(selectedBlock) : '[]';
    const currentConfig = _.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 (_jsx("div", { className: b({ empty: true }, className), children: _jsx(MessageCard, { title: MESSAGES.NO_BLOCK_SELECTED.title, description: MESSAGES.NO_BLOCK_SELECTED.description, theme: "info" }) }));
    }
    if (!currentSchema) {
        return (_jsx("div", { className: b({ empty: true }, className), children: _jsx(MessageCard, { title: MESSAGES.UNSUPPORTED_BLOCK.title, description: MESSAGES.UNSUPPORTED_BLOCK.description, theme: "warning" }) }));
    }
    return (_jsxs("div", { className: b(null, className), children: [_jsx("div", { className: b('title'), children: currentSchema.schema.name }), _jsx("div", { className: b('form'), children: currentSchema.schema.inputs && (_jsx(FormGenerator, { contentConfig: currentConfig, blockConfig: currentSchema.schema.inputs, onUpdateByKey: onUpdateByKey })) })] }));
};
export default BlockConfigForm;
//# sourceMappingURL=BlockConfigForm.js.map
