"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConstructorItem = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const blockIdContext_1 = require("../../../../context/blockIdContext/index.js");
const innerContext_1 = require("../../../../context/innerContext/index.js");
const usePCEditorBlockRegister_1 = require("../../../../hooks/usePCEditorBlockRegister.js");
const utils_1 = require("../../../../utils/index.js");
const b = (0, utils_1.block)('constructor-item');
const ConstructorItem = ({ data, blockKey, children, }) => {
    const { blocks } = React.useContext(innerContext_1.InnerContext);
    const parentId = React.useContext(blockIdContext_1.BlockIdContext);
    const { type, ...rest } = data;
    const path = React.useMemo(() => [...parentId, blockKey], [parentId, blockKey]);
    const blockRef = (0, usePCEditorBlockRegister_1.usePCEditorBlockRegister)(path);
    const blockData = blocks.find(({ type: blockType }) => blockType === type);
    if (!blockData) {
        return null;
    }
    const Component = blockData.component;
    return ((0, jsx_runtime_1.jsx)(blockIdContext_1.BlockIdContext.Provider, { value: path, children: (0, jsx_runtime_1.jsx)("div", { ref: blockRef, className: b(), children: (0, jsx_runtime_1.jsx)(Component, { ...rest, children: children }) }) }, blockKey));
};
exports.ConstructorItem = ConstructorItem;
//# sourceMappingURL=ConstructorItem.js.map
