"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createReport = void 0;
const utils_1 = require("./utils");
const bluebird_1 = require("bluebird");
const pdf = bluebird_1.Promise.promisifyAll(require("html-pdf"));
const createPDF = (html) => {
    var options = {
        format: "A4",
        base: "file:///" + __dirname + "/",
        localUrlAccess: true, // set this to true to enable local file access
    };
    return new bluebird_1.Promise((resolve, reject) => {
        pdf.create(html, options).toBuffer((err, buffer) => {
            if (err !== null) {
                reject(err);
            }
            else {
                resolve(buffer);
            }
        });
    });
};
const createReport = async (_data, type) => {
    let content;
    //Get the template corresponding to report
    try {
        content = (0, utils_1.getContent)(type);
        const assets = (0, utils_1.getAssets)(type);
        console.log(_data);
        content = (0, utils_1.replaceAssesmentData)([..._data.params.header, ...assets], content);
        content = (0, utils_1.replaceCompetenciesStrWeak)(_data.params.competencies, content);
        content = (0, utils_1.replacePersonality)(_data.params.personality, content);
        const averageHeight = 260; //Estimated height for personality card
        let nextPosition = 2125 + averageHeight * _data.params.personality.length;
        if (_data.params.waysToDevelop) {
            content = (0, utils_1.replaceWaysToDevelop)(_data.params.waysToDevelop, nextPosition, content);
        }
        const wtdQty = _data.params.waysToDevelop.length;
        nextPosition =
            wtdQty / 2 === 1
                ? 850 * (wtdQty / 2) + nextPosition + 127
                : 1200 * (wtdQty / 2) + nextPosition + 127;
        content = (0, utils_1.replacePracticalTips)(content, nextPosition);
        nextPosition = nextPosition + 1000;
        content = (0, utils_1.replaceYourIndividualDevPlan)(content, nextPosition);
        nextPosition = nextPosition + 1240;
        content = (0, utils_1.replaceFooter)(content, nextPosition);
        const buffer = await createPDF(content);
        return buffer;
    }
    catch (e) {
        console.error(e);
        throw Error();
    }
};
exports.createReport = createReport;
//# sourceMappingURL=index.js.map