"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildBarStyle = buildBarStyle;
const color_library_wrappers_1 = require("../../../../../common/color_library_wrappers");
const common_1 = require("../../../../../utils/common");
const dimmed_colors_1 = require("../../../../../utils/themes/dimmed_colors");
const texture_1 = require("../../../utils/texture");
function buildBarStyle(ctx, imgCanvas, baseColor, themeRectStyle, themeRectBorderStyle, geometryStateStyle, sharedStyle, rect) {
    const isDimmed = geometryStateStyle === sharedStyle.unhighlighted;
    const fillVariant = (0, dimmed_colors_1.getDimmedColor)(isDimmed, themeRectStyle.dimmed, 'fill', themeRectStyle.fill);
    const hasDimmedFillColor = (0, dimmed_colors_1.hasDimmedColor)(isDimmed, themeRectStyle.dimmed, 'fill');
    const dimmedOpacity = isDimmed && 'opacity' in themeRectStyle.dimmed
        ? themeRectStyle.dimmed.opacity
        : hasDimmedFillColor
            ? 1
            : geometryStateStyle.opacity;
    const fillBaseColor = (0, common_1.getColorFromVariant)(baseColor, fillVariant);
    const textureOpacity = isDimmed && themeRectStyle.dimmed && 'texture' in themeRectStyle.dimmed && themeRectStyle.dimmed.texture
        ? themeRectStyle.dimmed.texture.opacity
        : geometryStateStyle.opacity;
    const texture = themeRectStyle.texture
        ? (0, texture_1.getTextureStyles)(ctx, imgCanvas, baseColor, textureOpacity, themeRectStyle.texture)
        : undefined;
    const fillColor = (0, color_library_wrappers_1.overrideOpacity)((0, color_library_wrappers_1.colorToRgba)(fillBaseColor), (opacity) => opacity * themeRectStyle.opacity * dimmedOpacity);
    const fill = {
        color: fillColor,
        texture,
    };
    const strokeColor = (0, color_library_wrappers_1.overrideOpacity)((0, color_library_wrappers_1.colorToRgba)((0, common_1.getColorFromVariant)(baseColor, themeRectBorderStyle.stroke)), (opacity) => opacity * geometryStateStyle.opacity * (themeRectBorderStyle.strokeOpacity ?? themeRectStyle.opacity));
    const stroke = {
        color: strokeColor,
        width: themeRectBorderStyle.visible && rect.height > themeRectBorderStyle.strokeWidth
            ? themeRectBorderStyle.strokeWidth
            : 0,
    };
    return { fill, stroke };
}
//# sourceMappingURL=bar.js.map