-- ************************************************************************
-- **        ██████  ██████   █████  ██    ██ ███████ ███    ██          **
-- **        ██   ██ ██   ██ ██   ██ ██    ██ ██      ████   ██          **
-- **        ██████  ██████  ███████ ██    ██ █████   ██ ██  ██          **
-- **        ██   ██ ██   ██ ██   ██  ██  ██  ██      ██  ██ ██          **
-- **        ██████  ██   ██ ██   ██   ████   ███████ ██   ████          **
-- ************************************************************************
-- ** All rights reserved. This content is protected by © Copyright law. **
-- ************************************************************************

local function findBoostOption(skillName)
    for option, value in pairs(SandboxVars.DressForSuccess) do
        if type(option) == "string" and option:find("Boost") and option:find(skillName) then
            return value
        end
    end

    for option, value in pairs(SandboxVars.DressForSuccess2) do
        if type(option) == "string" and option:find("Boost") and option:find(skillName) then
            return value
        end
    end

    return nil
end

local function findMultiplierOption(skillName)
    for option, _ in pairs(SandboxVars.DressForSuccess) do
        if type(option) == "string" and option:find("Multiplier") and option:find(skillName) then
            return SandboxVars.DressForSuccess[option]
        end
    end

    for option, _ in pairs(SandboxVars.DressForSuccess2) do
        if type(option) == "string" and option:find("Multiplier") and option:find(skillName) then
            return SandboxVars.DressForSuccess2[option]
        end
    end

    return nil
end

local function onInitGlobalModData()
    if not DressForSuccess.ItemList then return end

    for _, item in ipairs(DressForSuccess.ItemList) do
        local baseItem = ScriptManager.instance:getItem(item.itemType)
        if baseItem and item.itemSkills then

            local itemSkillFormatted = item.itemSkills[1]:gsub(" ", "")
            if findBoostOption(itemSkillFormatted) == true then

                local tooltipText = getText("Tooltip_SkillBooster")
                local itemSkill = item.itemSkills[1]
                if itemSkill == "First Aid" then itemSkill = "Doctor" end

                local multiplier = findMultiplierOption(itemSkillFormatted) or "ERR"
                local skillText = getText("IGUI_perks_" .. itemSkill)

                tooltipText = tooltipText:gsub("SKILL", skillText)
                tooltipText = tooltipText:gsub("X", multiplier * 100)
                baseItem:DoParam("Tooltip = " .. tooltipText)
            end
        end
    end
end

Events.OnInitGlobalModData.Add(onInitGlobalModData)