"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.preloadDone = void 0;
var base64_1 = require("./base64");
var pdfmake_1 = __importDefault(require("pdfmake/build/pdfmake"));
var dayjs_1 = __importDefault(require("dayjs"));
var timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
var utc_1 = __importDefault(require("dayjs/plugin/utc"));
var react_1 = require("react");
dayjs_1.default.extend(utc_1.default);
dayjs_1.default.extend(timezone_1.default);
dayjs_1.default.tz.setDefault("Asia/Seoul");
var ReactLazyPreload = function (importStatement) {
    var Component = (0, react_1.lazy)(importStatement);
    Component.preload = importStatement;
    return Component;
};
exports.preloadDone = false;
// @ts-ignore
var pdfFonts = ReactLazyPreload(function () { return Promise.resolve().then(function () { return __importStar(require("./vfs_fonts_jejumj_gd_cn")); }); });
// @ts-ignore
pdfFonts.preload().then(function (res) {
    pdfmake_1.default.vfs = res.pdfMake.vfs;
    pdfmake_1.default.fonts = {
        제주명조: {
            normal: "jejumyungjo.ttf",
            bold: "jejugothic.ttf",
            italics: "cjk.ttf",
        },
    };
    exports.preloadDone = true;
});
pdfmake_1.default.tableLayouts = {
    showblackline: {
        hLineWidth: function (i, node) {
            if (i === 0 || i === node.table.body.length) {
                //맨앞 맨뒤
                return 1;
            }
            return i === node.table.headerRows ? 1 : 1;
        },
        vLineWidth: function (i) {
            return 1;
        },
        hLineColor: function (i) {
            var color = "black";
            // if(i===2) color='red';
            // else if(i===3) color='blue';
            // else if(i===4) color='green';
            return color;
        },
        vLineColor: function (i) {
            var color = "black";
            // if(i===2) color='red';
            // else if(i===3) color='blue';
            // else if(i===4) color='green';
            return color;
        },
    },
    showline: {
        hLineWidth: function (i, node) {
            if (i === 0 || i === node.table.body.length) {
                //맨앞 맨뒤
                return 1;
            }
            return i === node.table.headerRows ? 1 : 1;
        },
        vLineWidth: function (i) {
            return 1;
        },
        hLineColor: function (i) {
            var color = "#1A408E";
            // if(i===2) color='red';
            // else if(i===3) color='blue';
            // else if(i===4) color='green';
            return color;
        },
        vLineColor: function (i) {
            var color = "#1A408E";
            // if(i===2) color='red';
            // else if(i===3) color='blue';
            // else if(i===4) color='green';
            return color;
        },
    },
    hideline: {
        hLineWidth: function (i, node) {
            if (i === 0 || i === node.table.body.length) {
                //맨앞 맨뒤
                return 0;
            }
            return i === node.table.headerRows ? 0 : 0;
        },
        vLineWidth: function (i) {
            return 0;
        },
        hLineColor: function (i) {
            var color = "#1A408E";
            // if(i===2) color='red';
            // else if(i===3) color='blue';
            // else if(i===4) color='green';
            return color;
        },
    },
    headerunderline: {
        hLineWidth: function (i, node) {
            if (i === 0 || i === node.table.body.length) {
                return 0;
            }
            return i === node.table.headerRows ? 2 : 0;
        },
        vLineWidth: function (i) {
            return 0;
        },
        hLineColor: function (i) {
            return "#1A408E";
        },
    },
    titletable: {
        hLineWidth: function (i, node) {
            if (i === 0 || i === node.table.body.length) {
                return 0;
            }
            return i === node.table.headerRows ? 0 : 1;
        },
        vLineWidth: function (i) {
            return 0;
        },
        hLineColor: function (i) {
            return "#1A408E";
        },
    },
};
var PDF = /** @class */ (function () {
    function PDF(data, tier, dayDueDate, weekDueDate, agencyLogo) {
        var _this = this;
        this.makeFirstPage = function () {
            try {
                _this.doc = {
                    pageSize: "A4",
                    info: {
                        title: "리더스아이 트레이닝 수행리포트",
                        author: "bnri",
                        subject: "리더스아이 트레이닝 수행리포트",
                        keywords: "",
                    },
                    pageMargins: [20, 40, 20, 20],
                    background: function (currentPage, pageCount) {
                        if (currentPage * 1 === 1) {
                            return [
                                {
                                    margin: [20, 26],
                                    layout: "headerunderline",
                                    table: {
                                        // headers are automatically repeated if the table spans over multiple pages
                                        // you can declare how many rows should be treated as headers
                                        headerRows: 1,
                                        widths: ["*", "*"],
                                        body: [
                                            [
                                                {
                                                    text: "",
                                                    margin: [0, 10, 0, 10],
                                                    border: [false, false, false, false],
                                                },
                                                {
                                                    text: " ",
                                                    margin: [0, 10, 0, 10],
                                                    border: [false, false, false, false],
                                                },
                                            ],
                                            [
                                                {
                                                    text: "",
                                                    border: [false, false, false, false],
                                                },
                                                {
                                                    text: "",
                                                    border: [false, false, false, false],
                                                },
                                            ],
                                        ],
                                    },
                                },
                                {
                                    image: "readerseyeLogo",
                                    //fit: [200, 200],
                                    fit: [100, 180],
                                    opacity: 1,
                                    absolutePosition: { x: 470, y: 28 },
                                    //absolutePosition: { x: 550, y: 800 },
                                },
                                {
                                    text: "".concat(_this.data.testeeNickname, " (").concat(_this.data.testeeID, ") ").concat(_this.data.testeeClass),
                                    bold: true,
                                    // color: '#7367f0',
                                    color: "black",
                                    absolutePosition: { x: 46, y: 50 },
                                },
                            ];
                        }
                        else {
                            // console.log("background에서보자");
                            // console.log(userData.AgencyLogoBase64);
                            return [
                                {
                                    margin: [20, 26],
                                    layout: "headerunderline",
                                    table: {
                                        // headers are automatically repeated if the table spans over multiple pages
                                        // you can declare how many rows should be treated as headers
                                        headerRows: 1,
                                        widths: ["*", "*"],
                                        body: [
                                            [
                                                {
                                                    text: "",
                                                    margin: [0, 10, 0, 10],
                                                },
                                                { text: " ", margin: [0, 10, 0, 10] },
                                            ],
                                            ["", ""],
                                        ],
                                    },
                                },
                                {
                                    image: "학원로고",
                                    // image: 'agencyLogo',
                                    //fit: [200, 200],
                                    fit: [20, 20],
                                    opacity: 1,
                                    absolutePosition: { x: 21, y: 37 },
                                    //absolutePosition: { x: 550, y: 800 },
                                },
                                {
                                    text: _this.data.agencyName,
                                    bold: true,
                                    // color: '#7367f0',
                                    color: "black",
                                    absolutePosition: { x: 46, y: 41 },
                                },
                                {
                                    image: "readerseyeLogo",
                                    //fit: [200, 200],
                                    fit: [100, 180],
                                    opacity: 1,
                                    absolutePosition: { x: 470, y: 28 },
                                    //absolutePosition: { x: 550, y: 800 },
                                },
                            ];
                        }
                    },
                    footer: function (currentPage, pageCount) {
                        if (currentPage === 1) {
                            return null;
                        }
                        return {
                            table: {
                                widths: [600, 100],
                                body: [
                                    [
                                        {
                                            text: currentPage - 1 + " / " + (pageCount - 1),
                                            alignment: "center",
                                            fontSize: 10,
                                        },
                                    ],
                                ],
                            },
                            layout: "noBorders",
                        };
                    },
                    compress: true,
                    content: [
                        {
                            margin: [30, 30, 30, 30],
                            table: {
                                widths: ["*", "*"],
                                headerRows: 1,
                                body: [
                                    [
                                        {
                                            text: " ",
                                        },
                                        {
                                            text: " ",
                                        },
                                    ],
                                    [
                                        {
                                            margin: [10, 220, 10, 10],
                                            text: "리더스아이 트레이닝 수행리포트",
                                            bold: true,
                                            fontSize: 26,
                                            alignment: "center",
                                            colSpan: 2,
                                        },
                                    ],
                                    [
                                        {
                                            margin: [10, 0, 10, 250],
                                            text: "".concat(_this.data.startdate, "~").concat(_this.data.enddate),
                                            bold: true,
                                            fontSize: 20,
                                            alignment: "center",
                                            colSpan: 2,
                                        },
                                    ],
                                    [
                                        {
                                            margin: [10, 20, 10, 10],
                                            columns: [
                                                { width: "*", text: "" },
                                                {
                                                    width: "auto",
                                                    image: "학원로고",
                                                    // image: 'agencyLogo',
                                                    //fit: [200, 200],
                                                    fit: [60, 60],
                                                },
                                                {
                                                    margin: [8, 20, 0, 0],
                                                    width: "auto",
                                                    text: _this.data.agencyName,
                                                    fontSize: 20,
                                                    bold: true,
                                                },
                                                { width: "*", text: "" },
                                            ],
                                            colSpan: 2,
                                        },
                                    ],
                                ],
                            },
                            layout: {
                                hLineWidth: function (i, node) {
                                    if (i === 0 || i === node.table.body.length) {
                                        return 0;
                                    }
                                    return i === node.table.headerRows ? 0 : 0;
                                },
                                vLineWidth: function (i) {
                                    return 0;
                                },
                                hLineColor: function (i) {
                                    return i === 1 ? "black" : "#aaa";
                                },
                            },
                            pageBreak: "after",
                        }, //main page
                    ],
                    images: {
                        readerseyeLogo: base64_1.imgbase64forPDF["리더스아이로고가로"],
                        학원로고: _this.agencyLogo ? _this.agencyLogo : base64_1.imgbase64forPDF["기본로고"],
                        메달: base64_1.imgbase64forPDF[_this.tier],
                    },
                    styles: {
                        header: {
                            fontSize: 14,
                            bold: true,
                            alignment: "left",
                        },
                        sectionTitle: {
                            fontSize: 13,
                            bold: true,
                            margin: [0, 10, 0, 10],
                        },
                        levelScoreTitle: {
                            fontSize: 10,
                            bold: true,
                            margin: [0, 3, 0, 3],
                        },
                        resultTitle: {
                            fontSize: 11,
                            bold: true,
                            margin: [0, 0, 0, 5],
                        },
                        resultText: {
                            fontSize: 10,
                            lineHeight: 1.5,
                        },
                        tableHeader: {
                            bold: true,
                            fontSize: 9,
                            color: "black",
                            alignment: "center",
                            fillColor: "#eeedff",
                            margin: [0, 2, 0, 0],
                        },
                        tableItem: {
                            fontSize: 9,
                            color: "black",
                            alignment: "center",
                            margin: [0, 2, 0, 0],
                        },
                        tableParagraph: {
                            bold: false,
                            fontSize: 9,
                            lineHeight: 1.6,
                            color: "black",
                        },
                    },
                    pageBreakBefore: function (currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
                        return currentNode.headlineLevel === 1;
                    },
                    //headlineLevel: 1,
                    defaultStyle: {
                        font: "제주명조",
                    },
                };
                return true;
            }
            catch (err) {
                console.log("err", err);
                return false;
            }
        };
        this.makeSecondPage = function () {
            if (!_this.doc || !_this.doc.content) {
                throw new Error("doc or content not found");
            }
            var ratioChart = document.getElementById("RatioChart");
            var avgScoreChart = document.getElementById("AvgScoreChart");
            var avgDurationChart = document.getElementById("AvgDurationChart");
            var levelScoreDayChart = document.getElementById("levelScoreDayChart");
            var levelScoreWeekChart = document.getElementById("levelScoreWeekChart");
            if (!ratioChart || !avgScoreChart || !avgDurationChart || !levelScoreDayChart || !levelScoreWeekChart) {
                throw new Error("chart not found");
            }
            try {
                var ratioSrc = ratioChart.toDataURL();
                var avgScoreSrc = avgScoreChart.toDataURL();
                var avgDurationSrc = avgDurationChart.toDataURL();
                var levelScoreDaySrc = levelScoreDayChart.toDataURL();
                var levelScoreWeekSrc = levelScoreWeekChart.toDataURL();
                var firstScoreText = "".concat(_this.data.firstScore.toLocaleString(), "\uC810(").concat(_this.data.firstScoreDate, " \uC774\uD6C4, ").concat(_this.tier, ", ").concat(_this.data.firstScoreRank, "\uC704)");
                var monthScoreText = "".concat(_this.data.monthScore.toLocaleString(), "\uC810(").concat((0, dayjs_1.default)().format("YY년MM월,"), " ").concat(_this.data.monthScoreRank, "\uC704)");
                _this.doc.content = __spreadArray(__spreadArray([], _this.doc.content, true), [
                    {
                        stack: [
                            {
                                text: "".concat(_this.data.testeeNickname, "(").concat(_this.data.testeeID, ")\uC758 \uB9AC\uB354\uC2A4\uC544\uC774 \uD2B8\uB808\uC774\uB2DD \uC218\uD589\uB9AC\uD3EC\uD2B8"),
                                alignment: "center",
                                bold: true,
                                fontSize: 18,
                                margin: [0, 40, 0, 0],
                            },
                            {
                                text: "".concat(_this.data.startdate, " ~ ").concat(_this.data.enddate),
                                alignment: "center",
                                bold: true,
                                fontSize: 14,
                                margin: [0, 10],
                            },
                        ],
                    },
                    {
                        table: {
                            widths: ["80%", "20%"],
                            heights: [10, 10, 10, 10, 10, 10],
                            headerRows: 0,
                            body: [
                                [
                                    {
                                        text: "\uC218\uD589 \uAE30\uAD00 : ".concat(_this.data.agencyName, "(").concat(_this.data.agencyID, ")"),
                                        fontSize: 10,
                                        border: [false],
                                    },
                                    { rowSpan: 6, image: "메달", width: 47.25, height: 75, alignment: "center", border: [false] },
                                ],
                                [
                                    {
                                        text: "\uCD1D \uB204\uC801\uC810\uC218 : ".concat(_this.data.totScore.toLocaleString(), "\uC810"),
                                        fontSize: 10,
                                        border: [false],
                                    },
                                ],
                                [
                                    {
                                        text: "\uC6D4\uAC04\uC810\uC218 : ".concat(monthScoreText),
                                        fontSize: 10,
                                        border: [false],
                                    },
                                ],
                                [
                                    {
                                        text: "\uAE30\uB85D 1 : ".concat(firstScoreText),
                                        fontSize: 10,
                                        border: [false],
                                    },
                                ],
                                [
                                    {
                                        text: "\uAE30\uB85D 2 : ".concat(_this.data.secondScore.toLocaleString(), "\uC810(").concat(_this.data.secondScoreDate, " \uC774\uD6C4)"),
                                        fontSize: 10,
                                        border: [false],
                                    },
                                ],
                                [
                                    {
                                        text: "\uAE30\uAC04 \uB0B4 \uCD1D \uD68D\uB4DD \uC810\uC218 : ".concat(_this.data.dueScore.toLocaleString(), "\uC810"),
                                        fontSize: 10,
                                        border: [false],
                                    },
                                ],
                            ],
                        },
                    },
                    { text: "\uD2B8\uB808\uC774\uB2DD \uC218\uD589 \uD604\uD669", style: "sectionTitle" },
                    {
                        margin: [0, 5, 0, 5],
                        table: {
                            widths: ["1%", "32%", "1%", "32%", "1%", "32%", "1%"],
                            heights: [160],
                            headerRows: 0,
                            body: [
                                [
                                    { text: "", border: [false] },
                                    {
                                        stack: [
                                            { text: "수행률", alignment: "center", fontSize: 12, margin: [0, 5, 0, 5], bold: true },
                                            {
                                                image: ratioSrc,
                                                alignment: "center",
                                                fit: [130, 130],
                                            },
                                        ],
                                    },
                                    { text: "", border: [false] },
                                    {
                                        stack: [
                                            { text: "평균 수행 점수", alignment: "center", fontSize: 12, margin: [0, 5, 0, 5], bold: true },
                                            {
                                                image: avgScoreSrc,
                                                alignment: "center",
                                                fit: [130, 130],
                                            },
                                        ],
                                    },
                                    { text: "", border: [false] },
                                    {
                                        stack: [
                                            { text: "일 평균 수행 시간", alignment: "center", fontSize: 12, margin: [0, 5, 0, 5], bold: true },
                                            {
                                                image: avgDurationSrc,
                                                alignment: "center",
                                                fit: [130, 130],
                                            },
                                        ],
                                    },
                                    { text: "", border: [false] },
                                ],
                            ],
                        },
                        layout: {
                            hLineColor: function () { return "#aaa9bc"; },
                            vLineColor: function () { return "#aaa9bc"; },
                        },
                    },
                    {
                        text: "* \uAE30\uAD00 \uD3C9\uADE0 : \uD559\uC0DD\uC774 \uC18D\uD55C \uAE30\uAD00(".concat(_this.data.agencyName, ")\uC758 \uC804\uCCB4 \uD559\uC0DD\uB4E4\uC758 \uD3C9\uADE0 \uC810\uC218"),
                        fontSize: 10,
                        margin: [0, 10, 0, 5],
                    },
                    { text: "\uD2B8\uB808\uC774\uB2DD \uB808\uBCA8\uC2A4\uCF54\uC5B4 \uCD94\uC138", style: "sectionTitle" },
                    { text: "\uC77C\uBCC4 (".concat(_this.dayDueDate.startDate, " ~ ").concat(_this.dayDueDate.endDate, ")"), style: "levelScoreTitle" },
                    {
                        image: levelScoreDaySrc,
                        alignment: "center",
                        width: 570,
                        height: 135,
                        // fit: [130, 130],
                    },
                    { text: "\uC8FC\uBCC4 (".concat(_this.weekDueDate.startDate, " ~ ").concat(_this.weekDueDate.endDate, ")"), style: "levelScoreTitle" },
                    {
                        image: levelScoreWeekSrc,
                        alignment: "center",
                        width: 570,
                        height: 135,
                    },
                    {
                        text: "* \uB808\uBCA8\uACFC \uC218\uD589\uC810\uC218\uAC00 \uBC18\uC601\uB41C \uC810\uC218\uC785\uB2C8\uB2E4. 1\uB808\uBCA8\uB2F9 20\uC810\uC774 \uAC00\uC0B0\uB429\uB2C8\uB2E4. (\uB808\uBCA8\uC2A4\uCF54\uC5B4 = \uC810\uC218 + \uB808\uBCA8 x 20)",
                        fontSize: 10,
                        margin: [0, 10, 0, 0],
                    },
                ], false);
                return true;
            }
            catch (err) {
                console.log("err", err);
                return false;
            }
        };
        this.makeThirdPage = function () {
            try {
                if (!_this.doc || !_this.doc.content) {
                    throw new Error("doc or content not found");
                }
                var domainChart = document.getElementById("SentencemaskDomainChart");
                if (!domainChart) {
                    throw new Error("chart not found");
                }
                var domainChartSrc = domainChart.toDataURL();
                var headerList = ["할당된 과제", "레벨", "언어", "일 수행횟수", "주당 수행일", "총 수행횟수", "수행률", "총 수행시간", "평균 점수", "총 획득점수"];
                var trainingTypes = [
                    {
                        type: "Reading",
                        names: ["Sentence Mask", "Word Ordering", "Keyword Finding", "Category Finding"],
                    },
                    {
                        type: "Cognitive",
                        names: ["Visual Span", "Visual Counting", "TMT", "Stroop"],
                    },
                    {
                        type: "Tracking",
                        names: ["Saccade Tracking", "Pursuit Tracking", "Anti Tracking", "Sentence Tracking"],
                    },
                    {
                        type: "Exercise",
                        names: ["Exercise Horizontal", "Exercise Vertical", "Exercise HJump", "Exercise VJump"],
                    },
                ];
                var MakeTableRow_1 = function (task, data, hideLanguage, isHeader) {
                    var style = isHeader ? "tableHeader" : "tableItem";
                    if (!data) {
                        return [
                            {
                                style: style,
                                text: task,
                            },
                            {
                                style: style,
                                colSpan: 9,
                                text: "수행 없음",
                                alignment: "center",
                            },
                        ];
                    }
                    return [
                        { style: style, text: task },
                        { style: style, text: parseFloat(data.level.toFixed(1)) },
                        { style: style, text: hideLanguage ? "" : data.language },
                        { style: style, text: "".concat(parseFloat(data.reculsiveCount.toFixed(1)), "\uD68C") },
                        { style: style, text: "".concat(parseFloat(data.weeklyPerformedDays.toFixed(1)), "\uC77C") },
                        { style: style, text: "".concat(data.performedCount, " / ").concat(data.needPerformedCount) },
                        { style: style, text: "".concat(parseFloat((data.performedRatio * 100).toFixed(1)), "%") },
                        { style: style, text: "".concat(parseFloat(data.totDuration.toFixed(1)), "\uBD84") },
                        { style: style, text: "".concat(parseFloat(data.avgScore.toFixed(1)), "\uC810") },
                        { style: style, text: "".concat(parseFloat(data.totScore.toFixed(1)), "\uC810") },
                    ];
                };
                _this.doc.content = __spreadArray(__spreadArray([], _this.doc.content, true), [
                    { text: "\uAC1C\uBCC4 \uD2B8\uB808\uC774\uB2DD \uC218\uD589 \uACB0\uACFC", style: "sectionTitle", pageBreak: "before", margin: [0, 40, 0, 10] },
                    {
                        table: {
                            widths: ["20%", "7%", "8%", "auto", "auto", "auto", "8%", "auto", "auto", "auto"],
                            heights: Array(22).fill(15),
                            headerRows: 1,
                            body: __spreadArray(__spreadArray([
                                __spreadArray([], headerList.map(function (h) { return ({
                                    text: h,
                                    style: "tableHeader",
                                }); }), true)
                            ], trainingTypes
                                .map(function (type) {
                                var returnComponents = [];
                                returnComponents.push.apply(returnComponents, type.names.map(function (task) {
                                    var find = _this.data.trainingList.find(function (f) { return f.taskName === task.split(" ").join(""); });
                                    var hideLanguage = (find === null || find === void 0 ? void 0 : find.taskType) === "Reading" || (find === null || find === void 0 ? void 0 : find.taskName) === "SentenceTracking" ? false : true;
                                    return MakeTableRow_1(task, find, hideLanguage);
                                }));
                                returnComponents.push(MakeTableRow_1("".concat(type.type, " \uD3C9\uADE0"), _this.data.typeSummary[type.type], false, true));
                                return returnComponents;
                            })
                                .flat(), true), [
                                MakeTableRow_1("\uC804\uCCB4 \uD3C9\uADE0", _this.data.typeSummary.All, false, true),
                            ], false),
                        },
                        layout: {
                            hLineColor: function () { return "#aaa9bc"; },
                            vLineColor: function () { return "#aaa9bc"; },
                        },
                    },
                    { text: "\uAE00 \uC77D\uAE30 \uD2B8\uB808\uC774\uB2DD \uBD84\uC11D", style: "sectionTitle" },
                    {
                        margin: [0, 5, 0, 5],
                        table: {
                            widths: ["1%", "18%", "1%", "50%", "1%", "28%", "1%"],
                            heights: [160],
                            headerRows: 0,
                            body: [
                                [
                                    { text: "", border: [false] },
                                    {
                                        stack: [
                                            { text: "읽은 글", alignment: "center", fontSize: 11, margin: [0, 15, 0, 15], bold: true },
                                            { text: "".concat(_this.data.sentencemaskAnalysis.readingCount, "\uD3B8"), fontSize: 14, bold: true, margin: [0, 5, 0, 5] },
                                            { text: "기관 평균", alignment: "center", fontSize: 11, margin: [0, 20, 0, 15], bold: true },
                                            { text: "".concat(_this.data.sentencemaskAnalysis.agencyAvgReadingCount, "\uD3B8"), fontSize: 12, bold: true, margin: [0, 5, 0, 5] },
                                        ],
                                        alignment: "center",
                                    },
                                    { text: "", border: [false] },
                                    {
                                        stack: [
                                            {
                                                image: domainChartSrc,
                                                alignment: "center",
                                                width: 210,
                                                height: 160,
                                            },
                                        ],
                                    },
                                    { text: "", border: [false] },
                                    {
                                        stack: [
                                            { text: "읽은 글 정보", alignment: "center", fontSize: 11, margin: [0, 15, 0, 15], bold: true },
                                            { text: "최근 시선읽기진단 평균 속도", alignment: "center", fontSize: 10, margin: [0, 5, 0, 5] },
                                            { text: "".concat(_this.data.sentencemaskAnalysis.recentReadingSpeed.reading_speed, "\uC5B4\uC808/\uBD84"), alignment: "center", fontSize: 14, margin: [0, 5, 0, 5], bold: true },
                                            { text: "현재 트레이닝 평균 속도", alignment: "center", fontSize: 10, margin: [0, 20, 0, 5] },
                                            { text: "".concat(_this.data.sentencemaskAnalysis.recentSMReadingSpeed, "\uC5B4\uC808/\uBD84"), alignment: "center", fontSize: 12, margin: [0, 5, 0, 5], bold: true },
                                        ],
                                    },
                                    { text: "", border: [false] },
                                ],
                            ],
                        },
                        layout: {
                            hLineColor: function () { return "#aaa9bc"; },
                            vLineColor: function () { return "#aaa9bc"; },
                        },
                    },
                    {
                        text: "* Sentence Mask\uB97C \uD1B5\uD574 \uC81C\uACF5\uB41C \uC77D\uAE30 \uC790\uB8CC\uC785\uB2C8\uB2E4.",
                        fontSize: 10,
                        margin: [0, 10, 0, 0],
                    },
                ], false);
                return true;
            }
            catch (err) {
                console.log("err", err);
                return false;
            }
        };
        this.makeFourthPage = function () {
            try {
                if (!_this.doc || !_this.doc.content) {
                    throw new Error("doc or content not found");
                }
                var readingChart = document.getElementById("ReadingChart");
                var cognitiveChart = document.getElementById("CognitiveChart");
                var trackingChart = document.getElementById("TrackingChart");
                var exerciseChart = document.getElementById("ExerciseChart");
                if (!readingChart || !cognitiveChart || !trackingChart || !exerciseChart) {
                    throw new Error("chart not found");
                }
                var readingChartSrc = readingChart.toDataURL();
                var cognitiveChartSrc = cognitiveChart.toDataURL();
                var trackingChartSrc = trackingChart.toDataURL();
                var exerciseChartSrc = exerciseChart.toDataURL();
                _this.doc.content = __spreadArray(__spreadArray([], _this.doc.content, true), [
                    { text: "\uAC1C\uBCC4 \uD2B8\uB808\uC774\uB2DD \uC218\uD589 \uACB0\uACFC", style: "sectionTitle", pageBreak: "before", margin: [0, 30, 0, 10] },
                    {
                        margin: [0, 0, 0, 10],
                        table: {
                            widths: [240, "auto"],
                            heights: [160],
                            body: [
                                [
                                    {
                                        image: readingChartSrc,
                                        alignment: "center",
                                        width: 240,
                                        height: 160,
                                        border: [true, true, true, true],
                                        borderColor: ["#aaa9bc", "#aaa9bc", "#aaa9bc", "#aaa9bc"],
                                    },
                                    // { text: "", border: [false, false, false, false] },
                                    {
                                        margin: [3, 0, 0, 0],
                                        stack: [
                                            { text: "Reading Training", style: "resultTitle" },
                                            {
                                                text: "읽기를 기반으로 속도 제어, 안정성 향상, 문장 완성, 어휘의 탐색 및 판단 능력을 향상시키는 훈련입니다.",
                                                style: "resultText",
                                                margin: [0, 0, 0, 3],
                                            },
                                            {
                                                ul: [
                                                    {
                                                        style: "resultText",
                                                        text: "Word Ordering : 뒤섞여 있는 어절들을 정상적인 문장이 되도록 순서를 맞춰야 합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Sentence Mask : 일정한 속도로, 순차적으로 보여지는 글을 속도에 맞춰 읽어야 합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Keyword Finding : 글에서 특정 키워드를 빠르게 탐지해야 합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Category Finding : 글에서 특정 카테고리(범주)에 해당하는 단어들을 빠르게 탐지해야 합니다.",
                                                    },
                                                ],
                                            },
                                        ],
                                        border: [false, false, false, false],
                                    },
                                ],
                            ],
                        },
                    },
                    {
                        margin: [0, 0, 0, 10],
                        table: {
                            widths: [240, "auto"],
                            heights: [160],
                            body: [
                                [
                                    {
                                        image: cognitiveChartSrc,
                                        alignment: "center",
                                        width: 240,
                                        height: 160,
                                        border: [true, true, true, true],
                                        borderColor: ["#aaa9bc", "#aaa9bc", "#aaa9bc", "#aaa9bc"],
                                    },
                                    // { text: "", border: [false, false, false, false] },
                                    {
                                        margin: [3, 0, 0, 0],
                                        stack: [
                                            { text: "Cognitive Training", style: "resultTitle" },
                                            {
                                                text: "학습의 기초가 되는 시지각, 인지능력, 판단력 및 행동 제어 능력을 향상시키는 훈련입니다.",
                                                style: "resultText",
                                                margin: [0, 0, 0, 3],
                                            },
                                            {
                                                ul: [
                                                    {
                                                        style: "resultText",
                                                        text: "Visual Span : 순간적으로 제시되는 무의미한 글자들을 한 눈에 최대한 많이 기억해야 합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Visual Counting : 순간적으로 제시되는 점의 개수를 패턴화하여 세야 합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Trail Making Text(TMT) : 어지럽게 배치된 숫자와 문자들을 순서대로 빠르게 연결해야 합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Stroop Test : 제시되는 문장의 내용과 색깔을 비교하여 빠르게 판단해야 합니다.",
                                                    },
                                                ],
                                            },
                                        ],
                                        border: [false, false, false, false],
                                    },
                                ],
                            ],
                        },
                    },
                    {
                        margin: [0, 0, 0, 10],
                        table: {
                            widths: [240, "auto"],
                            heights: [160],
                            body: [
                                [
                                    {
                                        image: trackingChartSrc,
                                        alignment: "center",
                                        width: 240,
                                        height: 160,
                                        border: [true, true, true, true],
                                        borderColor: ["#aaa9bc", "#aaa9bc", "#aaa9bc", "#aaa9bc"],
                                    },
                                    // { text: "", border: [false, false, false, false] },
                                    {
                                        margin: [3, 0, 0, 0],
                                        stack: [
                                            { text: "Tracking Training", style: "resultTitle" },
                                            {
                                                text: "읽기와 시지각의 기본이 되는 안구운동의 제어와 통제, 지각 집중력을 향상시킵니다. 시선추적장치를 활용하며, 게임 형식으로 진행합니다.",
                                                style: "resultText",
                                                margin: [0, 0, 0, 3],
                                            },
                                            {
                                                ul: [
                                                    {
                                                        style: "resultText",
                                                        text: "Saccade Tracking : 상하좌우에 나타나는 점을 빠르고 정확하게 움직여 시선을 고정시켜야 합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Pursuit Tracking : 직선 또는 원운동 하는 점을 부드럽고 안정적으로 추적하며 보아야 합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Anti Saccade Tracking : 나타난 자극물을 빠르게 판단하여 시선을 보내거나 멈추어야 합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Sentence Tracking : 글을 순서대로 빠짐없이 읽어야만 시선에 따라 다음 부분이 보여집니다.",
                                                    },
                                                ],
                                            },
                                        ],
                                        border: [false, false, false, false],
                                    },
                                ],
                            ],
                        },
                    },
                    {
                        margin: [0, 0, 0, 10],
                        table: {
                            widths: [240, "auto"],
                            heights: [160],
                            body: [
                                [
                                    {
                                        image: exerciseChartSrc,
                                        alignment: "center",
                                        width: 240,
                                        height: 160,
                                        border: [true, true, true, true],
                                        borderColor: ["#aaa9bc", "#aaa9bc", "#aaa9bc", "#aaa9bc"],
                                    },
                                    // { text: "", border: [false, false, false, false] },
                                    {
                                        margin: [3, 0, 0, 0],
                                        stack: [
                                            { text: "Exercise Training", style: "resultTitle" },
                                            {
                                                text: "읽기 과정의 핵심 시선이동인 도약안구운동(saccade)을 빠르고 정확하게 훈련합니다. 시선추적장치를 활용합니다.",
                                                style: "resultText",
                                                margin: [0, 0, 0, 3],
                                            },
                                            {
                                                ul: [
                                                    {
                                                        style: "resultText",
                                                        text: "Horizontal Sweep : 수평방향으로 최대 폭의 시선이동을 훈련합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Vertical Sweep : 수직방향으로 최대 폭의 시선이동을 훈련합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Horizontal Jump : 읽기에 필요한 너비의 수평방향 시선이동을 훈련합니다.",
                                                    },
                                                    {
                                                        style: "resultText",
                                                        text: "Vertical Jump : 읽기에 필요한 너비의 수직방향 시선이동을 훈련합니다.",
                                                    },
                                                ],
                                            },
                                        ],
                                        border: [false, false, false, false],
                                    },
                                ],
                            ],
                        },
                    },
                ], false);
                return true;
            }
            catch (err) {
                console.log("err", err);
                return false;
            }
        };
        this.start = function () {
            return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
                var $report, delay, prevWidth, a, b, c, d;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            if (!exports.preloadDone) {
                                console.log("preloadDone is false");
                                return [2 /*return*/, resolve(false)];
                            }
                            $report = document === null || document === void 0 ? void 0 : document.querySelector("#trainingReport");
                            if (!$report) {
                                return [2 /*return*/, resolve(false)];
                            }
                            delay = function (d) { return new Promise(function (resolve) { return setTimeout(function () { return resolve(true); }, d); }); };
                            prevWidth = $report.style.width;
                            $report.style.width = "1024px";
                            document.body.style.overflow = "hidden";
                            return [4 /*yield*/, delay(1000)];
                        case 1:
                            _a.sent();
                            a = this.makeFirstPage();
                            b = this.makeSecondPage();
                            c = this.makeThirdPage();
                            d = this.makeFourthPage();
                            if (!a || !b || !c || !d) {
                                console.log(a, b, c, d);
                                resolve(false);
                                return [2 /*return*/];
                            }
                            if (!this.doc) {
                                console.log("doc type is falsy.");
                                resolve(false);
                                return [2 /*return*/];
                            }
                            this.pdf = pdfmake_1.default.createPdf(this.doc);
                            $report.style.width = prevWidth;
                            document.body.style.overflow = "unset";
                            resolve(true);
                            return [2 /*return*/];
                    }
                });
            }); });
        };
        this.download = function () {
            return new Promise(function (resolve, reject) {
                if (!_this.pdf) {
                    resolve(false);
                    return;
                }
                var filename = "\uD2B8\uB808\uC774\uB2DD \uC218\uD589 \uB9AC\uD3EC\uD2B8_".concat(_this.data.agencyName, "_").concat(_this.data.startdate, "-").concat(_this.data.enddate, "_").concat(_this.data.testeeNickname, ".pdf");
                _this.pdf.download(filename);
                resolve(true);
            });
        };
        this.pdf = null;
        this.doc = null;
        this.data = data;
        this.tier = tier;
        this.dayDueDate = dayDueDate;
        this.weekDueDate = weekDueDate;
        this.agencyLogo = agencyLogo;
    }
    return PDF;
}());
exports.default = PDF;
