export class TextUtils {
    static setText(textElement, content, font, width, height, cursor = 'hand') {
        this.alignText(textElement, font.textAlign, width, height);
        textElement.setAttribute('cursor', cursor);
        textElement.setAttribute('alignment-baseline', 'central');
        textElement.setAttribute('font-family', font.fontFamily);
        textElement.setAttribute('font-size', font.fontSize + '');
        textElement.setAttribute('fill', font.color);
        if (font.isBold) {
            textElement.setAttribute('font-weight', 'bold');
        }
        else {
            textElement.removeAttribute('font-weight');
        }
        if (font.isItalic) {
            textElement.setAttribute('font-style', 'italic');
        }
        else {
            textElement.removeAttribute('font-style');
        }
        if (font.isUnderline) {
            textElement.setAttribute('text-decoration', 'underline');
        }
        else {
            textElement.removeAttribute('text-decoration');
        }
        textElement.textContent = content;
    }
    static alignText(textElement, align, width, height) {
        switch (align) {
            case 'right':
                textElement.setAttribute('text-anchor', 'end');
                textElement.setAttribute('transform', `translate(${width},${height / 2})`);
                break;
            case 'left':
                textElement.setAttribute('text-anchor', 'start');
                textElement.setAttribute('transform', `translate(0,${height / 2})`);
                break;
            default:
                textElement.setAttribute('text-anchor', 'middle');
                textElement.setAttribute('transform', `translate(${width / 2},${height / 2})`);
                break;
        }
    }
}
