"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.genWelcomeBanner = genWelcomeBanner;
const node_path_1 = __importDefault(require("node:path"));
const canvas_1 = require("@napi-rs/canvas");
const welcome_1 = require("../renderers/welcome");
canvas_1.GlobalFonts.registerFromPath(`${node_path_1.default.join(__dirname, '..', '..', 'public', 'fonts')}/HelveticaBold.ttf`, 'Helvetica Bold');
canvas_1.GlobalFonts.registerFromPath(`${node_path_1.default.join(__dirname, '..', '..', 'public', 'fonts')}/Helvetica.ttf`, 'Helvetica');
async function genWelcomeBanner(data, options) {
    const { assets } = data;
    const width = options?.customWidth ?? 1024;
    const height = options?.customHeight ?? 500;
    const canvas = (0, canvas_1.createCanvas)(width, height);
    const ctx = canvas.getContext('2d');
    const userAvatar = `${assets?.avatarURL ?? assets?.defaultAvatarURL}?size=512`;
    const backgroundImage = options?.customBackground ?? assets?.bannerURL ?? undefined;
    const cardBase = await (0, welcome_1.genWelcomeBase)(options, backgroundImage);
    ctx.drawImage(cardBase, 0, 0);
    const hasFrame = !options?.removeAvatarFrame && !!data?.decoration?.avatarFrame;
    const cardAvatar = await (0, welcome_1.genWelcomeAvatar)(userAvatar, options, hasFrame);
    ctx.drawImage(cardAvatar, 0, 0);
    if (hasFrame && data.decoration?.avatarFrame) {
        const avatarFrame = await (0, welcome_1.genWelcomeAvatarFrame)(data.decoration.avatarFrame, options);
        ctx.drawImage(avatarFrame, 0, 0);
    }
    const username = options?.customUsername ??
        data.global_name ??
        data.username ??
        'Unknown User';
    const cardText = (0, welcome_1.genWelcomeText)(username, options);
    ctx.drawImage(cardText, 0, 0);
    return canvas.toBuffer('image/png');
}
//# sourceMappingURL=welcome.js.map