import { drawLabelBackground } from './labelBackground';
export var drawLabel = function (context, data, settings, _a) {
    var _b, _c, _d, _e;
    var _f = _a === void 0 ? {} : _a, backgroundColor = _f.backgroundColor, borderColor = _f.borderColor;
    if (!data.label)
        return;
    var size = settings.labelSize, font = settings.labelFont, weight = settings.labelWeight, marginLeft = data.selected ? 6 : 2, lineHeight = size * 1.2;
    var PERMANENT_MARGIN_LEFT = 9;
    context.font = "".concat(weight, " ").concat(size, "px ").concat(font);
    var labelBackgroundPath = drawLabelBackground(context, data, settings, {
        backgroundColor: data.selected ? '#FFF' : backgroundColor,
        marginLeft: marginLeft,
        borderColor: borderColor,
        lineHeight: lineHeight
    });
    context.fillStyle = ((_b = settings.labelColor) === null || _b === void 0 ? void 0 : _b.attribute)
        ? data[settings.labelColor.attribute] || settings.labelColor.color || '#000'
        : settings.labelColor.color;
    var y = data.secondaryLabel ? data.y - size / (3 * 1.25) : data.y + size / 3;
    context.fillText(data.label, data.x + data.size + PERMANENT_MARGIN_LEFT + marginLeft, y);
    if (data.secondaryLabel) {
        context.fillStyle = ((_c = settings.secondaryLabelColor) === null || _c === void 0 ? void 0 : _c.attribute)
            ? data[settings.secondaryLabelColor.attribute] || ((_d = settings.secondaryLabelColor) === null || _d === void 0 ? void 0 : _d.color) || '#000'
            : (_e = settings.secondaryLabelColor) === null || _e === void 0 ? void 0 : _e.color;
        context.fillText(data.secondaryLabel, data.x + data.size + PERMANENT_MARGIN_LEFT + marginLeft, y + lineHeight);
    }
    return labelBackgroundPath;
};
