--[[
    Commander 3.0 - Color Utilities

    Centralized theme color helpers used throughout the addon.
    Eliminates duplicated GetThemeColor/Colorize functions.
]]

local ADDON_NAME, C3 = ...

local Colors = {}

--- Get a theme color by key
---@param key string Theme color key (e.g., "accent.success", "status.dim")
---@return string|nil hex Hex color string without # (e.g., "A3BE8C") or nil
function Colors.GetColor(key)
    local theme = C3.UI and C3.UI.Theme
    return theme and theme:GetColor(key) or nil
end

--- Wrap text in WoW color escape codes using a theme color
---@param text string Text to colorize
---@param colorKey string Theme color key
---@return string coloredText Text wrapped in |cFF...|r codes, or original text if color not found
function Colors.Colorize(text, colorKey)
    local hex = Colors.GetColor(colorKey)
    if hex then
        return string.format("|cFF%s%s|r", hex, text)
    end
    return text
end

--- Wrap text in WoW color escape codes using a raw hex value
---@param text string Text to colorize
---@param hex string Hex color string (e.g., "FF0000" for red)
---@return string coloredText Text wrapped in |cFF...|r codes
function Colors.ColorizeHex(text, hex)
    return string.format("|cFF%s%s|r", hex, text)
end

-- Convenience aliases
Colors.Get = Colors.GetColor
Colors.C = Colors.Colorize

C3.Colors = Colors
return Colors
