"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const paragraph_1 = require("../paragraph");
const xml_components_1 = require("../xml-components");
const grid_1 = require("./grid");
const properties_1 = require("./properties");
class Table extends xml_components_1.XmlComponent {
    constructor(rows, cols) {
        super("w:tbl");
        this.properties = new properties_1.TableProperties();
        this.root.push(this.properties);
        const gridCols = [];
        for (let i = 0; i < cols; i++) {
            gridCols.push(1);
        }
        this.grid = new grid_1.TableGrid(gridCols);
        this.root.push(this.grid);
        this.rows = [];
        for (let i = 0; i < rows; i++) {
            const cells = [];
            for (let j = 0; j < cols; j++) {
                cells.push(new TableCell());
            }
            const row = new TableRow(cells);
            this.rows.push(row);
            this.root.push(row);
        }
    }
    getRow(ix) {
        return this.rows[ix];
    }
    getCell(row, col) {
        return this.getRow(row).getCell(col);
    }
    setWidth(type, width) {
        this.properties.setWidth(type, width);
        return this;
    }
    fixedWidthLayout() {
        this.properties.fixedWidthLayout();
        return this;
    }
}
exports.Table = Table;
class TableRow extends xml_components_1.XmlComponent {
    constructor(cells) {
        super("w:tr");
        this.properties = new TableRowProperties();
        this.root.push(this.properties);
        this.cells = cells;
        cells.forEach((c) => this.root.push(c));
    }
    getCell(ix) {
        return this.cells[ix];
    }
}
exports.TableRow = TableRow;
class TableRowProperties extends xml_components_1.XmlComponent {
    constructor() {
        super("w:trPr");
    }
}
exports.TableRowProperties = TableRowProperties;
class TableCell extends xml_components_1.XmlComponent {
    constructor() {
        super("w:tc");
        this.properties = new TableCellProperties();
        this.root.push(this.properties);
    }
    addContent(content) {
        this.root.push(content);
        return this;
    }
    prepForXml() {
        const retval = super.prepForXml();
        const content = retval["w:tc"];
        if (!content[content.length - 1]["w:p"]) {
            content.push(new paragraph_1.Paragraph().prepForXml());
        }
        return retval;
    }
    createParagraph(text) {
        const para = new paragraph_1.Paragraph(text);
        this.addContent(para);
        return para;
    }
}
exports.TableCell = TableCell;
class TableCellProperties extends xml_components_1.XmlComponent {
    constructor() {
        super("w:tcPr");
    }
}
exports.TableCellProperties = TableCellProperties;
//# sourceMappingURL=table.js.map