// add footer contents in multiple sections

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

const docx = new CreateDocx();

// add footer contents in the first section
const footersA: OptionsFooter[] = [];

const footerFragmentDefaultA = new WordFragment();
footerFragmentDefaultA.addText("Text footer first section.");
const footerContentDefaultA: OptionsFooter = {
    text: footerFragmentDefaultA,
};

const textFirstFooterA: OptionsText = {
    bold: true,
    text: "Text first footer in the first section.",
};
const footerFragmentFirstA = new WordFragment();
footerFragmentFirstA.addText([textFirstFooterA]);
const footerContentFirstA: OptionsFooter = {
    text: footerFragmentFirstA,
    type: "first",
};

footersA.push(footerContentDefaultA);
footersA.push(footerContentFirstA);

// add footers
docx.addFooter(footersA);

docx.addText("First page in the first section.");
docx.addBreak("page");
docx.addText("Page in the first section.");

// add footer contents in the second section excluding footers and footers from the previous section
const footersB: OptionsFooter[] = [];
const optionsSection: OptionsSection = {
    excludeHeadersFooters: true,
};
docx.addSection(optionsSection);

const footerFragmentDefaultB = new WordFragment();
footerFragmentDefaultB.addText("Text footer second section.");
const footerContentDefaultB: OptionsFooter = {
    text: footerFragmentDefaultB,
};

const textFirstFooterB: OptionsText = {
    bold: true,
    text: "Text first footer in the second section.",
};
const footerFragmentFirstB = new WordFragment();
footerFragmentFirstB.addText([textFirstFooterB]);
const footerContentFirstB: OptionsFooter = {
    text: footerFragmentFirstB,
    type: "first",
};

footersB.push(footerContentDefaultB);
footersB.push(footerContentFirstB);

// add footers
docx.addFooter(footersB);

docx.addText("First page in the second section.");
docx.addBreak("page");
docx.addText("Page in the second section.");

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