"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertToYfmTable = void 0;
const BaseSchema_1 = require("../../../base/BaseSchema/index.js");
const helpers_1 = require("../../../markdown/Table/helpers.js");
const utils_1 = require("../utils.js");
const convertToYfmTable = (state, dispatch) => {
    const mdTable = (0, helpers_1.findParentTable)(state);
    if (!mdTable)
        return false;
    if (dispatch) {
        const { schema } = state;
        const yfmTableRowNodes = [];
        const mdTableRows = (0, helpers_1.findTableRows)(mdTable.node, state.schema);
        for (const row of mdTableRows) {
            const yfmTableCellNodes = [];
            const mdRowCells = (0, helpers_1.findTableCells)(row.node, state.schema);
            for (const cell of mdRowCells) {
                yfmTableCellNodes.push((0, utils_1.yfmTableCellType)(schema).create(null, (0, BaseSchema_1.pType)(schema).create(null, cell.node.content)));
            }
            yfmTableRowNodes.push((0, utils_1.yfmTableRowType)(schema).create(null, yfmTableCellNodes));
        }
        const yfmTableNode = (0, utils_1.yfmTableType)(schema).create(null, (0, utils_1.yfmTableBodyType)(schema).create(null, yfmTableRowNodes));
        dispatch(state.tr.replaceWith(mdTable.pos, mdTable.pos + mdTable.node.nodeSize, yfmTableNode));
    }
    return true;
};
exports.convertToYfmTable = convertToYfmTable;
//# sourceMappingURL=convert-table.js.map
