local _, namespace = ...

namespace.WildThingsUI = {
	VERSION = 1
}

local WTUI = namespace.WildThingsUI

-- Tooltip
CreateFrame("GameTooltip", "WildThingsUITooltip", UIParent, "GameTooltipTemplate")

WTUI.Tooltip = _G["WildThingsUITooltip"]
WTUI.Tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")

WTUI.Tooltip:AddFontStrings(
	WTUI.Tooltip:CreateFontString("$parentTextLeft1", nil, "GameTooltipText"),
	WTUI.Tooltip:CreateFontString("$parentTextRight1", nil, "GameTooltipText")
)

if WOW_PROJECT_ID == 1 then -- Retail
    WTUI.Tooltip.TextLeft1:SetFontObject(WildThingsFont13)
    WTUI.Tooltip.TextRight1:SetFontObject(WildThingsFont13)
end

-- Compatibility between retail/classic
function WTUI.GetSpellInfo(spell)
	if C_Spell and C_Spell.GetSpellInfo then
		return C_Spell.GetSpellInfo(spell)
	else
		local name, rank, iconID, castTime, minRange, maxRange, spellID, originalIconID = GetSpellInfo(spell)

		if name then
			return {
				name = name,
				iconID = iconID,
				originalIconID = originalIconID,
				castTime = castTime,
				minRange = minRange,
				maxRange = maxRange,
				spellID = spellID,
				rank = rank
			}
		end
	end
end

-- savedTable is a table in the addon's SavedVariables where WildThingsUI can save some of its persistent data
-- This function should be called before any of the other WildThingsUI functions are
function WTUI:Initialize(savedTable)
	if not savedTable.WildThingsUI then savedTable.WildThingsUI = {} end
    if not savedTable.WildThingsUI.spellDescriptionCache then savedTable.WildThingsUI.spellDescriptionCache = {} end -- Used in SpellIcon widget
	if not savedTable.WildThingsUI.frameSettings then savedTable.WildThingsUI.frameSettings = {} end

    WTUI.spellDescriptionCache = savedTable.WildThingsUI.spellDescriptionCache
	WTUI.frameSettings = savedTable.WildThingsUI.frameSettings
end
