"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sanitizeProjectionForChildrenCapability = sanitizeProjectionForChildrenCapability;
const blocksBridge_1 = require("./blocksBridge.js");
const common_1 = require("./common.js");
function parentRowSupportsChildren(flat, parentId) {
    if (parentId === null) {
        return true;
    }
    const row = flat.find((x) => String(x.id) === String(parentId));
    return Boolean(row && (0, blocksBridge_1.blockHasChildrenProp)(row.block));
}
// Не даём сделать элемент дочерним у блока без пропа `children`
// рекурсивно уменьшаем глубину, пока не найдём допустимого родителя.
function sanitizeProjectionForChildrenCapability(flat, targetId, projectedDepth) {
    const { depth, parentId } = (0, common_1.getProjection)(flat, targetId, projectedDepth);
    if (parentRowSupportsChildren(flat, parentId)) {
        return { depth, parentId };
    }
    if (projectedDepth <= 0) {
        return (0, common_1.getProjection)(flat, targetId, 0);
    }
    return sanitizeProjectionForChildrenCapability(flat, targetId, projectedDepth - 1);
}
//# sourceMappingURL=treeDragGuards.js.map
