'use strict';

var jsUtil_esm = require('../../../node_modules/@mj-studio/js-util/dist/js-util.esm.js');
var dimension = require('../../../design/dimension.js');
var palette = require('../../../design/palette.js');
var Chip = require('../Chip/Chip.js');
var Doc = require('../../util/Doc.js');
var TextUtil = require('../../util/TextUtil.js');

const FirstPageHeader = ({ pdfTemplate, ...props }) => {
    switch (pdfTemplate) {
        case 't1':
            return T1FirstPageHeader({ ...props });
        case 't2':
            return T2FirstPageHeader({ ...props });
        case 't3':
            return T3FirstPageHeader({ ...props });
        case 't4':
            return T4FirstPageHeader({ ...props });
        case 't5':
            return T5FirstPageHeader({ ...props });
        case 't6':
            return T6FirstPageHeader({ ...props });
        default:
            return undefined;
    }
};
const T1FirstPageHeader = ({ title, description, color, titleTag }) => async () => {
    if (!jsUtil_esm.is.nullOrUndefined(titleTag)) {
        Doc.Doc.font('bold')
            .get()
            .fontSize(12)
            .fillColor(palette.default.gray900)
            .text(title, 0, dimension.Dimension.paddingTop + TextUtil.TextUtil.getLineHeightApply(12), {
            align: 'center',
        });
        Doc.Doc.font('normal')
            .get()
            .fontSize(8)
            .fillColor(palette.default.gray500)
            .text(description, 0, dimension.Dimension.paddingTop + 18 + TextUtil.TextUtil.getLineHeightApply(8), {
            align: 'center',
        });
        await Doc.Doc.renderComponent(Chip.Chip({
            text: titleTag,
            transformOrigin: 'center',
            x: Doc.Doc.width / 2,
            y: 54,
            color,
            size: 'm',
            variant: 'filled',
        }));
    }
    else {
        Doc.Doc.font('bold')
            .get()
            .fontSize(12)
            .fillColor(palette.default.gray900)
            .text(title, 0, dimension.Dimension.paddingTop + 10 + TextUtil.TextUtil.getLineHeightApply(12), {
            align: 'center',
        });
        Doc.Doc.font('normal')
            .get()
            .fontSize(8)
            .fillColor(palette.default.gray500)
            .text(description, 0, dimension.Dimension.paddingTop + 10 + 18 + TextUtil.TextUtil.getLineHeightApply(8), {
            align: 'center',
        });
    }
};
const T2FirstPageHeader = ({ title, description, titleTag }) => async () => {
    Doc.Doc.font('normal')
        .get()
        .fontSize(8)
        .fillColor(palette.default.gray500)
        .text(title, 0, dimension.Dimension.paddingTop, { align: 'center' });
    Doc.Doc.font('bold')
        .get()
        .fontSize(12)
        .fillColor(palette.default.gray900)
        .text(description, 0, dimension.Dimension.paddingTop + 12, { align: 'center' });
    // 성명란
    const studentNameRect = {
        x: dimension.Dimension.paddingX + 158,
        y: dimension.Dimension.paddingTop + 12 + 18 + 8,
        width: 96,
        height: 20,
    };
    Doc.Doc.renderComponent((doc) => {
        doc
            .rect(studentNameRect.x, studentNameRect.y, studentNameRect.width, studentNameRect.height)
            .moveTo(studentNameRect.x + 30, studentNameRect.y)
            .lineTo(studentNameRect.x + 30, studentNameRect.y + 20)
            .lineWidth(0.5)
            .strokeColor(palette.default.gray900)
            .stroke();
    });
    Doc.Doc.font('normal')
        .get()
        .fontSize(8)
        .fillColor(palette.default.gray900)
        .text('성명', studentNameRect.x + 8, studentNameRect.y + 5);
    // 학번란
    const studentNumberRect = {
        x: dimension.Dimension.paddingX + 262,
        y: dimension.Dimension.paddingTop + 12 + 18 + 8,
        width: 127,
        height: 20,
    };
    Doc.Doc.renderComponent((doc) => {
        doc
            .rect(studentNumberRect.x, studentNumberRect.y, studentNumberRect.width, studentNumberRect.height)
            .moveTo(studentNumberRect.x + 30, studentNumberRect.y)
            .lineTo(studentNumberRect.x + 30, studentNumberRect.y + 20)
            .lineWidth(0.5)
            .strokeColor(palette.default.gray900)
            .stroke();
    });
    Doc.Doc.font('normal')
        .get()
        .fontSize(8)
        .fillColor(palette.default.gray900)
        .text('학번', studentNumberRect.x + 8, studentNumberRect.y + 5);
    if (!jsUtil_esm.is.nullOrUndefined(titleTag)) {
        // 학습지 태그
        await Doc.Doc.renderComponent(Chip.Chip({
            text: titleTag,
            transformOrigin: 'left',
            x: dimension.Dimension.paddingX,
            y: dimension.Dimension.paddingTop + 15,
            color: palette.default.gray900,
            size: 'l',
            variant: 'outlined',
        }));
    }
};
const T3FirstPageHeader = ({ title, description, color, titleTag }) => async () => {
    // 두 원이 겹쳐 있는 듯한 모양
    const shapeDonut = {
        x: dimension.Dimension.paddingX + 371,
        y: 0,
        radius: 109 / 2,
        strokeWidth: 40,
    };
    const shapeCircle = {
        x: dimension.Dimension.paddingX + 452,
        y: 0,
        radius: 149 / 2,
    };
    Doc.Doc.renderComponent((doc) => {
        doc
            .circle(shapeDonut.x, shapeDonut.y, shapeDonut.radius)
            .lineWidth(shapeDonut.strokeWidth)
            .strokeColor(color)
            .strokeOpacity(0.1)
            .stroke();
        doc.circle(shapeCircle.x, shapeCircle.y, shapeCircle.radius).fillOpacity(0.1).fill(color);
    });
    if (!jsUtil_esm.is.nullOrUndefined(titleTag)) {
        Doc.Doc.font('bold')
            .get()
            .fontSize(12)
            .fillColor(palette.default.gray900, 1)
            .text(title, dimension.Dimension.paddingX, dimension.Dimension.paddingTop + TextUtil.TextUtil.getLineHeightApply(12), {
            align: 'left',
        });
        Doc.Doc.font('normal')
            .get()
            .fontSize(8)
            .fillColor(palette.default.gray500, 1)
            .text(description, dimension.Dimension.paddingX, dimension.Dimension.paddingTop + 18 + TextUtil.TextUtil.getLineHeightApply(8), {
            align: 'left',
        });
        await Doc.Doc.renderComponent(Chip.Chip({
            text: titleTag,
            transformOrigin: 'left',
            x: dimension.Dimension.paddingX,
            y: dimension.Dimension.paddingTop + 34,
            color,
            size: 'm',
            variant: 'filled',
        }));
    }
    else {
        Doc.Doc.font('bold')
            .get()
            .fontSize(12)
            .fillColor(palette.default.gray900, 1)
            .text(title, dimension.Dimension.paddingX, dimension.Dimension.paddingTop + 10 + TextUtil.TextUtil.getLineHeightApply(12), {
            align: 'left',
        });
        Doc.Doc.font('normal')
            .get()
            .fontSize(8)
            .fillColor(palette.default.gray500, 1)
            .text(description, dimension.Dimension.paddingX, dimension.Dimension.paddingTop + 10 + 18 + TextUtil.TextUtil.getLineHeightApply(8), {
            align: 'left',
        });
    }
};
const T4FirstPageHeader = ({ title, description, color, titleTag }) => async () => {
    // 배경
    Doc.Doc.renderComponent((doc) => {
        doc.rect(0, 0, Doc.Doc.width, dimension.Dimension.headerHeight).fillColor(color, 0.1).fill();
        doc
            .roundedRect(dimension.Dimension.paddingX, 13, Doc.Doc.width - dimension.Dimension.paddingX * 2, 64, 999)
            .fillColor(palette.default.white, 1)
            .strokeColor(palette.default.gray900)
            .lineWidth(1)
            .fillAndStroke();
        doc
            .circle(dimension.Dimension.paddingX + 12 + 20, 25 + 20, 20)
            .fillColor(palette.default.gray900, 1)
            .fill();
        doc.image(`${__dirname}/../../../assets/image/shdw_logo.png`, 46, 35, {
            width: 20,
            height: 20,
        });
    });
    Doc.Doc.font('bold')
        .get()
        .fontSize(14)
        .fillColor(palette.default.gray900, 1)
        .text(description, 84, 27 + TextUtil.TextUtil.getLineHeightApply(14), { baseline: 'hanging' });
    Doc.Doc.font('normal')
        .get()
        .fontSize(10)
        .fillColor(palette.default.gray500, 1)
        .text(title, 84, 27 + 21 + TextUtil.TextUtil.getLineHeightApply(10), { baseline: 'hanging' });
    if (!jsUtil_esm.is.nullOrUndefined(titleTag)) {
        // 학습지 태그
        await Doc.Doc.renderComponent(Chip.Chip({
            text: titleTag,
            transformOrigin: 'right',
            x: Doc.Doc.width - 36,
            y: 37,
            color,
            size: 'm',
            variant: 'filled',
        }));
    }
};
const T5FirstPageHeader = ({ title, description, color, titleTag }) => async () => {
    // 배경
    Doc.Doc.renderComponent((doc) => {
        doc.rect(0, 0, Doc.Doc.width, 12).fillColor(color, 0.1).fill();
        doc.rect(dimension.Dimension.paddingX, 0, 48, 82).fillColor(color, 1).fill();
        const text = 'SHDW';
        const textWidth = doc.fontSize(8).widthOfString(text, { align: 'center' });
        Doc.Doc.font('normal');
        doc
            .fillColor(palette.default.white, 1)
            .text(text, dimension.Dimension.paddingX + 24 - textWidth / 2, 30 + TextUtil.TextUtil.getLineHeightApply(8), {
            baseline: 'hanging',
        });
        doc.image(`${__dirname}/../../../assets/image/shdw_logo.png`, 38, 44, {
            width: 20,
            height: 20,
        });
    });
    Doc.Doc.font('bold')
        .get()
        .fontSize(14)
        .fillColor(palette.default.gray900, 1)
        .text(description, dimension.Dimension.paddingX + 48 + 24, 30 + TextUtil.TextUtil.getLineHeightApply(14), {
        baseline: 'hanging',
    });
    Doc.Doc.font('normal')
        .get()
        .fontSize(10)
        .fillColor(palette.default.gray500, 1)
        .text(title, dimension.Dimension.paddingX + 48 + 24, 30 + 21 + 2 + TextUtil.TextUtil.getLineHeightApply(10), {
        baseline: 'hanging',
    });
    if (!jsUtil_esm.is.nullOrUndefined(titleTag)) {
        // 학습지 태그
        await Doc.Doc.renderComponent(Chip.Chip({
            text: titleTag,
            transformOrigin: 'right',
            x: Doc.Doc.width - dimension.Dimension.paddingX,
            y: 39,
            color,
            size: 'l',
            variant: 'outlined',
        }));
    }
};
const T6FirstPageHeader = ({ title, description, color, titleTag }) => async () => {
    // 배경
    Doc.Doc.renderComponent((doc) => {
        doc.rect(0, 0, Doc.Doc.width, dimension.Dimension.headerHeight).fillColor(color, 0.1).fill();
    });
    Doc.Doc.font('bold')
        .get()
        .fontSize(14)
        .fillColor(palette.default.gray900, 1)
        .text(description, dimension.Dimension.paddingX, 27 + TextUtil.TextUtil.getLineHeightApply(14), {
        baseline: 'hanging',
    });
    Doc.Doc.font('normal')
        .get()
        .fontSize(10)
        .fillColor(palette.default.gray500, 1)
        .text(title, dimension.Dimension.paddingX, 27 + 21 + TextUtil.TextUtil.getLineHeightApply(10), {
        baseline: 'hanging',
    });
    if (!jsUtil_esm.is.nullOrUndefined(titleTag)) {
        // 학습지 태그
        await Doc.Doc.renderComponent(Chip.Chip({
            text: titleTag,
            transformOrigin: 'right',
            x: Doc.Doc.width - dimension.Dimension.paddingX,
            y: 35,
            color,
            size: 'l',
            variant: 'outlined',
        }));
    }
};

exports.FirstPageHeader = FirstPageHeader;
