'use strict';

var dimension = require('../../../design/dimension.js');
var palette = require('../../../design/palette.js');
var Doc = require('../../util/Doc.js');
var TextUtil = require('../../util/TextUtil.js');

const OtherPageHeader = ({ pdfTemplate, ...props }) => {
    switch (pdfTemplate) {
        case 't1':
            return T1OtherPageHeader({ ...props });
        case 't2':
            return T2OtherPageHeader({ ...props });
        case 't3':
            return T3OtherPageHeader({ ...props });
        case 't4':
            return T4OtherPageHeader({ ...props });
        case 't5':
            return T5OtherPageHeader({ ...props });
        case 't6':
            return T6OtherPageHeader({ ...props });
        default:
            return undefined;
    }
};
const T1OtherPageHeader = ({ title, description }) => async () => {
    Doc.Doc.font('bold')
        .get()
        .fontSize(12)
        .fillColor(palette.default.gray900)
        .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)
        .text(description, dimension.Dimension.paddingX, dimension.Dimension.paddingTop + 10 + 18 + TextUtil.TextUtil.getLineHeightApply(8), {
        align: 'left',
    });
};
const T2OtherPageHeader = ({ title, description }) => async () => {
    Doc.Doc.font('normal')
        .get()
        .fontSize(8)
        .fillColor(palette.default.gray500)
        .text(title, 0, dimension.Dimension.paddingTop + 14, { align: 'center' });
    Doc.Doc.font('bold')
        .get()
        .fontSize(12)
        .fillColor(palette.default.gray900)
        .text(description, 0, dimension.Dimension.paddingTop + 14 + 12, { align: 'center' });
};
const T3OtherPageHeader = ({ title, description, color }) => 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);
    });
    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 T4OtherPageHeader = ({ title, description, color }) => 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.Doc.font('bold')
        .get()
        .fontSize(14)
        .fillColor(palette.default.gray900, 1)
        .text(description, 56, 27 + TextUtil.TextUtil.getLineHeightApply(14), { baseline: 'hanging' });
    Doc.Doc.font('normal')
        .get()
        .fontSize(10)
        .fillColor(palette.default.gray500, 1)
        .text(title, 56, 27 + 21 + TextUtil.TextUtil.getLineHeightApply(10), { baseline: 'hanging' });
};
const T5OtherPageHeader = ({ title, description, color }) => async () => {
    // 배경
    Doc.Doc.renderComponent((doc) => {
        doc.rect(0, 0, Doc.Doc.width, 12).fillColor(color, 0.1).fill();
    });
    Doc.Doc.font('bold')
        .get()
        .fontSize(14)
        .fillColor(palette.default.gray900, 1)
        .text(description, dimension.Dimension.paddingX, 30 + TextUtil.TextUtil.getLineHeightApply(14), {
        baseline: 'hanging',
    });
    Doc.Doc.font('normal')
        .get()
        .fontSize(10)
        .fillColor(palette.default.gray500, 1)
        .text(title, dimension.Dimension.paddingX, 30 + 21 + 2 + TextUtil.TextUtil.getLineHeightApply(10), {
        baseline: 'hanging',
    });
};
const T6OtherPageHeader = ({ title, description, color }) => 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',
    });
};

exports.OtherPageHeader = OtherPageHeader;
