// generate and save multiple DOCX files with their own contents

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

// create two documents
const docxA = new CreateDocx();
const docxB = new CreateDocx();

// add contents into the first document
docxA.addText("New content.");
const linkA: OptionsLink = {
    link: "https://www.phpdocx.com",
    text: "Link to phpdocx.",
};
docxA.addLink(linkA);

// generate a new DOCX
docxA.save().then(contents => {
    fs.writeFileSync("save_2A.docx", Buffer.from(contents));
});

// add more contents into the first document
const filePng = fs.readFileSync("../../files/image.png");
docxA.addText("A PNG image:");
const imagePng: OptionsImage = {
    image: filePng,
};
docxA.addImage(imagePng);

// generate a new DOCX with the new contents
docxA.save().then(contents => {
    fs.writeFileSync("save_2B.docx", Buffer.from(contents));
});

// add contents into the second document
const text =
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

const optionsParagraph: OptionsParagraph = {
    align: "justify",
    bold: true,
};
docxB.addText(text, optionsParagraph);

const textA: OptionsText = {
    italic: true,
    fontSize: 14,
    text: "New content.",
};
const textB: OptionsText = {
    color: "0000FF",
    font: "Times New Roman",
    text: " Other content.",
};
docxB.addText([textA, textB], optionsParagraph);

const linkB: OptionsLink = {
    link: "https://www.phpxlsx.com",
    text: "Link to phpxlsx.",
};
docxB.addLink(linkB);

const fileJpg = fs.readFileSync("../../files/image.jpg");
docxB.addText("A JPG image with default styles:");
const imageJpg: OptionsImage = {
    image: fileJpg,
};
docxB.addImage(imageJpg);

// generate a new DOCX
docxB.save().then(contents => {
    fs.writeFileSync("save_2C.docx", Buffer.from(contents));
});
