--- @class WowUkrainizerInternals
local ns = select(2, ...);

---Utility module for manipulating FontString objects.
---
---@class FontStringUtil
local internal = {}
ns.FontStringUtil = internal

--- Safely get text from a FontString, returning nil if the value is a secret (WoW 12.0+).
---@param fontString FontString
---@return string|nil
function internal.SafeGetText(fontString)
    if not fontString then return nil end
    local text = fontString:GetText()
    if text ~= nil and issecretvalue(text) then return nil end
    return text
end

--- Set text of a font string and maintain its original text color.
---
---@param fontString FontString @The font string to set text for.
---@param value string @The text value to set.
function internal.SetText(fontString, value)
    if (not fontString) then return end

    local r, g, b = fontString:GetTextColor()

    fontString:SetText(value)
    fontString:SetTextColor(r, g, b)
end

--- This function updates the text of a given UI font string element using a provided translation function.
--- It takes a font string object and a translation function as parameters, then sets the font string's
--- text to the translated version of its current text.
---
--- @param fontStringObject FontString @The UI font string object to be updated
--- @param translationFunc function @The function used for translation
function internal.UpdateTextWithTranslation(fontStringObject, translationFunc)
    local text = internal.SafeGetText(fontStringObject)
    if not text then return end
    fontStringObject:SetText(translationFunc(text))
end
