"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clearCells = void 0;
const specs_1 = require("../../../../../base/specs.js");
const table_desc_1 = require("../../../../../../table-utils/table-desc.js");
const clearCells = (params) => {
    return (state, dispatch) => {
        const table = state.doc.nodeAt(params.tablePos);
        const tableDesc = table && table_desc_1.TableDesc.create(table)?.bind(params.tablePos);
        if (!tableDesc)
            return false;
        if (!dispatch)
            return true;
        const { tr } = state;
        const paragraph = (0, specs_1.pType)(state.schema);
        const clear = (cells) => {
            for (const pos of cells) {
                if (pos.type !== 'real')
                    continue;
                tr.replaceWith(tr.mapping.map(pos.from + 1), tr.mapping.map(pos.to - 1), paragraph.create());
            }
        };
        if (params.rows) {
            for (const rowIdx of params.rows) {
                const cellsPos = tableDesc.getPosForRowCells(rowIdx);
                clear(cellsPos);
            }
        }
        if (params.cols) {
            for (const colIdx of params.cols) {
                const cellsPos = tableDesc.getPosForColumn(colIdx);
                clear(cellsPos);
            }
        }
        if (tr.docChanged)
            dispatch(tr);
        return true;
    };
};
exports.clearCells = clearCells;
//# sourceMappingURL=clear-cells.js.map
