import { jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import { BlockIdContext } from "../../../../context/blockIdContext/index.js";
import { InnerContext } from "../../../../context/innerContext/index.js";
import { usePCEditorBlockRegister } from "../../../../hooks/usePCEditorBlockRegister.js";
import { block } from "../../../../utils/index.js";
import './ConstructorItem.css';
const b = block('constructor-item');
export const ConstructorItem = ({ data, blockKey, children, }) => {
    const { blocks } = React.useContext(InnerContext);
    const parentId = React.useContext(BlockIdContext);
    const { type, ...rest } = data;
    const path = React.useMemo(() => [...parentId, blockKey], [parentId, blockKey]);
    const blockRef = usePCEditorBlockRegister(path);
    const blockData = blocks.find(({ type: blockType }) => blockType === type);
    if (!blockData) {
        return null;
    }
    const Component = blockData.component;
    return (_jsx(BlockIdContext.Provider, { value: path, children: _jsx("div", { ref: blockRef, className: b(), children: _jsx(Component, { ...rest, children: children }) }) }, blockKey));
};
//# sourceMappingURL=ConstructorItem.js.map
