"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeCurrentColumn = void 0;
const helpers_1 = require("../helpers.js");
const utils_1 = require("../utils.js");
const removeCurrentColumn = (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;
    }
    if (parentRow.node.childCount < 2) {
        // there is one column left
        return false;
    }
    const parentCellIndex = (0, helpers_1.findChildIndex)(parentRow.node, parentCell.node);
    if (parentCellIndex < 0) {
        return false;
    }
    if (parentCellIndex === 0) {
        return false; // TODO: remove first column
    }
    if (dispatch) {
        let tr = state.tr;
        const allRows = (0, utils_1.findChildTableRows)(parentTable.node);
        for (const row of allRows) {
            const rowCells = (0, utils_1.findChildTableCells)(row.node);
            const cell = rowCells[parentCellIndex];
            const from = parentTable.start + row.pos + cell.pos;
            const to = from + cell.node.nodeSize;
            tr = tr.delete(tr.mapping.map(from), tr.mapping.map(to));
        }
        dispatch(tr);
    }
    return true;
};
exports.removeCurrentColumn = removeCurrentColumn;
//# sourceMappingURL=removeCurrentColumn.js.map
