// add tables with text contents and WordFragments

import {
    CreateDocx,
    OptionsImage,
    OptionsLink,
    OptionsText,
    WordFragment,
} from "../../../build";
import * as fs from "fs";

const docx = new CreateDocx();

// create WordFragments
const wordFragmentText = new WordFragment();
const textA: OptionsText = {
    bold: false,
    italic: true,
    fontSize: 14,
    text: "A content with styles ",
};
const textB: OptionsText = {
    color: "0000FF",
    font: "Times New Roman",
    text: "in a cell.",
};
wordFragmentText.addText([textA, textB]);

const wordFragmentLink = new WordFragment();
const optionsLink: OptionsLink = {
    link: "https://www.phpdocx.com",
    text: "phpdocx",
};
wordFragmentLink.addLink(optionsLink);

const filePng = fs.readFileSync("../../files/image.png");
const wordFragmentImage = new WordFragment();
const imagePng: OptionsImage = {
    image: filePng,
};
wordFragmentImage.addImage(imagePng);

// add text contents and WordFragments in the table
const items = [
    ["Title A", "Title B", "Title C"],
    [wordFragmentText, wordFragmentLink, wordFragmentImage],
];

docx.addTable(items);

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