"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const lodash_1 = tslib_1.__importDefault(require("lodash"));
const blockIdContext_1 = require("../../../context/blockIdContext/index.js");
const editor_v2_1 = require("../../../editor-v2/index.js");
const usePCEditorBlockRegister_1 = require("../../../hooks/usePCEditorBlockRegister.js");
const usePCEditorStore_1 = require("../../../hooks/usePCEditorStore.js");
const utils_1 = require("../../../utils/index.js");
const b = (0, utils_1.block)('childrens-wrap');
const ChildrensWrap = ({ children }) => {
    const { manipulateOverlayMode, content } = (0, usePCEditorStore_1.usePCEditorStore)();
    const parentBlockId = React.useContext(blockIdContext_1.BlockIdContext);
    const newBlockIndex = React.useMemo(() => {
        const contentConfig = lodash_1.default.get(content.blocks, (0, editor_v2_1.generateChildrenPathFromArray)(parentBlockId));
        return contentConfig?.children?.length ?? 0;
    }, [content.blocks, parentBlockId]);
    const path = React.useMemo(() => [...parentBlockId, newBlockIndex], [parentBlockId, newBlockIndex]);
    const blockRef = (0, usePCEditorBlockRegister_1.usePCEditorBlockRegister)(path, true);
    if (manipulateOverlayMode === 'insert' && newBlockIndex === 0) {
        return (0, jsx_runtime_1.jsx)("div", { ref: blockRef, className: b({ 'drop-zone': true }) });
    }
    if (manipulateOverlayMode === 'insert') {
        return ((0, jsx_runtime_1.jsx)("div", { ref: blockRef, className: b(), children: children }));
    }
    return children;
};
exports.default = ChildrensWrap;
//# sourceMappingURL=ChildrensWrap.js.map
