// add text contents and WordFragments in the same paragraph

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

const docx = new CreateDocx();

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

// create texts WordFragments
const wordFragmentTextA = new WordFragment();
wordFragmentTextA.addText("A link to ");
const wordFragmentTextB = new WordFragment();
wordFragmentTextB.addText(
    " in the middle of a paragraph with the following date: "
);

// create a date WordFragment
const dateTime: OptionsDateTime = {
    format: "M/d/yyyy",
    bold: true,
    color: "333333",
};
const wordFragmentDate = new WordFragment();
wordFragmentDate.addDateTime(dateTime);

// add the WordFragments as inline contents in the same paragraph
docx.addText([
    wordFragmentTextA,
    wordFragmentLink,
    wordFragmentTextB,
    wordFragmentDate,
]);

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