import {randomId} from "../../../helpers.js";

export function insertBlock(blockData, blockField, afterBlockId = null) {

    if (!afterBlockId) {
        return [{
            meta: blockField,
            id: randomId(),
            value: null
        }, ...blockData];
    }

    return blockData.reduce((carry, block) => {
        carry.push(block)
        if (block.id === afterBlockId) {
            carry.push({
                meta: blockField,
                id: randomId(),
                value: null
            });
        }
        return carry;
    }, []);

}