
local L = LibStub("AceLocale-3.0"):GetLocale("MNT2", false)

local SPEED_SLOW = {
	['ground'] = 60,
	['flying'] = 60,
}
local SPEED_MEDIUM = {
	['ground'] = 100,
	['flying'] = 280,
}
local SPEED_FAST = {
	['flying'] = 310,
}

local mountBypass = {
	[75973] = {'flying', 60, 'flying', 280}, -- X-53 Touring Rocket
	[54729] = {'flying', 60, 'flying', 280}, -- Winged Steed of the Ebon Blade
	[58983] = {'ground', 60, 'ground', 100}, -- Big Blizzard Bear
	[48025] = {'ground', 60, 'ground', 100, 'flying', 60, 'flying', 280}, -- Headless Horseman's Mount
	[75614] = {'ground', 60, 'ground', 100, 'flying', 60, 'flying', 280}, -- Celestial Steed
	[30174] = {'ground', 0}, -- Turtle Mount TCG
	[64731] = {'ground', 0, 'water', 60}, -- Turtle Mount Fishing
	[25953] = {'aq', 100}, -- Blue Qiraji Battle Tank
	[26056] = {'aq', 100}, -- Green Qiraji Battle Tank
	[26054] = {'aq', 100}, -- Red Qiraji Battle Tank
	[26055] = {'aq', 100}, -- Yellow Qiraji Battle Tank
	[60024] = {'flying', 310}, --Violet Proto-Drake
	[579] = {'ground', 100}, --Red Wolf
}

local Scanner = CreateFrame("GameTooltip", "MNT_ScannerTooltip", nil, "GameTooltipTemplate")
Scanner:SetOwner(UIParent, "ANCHOR_NONE")
for i = 1, 30 do
	Scanner[i] = _G["MNT_ScannerTooltipTextLeft"..i]
	if not Scanner[i] then
		Scanner[i] = Scanner:CreateFontString()
		Scanner:AddFontStrings(Scanner[i], Scanner:CreateFontString())
	end
end

local mountscancache = {}
setmetatable(mountscancache, {__mode = "kv"}) -- can GC the cache if it wants to no need for it unless you make frequent calls with the same spellid to this function
function MNT2:GetMountType(spellid)
	if mountscancache[spellid] then
		return unpack(mountscancache[spellid])
	elseif( mountBypass[spellid] ) then
		return unpack(mountBypass[spellid])
	else
		local mountpack = {} -- odd numbers are mount types evens are speeds multible once mean scaling mounts
		Scanner:ClearLines()
		Scanner:SetHyperlink("spell:"..spellid)
		local _, _, Outland, Northrend = GetMapContinents()
		local numLines = Scanner:NumLines()
		local text = ""
		for i=1,numLines do
			text = string.format("%s %s", text, Scanner[i]:GetText())
		end
		if text:match(Outland) or text:match(Northrend) then
			mountpack[1] = 'flying'
		else
			mountpack[1] = 'ground'
		end
		if text:match(L.SpeedFast) then
			mountpack[2] = SPEED_FAST[mountpack[1]]
		elseif text:match(L.SpeedMedium) then
			mountpack[2] = SPEED_MEDIUM[mountpack[1]]
		else
			mountpack[2] = SPEED_SLOW[mountpack[1]]
		end
		mountscancache[spellid] = mountpack
		return unpack(mountpack)
	end
end
