local addonName, ns = ...

------------------------------------------------------------
-- Colour theme (matches the Housing Herald website: dark
-- navy surfaces, antique-gold text).
--
-- Tokens are ColorMixin objects, so call sites may use either
-- :GetRGBA() or .r/.g/.b access. Where a surface needs a
-- different alpha (e.g. popups at 0.97), pass it explicitly.
------------------------------------------------------------

ns.Theme = {
    BG          = CreateColor(0.039, 0.047, 0.114, 0.92), -- #0A0C1D deep navy
    PANEL       = CreateColor(0.094, 0.106, 0.188, 1),    -- #181B30 lighter navy
    BORDER      = CreateColor(0.541, 0.451, 0.227, 0.8),  -- #8A733A muted gold
    HEADING     = CreateColor(0.851, 0.725, 0.361, 1),    -- #D9B95C antique gold
    LABEL       = CreateColor(0.702, 0.6, 0.302, 1),      -- #B3994D dim gold
    TEXT_MUTED  = CreateColor(0.6, 0.6, 0.6, 1),          -- #999999 inactive text
    SELECTED    = CreateColor(0.165, 0.208, 0.376, 0.8),  -- #2A3560 selected row
    HOVER       = CreateColor(0.137, 0.169, 0.302, 0.4),  -- #232B4D hovered row
    BUTTON_BG         = CreateColor(0.125, 0.106, 0.098, 1), -- #201B19 button fill
    BUTTON_HOVER_BG   = CreateColor(0.580, 0.431, 0.043, 1), -- #946E0B hovered button fill
    BUTTON_HOVER_TEXT = CreateColor(1, 1, 1, 1),             -- #FFFFFF hovered button text
    CHAT_PREFIX = "|cFFD9B95CHousing Herald:|r ",
}

-- Wrap `text` in the WoW color escape for `color` (|cffRRGGBB…|r), computing
-- the hex from the color's .r/.g/.b. Used for gold headings in rich-text views.
function ns.Colorize(color, text)
    local hex = string.format("ff%02x%02x%02x",
        math.floor(color.r * 255 + 0.5),
        math.floor(color.g * 255 + 0.5),
        math.floor(color.b * 255 + 0.5))
    return "|c" .. hex .. text .. "|r"
end

-- Convert a "#RRGGBB" (or bare "RRGGBB") hex string to r, g, b floats.
-- Returns nil for anything malformed so call sites can fall back to a
-- default colour. Used for dye swatches.
function ns.HexToRGB(hex)
    if type(hex) ~= "string" then return nil end
    local r, g, b = hex:match("^#?(%x%x)(%x%x)(%x%x)$")
    if not r then return nil end
    return tonumber(r, 16) / 255, tonumber(g, 16) / 255, tonumber(b, 16) / 255
end
