"use strict";
/**
* Color utility functions for BFUI
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.adjustBrightness = adjustBrightness;
exports.hexToRgba = hexToRgba;
exports.isLightColor = isLightColor;
exports.getContrastColor = getContrastColor;
/**
* Adjusts the brightness of a hex color
* @param hex The hex color to adjust
* @param percent The percentage to adjust by (positive lightens, negative darkens)
* @returns The adjusted hex color
*/
function adjustBrightness(hex, percent) {
    // Convert hex to RGB
    let r = parseInt(hex.substring(1, 3), 16);
    let g = parseInt(hex.substring(3, 5), 16);
    let b = parseInt(hex.substring(5, 7), 16);
    // Adjust brightness
    r = Math.max(0, Math.min(255, r + (r * percent) / 100));
    g = Math.max(0, Math.min(255, g + (g * percent) / 100));
    b = Math.max(0, Math.min(255, b + (b * percent) / 100));
    // Convert back to hex
    return `#${Math.round(r).toString(16).padStart(2, '0')}${Math.round(g)
        .toString(16)
        .padStart(2, "0')}${Math.round(b).toString(16).padStart(2, '0")}`;
}
/**
* Converts a hex color to RGBA format
* @param hex The hex color to convert
* @param alpha The alpha value (0 - 1)
* @returns The RGBA color string
*/
function hexToRgba(hex, alpha = 1) {
    // Convert hex to RGB
    const r = parseInt(hex.substring(1, 3), 16);
    const g = parseInt(hex.substring(3, 5), 16);
    const b = parseInt(hex.substring(5, 7), 16);
    return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
/**
* Determines if a color is light or dark
* @param hex The hex color to check
* @returns True if the color is light, false if it's dark
*/
function isLightColor(hex) {
    // Convert hex to RGB
    const r = parseInt(hex.substring(1, 3), 16);
    const g = parseInt(hex.substring(3, 5), 16);
    const b = parseInt(hex.substring(5, 7), 16);
    // Calculate perceived brightness using the sRGB color space
    // See: https://www.w3.org / TR / AERT / #color - contrast
    const brightness = (r * 299 + g * 587 + b * 114) / 1000;
    return brightness > 128;
}
/**
* Returns a contrasting color (black or white) based on the input color
* @param hex The hex color to get a contrast for
* @returns White or black, whichever provides better contrast
*/
function getContrastColor(hex) {
    // Return black for light colors, white otherwise
    return isLightColor(hex) ? '#000000' : '#FFFFFF';
}
//# sourceMappingURL=colorUtils.js.map