// add tables

import { CreateDocx, OptionsTable } from "../../../build";
import * as fs from "fs";

const docx = new CreateDocx();

// add a table with text contents
const items = [
    ["11", "12", "13", "14"],
    ["21", "22", "23", "24"],
    ["31", "32", "33", "34"],
];

docx.addTable(items);

// add a table applying table styles
const optionsTableA: OptionsTable = {
    align: "right",
    border: {
        top: {
            color: "FF0000",
            width: 4,
        },
        right: {
            width: 4,
        },
        bottom: {
            color: "FF0000",
            width: 4,
        },
        left: {
            width: 4,
        },
        insideH: {
            color: "00FF00",
            width: 10,
            style: "dashed",
            space: 10,
        },
        insideV: {
            style: "dashed",
        },
    },
    textWrapping: "around",
    width: {
        type: "pct",
        value: 50,
    },
};
docx.addTable(items, [], optionsTableA);
docx.addText("Text content added 'around' a table.");

// add a table applying table styles
const optionsTableB: OptionsTable = {
    align: "center",
    cellSpacing: 30,
    cellMargin: {
        top: 100,
        left: 200,
        bottom: 100,
        right: 200,
    },
    columnWidths: [5000, 1000, 1000, 1000],
    layout: "fixed",
    paragraphAfterOptions: {
        spacing: {
            before: 0,
            after: 0,
        },
    },
    width: {
        type: "dxa",
        value: 8000,
    },
};
docx.addTable(items, [], optionsTableB);

docx.save().then(contents => {
    fs.writeFileSync("addTable_1.docx", Buffer.from(contents));
});
