"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
postscriptum.plugin('ps-empty-end-pages', (processor, options) => {
    processor.on('pagination-end', function () {
        let pagesToAdd = options.minToAdd;
        const remainder = (this.pages.length + pagesToAdd) % options.multipleOf;
        if (remainder != 0)
            pagesToAdd += options.multipleOf - remainder;
        if (options.beforeLast === true)
            options.beforeLast = 1;
        const beforePage = options.beforeLast ? this.pages[this.pages.length - options.beforeLast] : null;
        for (let i = 0; i < pagesToAdd; i++) {
            this.addStandalonePage(this.currentPage.body.cloneNode(false), options.pageName, options.blank, beforePage);
        }
        // Updates the global counter of the page count
        const destCounterReset = postscriptum.counters.parseCounterValue(getComputedStyle(this.dest).counterReset);
        destCounterReset.pages += pagesToAdd;
        this.dest.style.counterReset = Object.entries(destCounterReset).flat().join(' ');
    });
}, { multipleOf: 4, beforeLast: true, pageName: '', minToAdd: 0, blank: true });
