"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addColumnAfter = void 0;
const helpers_1 = require("../helpers.js");
const utils_1 = require("../utils.js");
const addColumnAfter = (state, dispatch) => {
    const parentCell = (0, utils_1.findParentTableCell)(state.selection);
    const parentRow = (0, utils_1.findParentTableRow)(state.selection);
    const parentTable = (0, utils_1.findParentTable)(state.selection);
    if (!parentCell || !parentRow || !parentTable) {
        return false;
    }
    const parentCellIndex = (0, helpers_1.findChildIndex)(parentRow.node, parentCell.node);
    if (parentCellIndex < 0) {
        return false;
    }
    if (dispatch) {
        const allRows = (0, utils_1.findChildTableRows)(parentTable.node);
        let tr = state.tr;
        for (const row of allRows) {
            const rowCells = (0, utils_1.findChildTableCells)(row.node);
            const cell = rowCells[parentCellIndex];
            tr = tr.insert(tr.mapping.map(parentTable.pos + row.pos + cell.pos + cell.node.nodeSize + 2), 
            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
            cell.node.type.createAndFill(cell.node.attrs));
        }
        dispatch(tr.scrollIntoView());
    }
    return true;
};
exports.addColumnAfter = addColumnAfter;
//# sourceMappingURL=addColumnAfter.js.map
