local ns = _G.WoWTranslate_UK_NS

local translator = setmetatable({}, { __index = ns.BaseTooltipTranslator })

function translator:IsEnabled()
    return true
end

-- Spell-specific setter methods not always covered by TooltipDataProcessor
-- (e.g. SetAction for action bars hits before data resolves, SetTraitEntry
-- for the talent tree editor). Item setters live in ItemTooltipTranslator.
local SPELL_SETTER_METHODS = {
    "SetSpellByID",
    "SetSpellBookItem",
    "SetAction",
    "SetOwnedItemByID",
    "SetTraitEntry",
    "SetPvpTalent",
    "SetSpecialization",
}

function translator:Init()
    -- Primary: modern 10.0.2+ API used in 12.0.5. This already fires for
    -- every spell tooltip regardless of which setter was used.
    if TooltipDataProcessor and Enum and Enum.TooltipDataType and Enum.TooltipDataType.Spell then
        TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Spell, function(tooltip)
            if ns.TranslateTooltipLines then ns.TranslateTooltipLines(tooltip) end
        end)
    end

    -- Fallback: setter hooks for edge cases where TooltipDataProcessor does
    -- not resolve in time (action buttons, lazy talent tooltips).
    for _, method in ipairs(SPELL_SETTER_METHODS) do
        pcall(hooksecurefunc, GameTooltip, method, function(self)
            C_Timer.After(0, function()
                if ns.TranslateTooltipLines then ns.TranslateTooltipLines(self) end
            end)
        end)
    end
end

ns.TranslationsManager:Add(translator)
