"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDivTextSize = void 0;
const array_1 = require("../array");
const getTextLines_1 = require("./getTextLines");
const getDivTextSize = (text, fontSize, maxLineLength) => {
    const lines = (0, getTextLines_1.getTextLines)(text, maxLineLength);
    if (!lines.length) {
        return { width: 0, height: fontSize };
    }
    const lastLine = (0, array_1.last)(lines);
    if (lastLine.trim() === '') {
        lines.splice(lines.length - 1, 1);
    }
    const newText = lines.join('');
    const lineCount = lines.length;
    let maxLineCharCount = Number.MIN_SAFE_INTEGER;
    let maxLineCharIndex = Number.MIN_SAFE_INTEGER;
    for (let i = 0; i < lines.length; i++) {
        const line = lines[i];
        const lineLength = line.trim().length;
        if (lineLength > maxLineCharCount) {
            maxLineCharIndex = i;
            maxLineCharCount = lineLength;
        }
    }
    const emptySpaceAround = newText.length - newText.trim().length;
    const isLastLine = maxLineCharIndex === lineCount - 1;
    const emptySpaceToAdd = isLastLine ? emptySpaceAround : 0;
    const width = ((maxLineCharCount + emptySpaceToAdd) * fontSize) / 2;
    const height = lineCount * fontSize;
    return { width, height };
};
exports.getDivTextSize = getDivTextSize;
//# sourceMappingURL=getDivTextSize.js.map