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

local TLA = ns.TooltipLineAccessor

---@class BaseTooltipTranslator : BaseTranslator
---@field tooltipDataTypes Enum.TooltipDataType[]
local translator = setmetatable({}, { __index = ns.BaseTranslator })
ns.BaseTooltipTranslator = translator

function translator:Init()
    for _, dataType in ipairs(self.tooltipDataTypes) do
        TooltipDataProcessor.AddTooltipPostCall(dataType, function(tooltip, tooltipData)
            self:TooltipCallback(tooltip, tooltipData)
        end)
    end
end

--- Parse the tooltip and tooltip data; to be overridden by custom logic in subclasses
---@protected
function translator:ParseTooltip(tooltip, tooltipData)
end

--- Translate the tooltip info; to be overridden by custom logic in subclasses
---@protected
function translator:TranslateTooltipInfo(tooltipInfo)
end

---@protected
function translator:TooltipCallback(tooltip, tooltipData)
    if issecrettable(tooltipData) then return end

    self._postCallLineCount = tooltip:NumLines()

    local tooltipInfo = self:ParseTooltip(tooltip, tooltipData)
    if (not tooltipInfo) then return end

    local translatedTooltipLines = self:TranslateTooltipInfo(tooltipInfo)
    if (not translatedTooltipLines) then return end

    for _, entry in ipairs(translatedTooltipLines) do
        if entry.right then
            TLA.SetRightText(tooltip, entry.line, entry.value)
        else
            TLA.SetLeftText(tooltip, entry.line, entry.value)
        end
    end
end
