local addonName, addon = ...

addon.DM = addon.DM or {}; local DM = addon.DM

--[[if GetLocale() == "enUS" then
	-- read ui map id list from HDB
	local HBD = LibStub("HereBeDragons-2.0")
	DM.mapIDs = {}
	DM.zoneNames = {}
	for i, id in ipairs(HBD:GetAllMapIDs()) do
		DM.mapIDs[HBD:GetLocalizedMap(id)] = id
		DM.zoneNames[id] = HBD:GetLocalizedMap(id)
	end
else ]]

if select(4, GetBuildInfo()) >= 40000 then
	DM.zoneNames = {
		"Durotar", -- 1
		"Burning Blade Coven",
		"Tiragarde Keep",
		"Tiragarde Keep",
		"Skull Rock",
		"Dustwind Cave",
		"Mulgore",
		"Palemane Rock",
		"The Venture Co. Mine",
		"The Barrens",
		"Wailing Caverns",
		"Kalimdor",
		"Eastern Kingdoms",
		"Arathi Highlands",
		"Badlands",
		"Uldaman",
		"Blasted Lands",
		"Tirisfal Glades",
		"Scarlet Monastery Entrance",
		nil,
		"Silverpine Forest",
		"Western Plaguelands",
		"Eastern Plaguelands",
		nil,
		"Hillsbrad Foothills",
		"The Hinterlands",
		"Dun Morogh",
		"Coldridge Pass",
		"The Grizzled Den",
		"New Tinkertown",
		"Gol'Bolar Quarry",
		"Searing Gorge",
		"Blackrock Mountain",
		"Blackrock Mountain",
		"Blackrock Mountain",
		"Burning Steppes",
		"Elwynn Forest",
		"Fargodeep Mine",
		"Fargodeep Mine",
		"Jasperlode Mine",
		nil,
		"Deadwind Pass",
		nil,
		nil,
		nil,
		nil,
		"Duskwood",
		"Loch Modan",
		"Redridge Mountains",
		"Northern Stranglethorn", -- 50
		"Swamp of Sorrows",
		"Westfall",
		"Gold Coast Quarry",
		"Jangolode Mine",
		"The Deadmines",
		"Wetlands",
		"Teldrassil",
		"Shadowthread Cave",
		"Fel Rock",
		"Ban'ethil Barrow Den",
		"Ban'ethil Barrow Den",
		"Darkshore",
		"Ashenvale",
		"Thousand Needles",
		"Stonetalon Mountains",
		"Desolace",
		"Maraudon",
		"Maraudon",
		"Feralas",
		"Dustwallow Marsh",
		"Tanaris",
		"The Noxious Lair",
		"The Gaping Chasm",
		"Caverns of Time",
		"Caverns of Time",
		"Azshara",
		"Felwood",
		"Un'Goro Crater",
		"The Slithering Scar",
		"Moonglade",
		"Silithus",
		"Twilight's Run",
		"Winterspring",
		"Stormwind City",
		"Orgrimmar",
		"Orgrimmar",
		"Ironforge",
		"Thunder Bluff",
		"Darnassus",
		nil,
		"Alterac Valley",
		"Warsong Gulch",
		"Arathi Basin",
		"Eversong Woods",
		"Ghostlands",
		"Amani Catacombs",
		"Azuremyst Isle",
		"Tides' Hollow",
		"Stillpine Hold",
		"Hellfire Peninsula", -- 100
		nil,
		"Zangarmarsh",
		"The Exodar",
		"Shadowmoon Valley",
		"Blade's Edge Mountains",
		"Bloodmyst Isle",
		"Nagrand",
		"Terokkar Forest",
		"Netherstorm",
		"Silvermoon City",
		"Shattrath City",
		"Eye of the Storm",
		"Northrend",
		"Borean Tundra",
		"Dragonblight",
		"Grizzly Hills",
		"Howling Fjord",
		"Icecrown",
		"Sholazar Basin",
		"The Storm Peaks",
		"Zul'Drak",
		"Isle of Quel'Danas",
		"Wintergrasp",
		"Plaguelands: The Scarlet Enclave",
		"Dalaran",
		"Dalaran",
		"Crystalsong Forest",
		"Strand of the Ancients",
		"The Nexus",
		"The Culling of Stratholme",
		"The Culling of Stratholme",
		"Ahn'kahet: The Old Kingdom",
		"Utgarde Keep",
		"Utgarde Keep",
		"Utgarde Keep",
		"Utgarde Pinnacle",
		"Utgarde Pinnacle",
		"Halls of Lightning",
		"Halls of Lightning",
		"Halls of Stone",
		"The Eye of Eternity",
		"The Oculus",
		"The Oculus",
		"The Oculus",
		"The Oculus",
		"The Oculus",
		"Ulduar",
		"Ulduar",
		"Ulduar",
		"Ulduar", -- 150
		"Ulduar",
		"Ulduar",
		"Gundrak",
		"Gundrak",
		"The Obsidian Sanctum",
		"Vault of Archavon",
		"Azjol-Nerub",
		"Azjol-Nerub",
		"Azjol-Nerub",
		"Drak'Tharon Keep",
		"Drak'Tharon Keep",
		"Naxxramas",
		"Naxxramas",
		"Naxxramas",
		"Naxxramas",
		"Naxxramas",
		"Naxxramas",
		"The Violet Hold",
		"Isle of Conquest",
		"Hrothgar's Landing",
		"Trial of the Champion",
		"Trial of the Crusader",
		"Trial of the Crusader",
		"The Lost Isles",
		"Kaja'mite Cavern",
		"Volcanoth's Lair",
		"Gallywix Labor Mine",
		"Gallywix Labor Mine",
		"Gilneas",
		"Emberstone Mine",
		"Greymane Manor",
		"Greymane Manor",
		"The Forge of Souls",
		"Pit of Saron",
		"Halls of Reflection",
		"Icecrown Citadel",
		"Icecrown Citadel",
		"Icecrown Citadel",
		"Icecrown Citadel",
		"Icecrown Citadel",
		"Icecrown Citadel",
		"Icecrown Citadel",
		"Icecrown Citadel",
		"Kezan",
		"Kaja'mine",
		"Kaja'mine",
		"Kaja'mine",
		"Mount Hyjal",
		"Southern Barrens",
		"The Ruby Sanctum", -- 200
		"Kelp'thar Forest",
		"Gilneas City",
		"Vashj'ir",
		"Abyssal Depths",
		"Shimmering Expanse",
		"Twin Peaks",
		"Deepholm",
		nil,
		nil,
		"The Cape of Stranglethorn",
		nil,
		nil,
		"Ragefire Chasm",
		nil,
		nil,
		nil,
		"Ruins of Gilneas",
		"Ruins of Gilneas City",
		"Zul'Farrak",
		"The Temple of Atal'Hakkar",
		"Blackfathom Deeps",
		"Blackfathom Deeps",
		"Blackfathom Deeps",
		"Stranglethorn Vale",
		"The Stockade",
		"Gnomeregan",
		"Gnomeregan",
		"Gnomeregan",
		"Gnomeregan",
		"Uldaman",
		"Uldaman",
		"Molten Core",
		"Zul'Gurub",
		"Dire Maul",
		"Dire Maul",
		"Dire Maul",
		"Dire Maul",
		"Dire Maul",
		"Dire Maul",
		"Dire Maul",
		"Twilight Highlands",
		"Blackrock Depths",
		"Blackrock Depths",
		"Tol Barad",
		"Tol Barad Peninsula",
		"The Shattered Halls",
		"Ruins of Ahn'Qiraj",
		"Onyxia's Lair",
		"Uldum",
		"Blackrock Spire", -- 250
		"Blackrock Spire",
		"Blackrock Spire",
		"Blackrock Spire",
		"Blackrock Spire",
		"Blackrock Spire",
		"Auchenai Crypts",
		"Auchenai Crypts",
		"Sethekk Halls",
		"Sethekk Halls",
		"Shadow Labyrinth",
		"The Blood Furnace",
		"The Underbog",
		"The Steamvault",
		"The Steamvault",
		"The Slave Pens",
		"The Botanica",
		"The Mechanar",
		"The Mechanar",
		"The Arcatraz",
		"The Arcatraz",
		"The Arcatraz",
		"Mana-Tombs",
		"The Black Morass",
		"Old Hillsbrad Foothills",
		"The Battle for Gilneas",
		"The Maelstrom",
		"Lost City of the Tol'vir",
		nil,
		"Wailing Caverns",
		"Maraudon",
		"Maraudon",
		"Baradin Hold",
		"Blackrock Caverns",
		"Blackrock Caverns",
		"Blackwing Descent",
		"Blackwing Descent",
		"Blackwing Lair",
		"Blackwing Lair",
		"Blackwing Lair",
		"Blackwing Lair",
		"The Deadmines",
		"The Deadmines",
		"Grim Batol",
		"The Bastion of Twilight",
		"The Bastion of Twilight",
		"The Bastion of Twilight",
		"Halls of Origination",
		"Halls of Origination",
		"Halls of Origination",
		"Razorfen Downs", -- 300
		"Razorfen Kraul",
		"Scarlet Monastery",
		"Scarlet Monastery",
		"Scarlet Monastery",
		"Scarlet Monastery",
		"ScholomanceOLD",
		"ScholomanceOLD",
		"ScholomanceOLD",
		"ScholomanceOLD",
		"Shadowfang Keep",
		"Shadowfang Keep",
		"Shadowfang Keep",
		"Shadowfang Keep",
		"Shadowfang Keep",
		"Shadowfang Keep",
		"Shadowfang Keep",
		"Stratholme",
		"Stratholme",
		"Ahn'Qiraj",
		"Ahn'Qiraj",
		"Ahn'Qiraj",
		"Throne of the Tides",
		"Throne of the Tides",
		"The Stonecore",
		"The Vortex Pinnacle",
		nil,
		"Ahn'Qiraj: The Fallen Kingdom",
		"Throne of the Four Winds",
		"Hyjal Summit",
		"Gruul's Lair",
		"Magtheridon's Lair",
		"Serpentshrine Cavern",
		"Zul'Aman",
		"Tempest Keep",
		"Sunwell Plateau",
		"Sunwell Plateau",
		"Zul'Gurub",
		"Molten Front",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Hellfire Ramparts",
		"Magisters' Terrace",
		"Magisters' Terrace",
		"Karazhan", -- 350
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Karazhan",
		"Firelands",
		"Firelands",
		"Firelands",
		"The Nexus",
		"The Jade Forest",
		"Greenstone Quarry",
		"Greenstone Quarry",
		"The Widow's Wail",
		"Oona Kagu",
		"Valley of the Four Winds",
		"Cavern of Endless Echoes",
		"The Wandering Isle",
		"Kun-Lai Summit",
		"Howlingwind Cavern",
		"Pranksters' Hollow",
		"Knucklethump Hole",
		"The Deeper",
		"The Deeper",
		"Tomb of Conquerors",
		"Ruins of Korune",
		"Ruins of Korune",
		"Townlong Steppes",
		"Niuzao Temple",
		"Vale of Eternal Blossoms",
		"Shrine of Two Moons",
		"Shrine of Two Moons",
		"Shrine of Seven Stars",
		"Shrine of Seven Stars",
		"Guo-Lai Halls",
		"Guo-Lai Halls",
		"Eye of the Storm",
		"Well of Eternity",
		"Hour of Twilight",
		"Hour of Twilight", -- 400
		"End Time",
		"End Time",
		"End Time",
		"End Time",
		"End Time",
		"End Time",
		"Darkmoon Island",
		nil,
		"Dragon Soul",
		"Dragon Soul",
		"Dragon Soul",
		"Dragon Soul",
		"Dragon Soul",
		"Dragon Soul",
		"Dragon Soul",
		"Dustwallow Marsh",
		"Temple of Kotmogu",
		"Krasarang Wilds",
		"Ruins of Ogudei",
		"Ruins of Ogudei",
		"Ruins of Ogudei",
		"Dread Wastes",
		"Silvershard Mines",
		"Pandaria",
		"Northshire",
		"Echo Ridge Mine",
		"Coldridge Valley",
		"Frostmane Hovel",
		"Temple of the Jade Serpent",
		"Temple of the Jade Serpent",
		"Scarlet Halls",
		"Scarlet Halls",
		"The Veiled Stair",
		"The Ancient Passage",
		"Scarlet Monastery",
		"Scarlet Monastery",
		"Gate of the Setting Sun",
		"Gate of the Setting Sun",
		"Stormstout Brewery",
		"Stormstout Brewery",
		"Stormstout Brewery",
		"Stormstout Brewery",
		"Shado-Pan Monastery",
		"Shado-Pan Monastery",
		"Shado-Pan Monastery",
		"Shado-Pan Monastery",
		"A Brewing Storm",
		"The Jade Forest",
		"Temple of Kotmogu",
		"Unga Ingoo", -- 450
		"Assault on Zan'vess",
		"Brewmoon Festival",
		"Mogu'shan Palace",
		"Mogu'shan Palace",
		"Mogu'shan Palace",
		"Terrace of Endless Spring",
		"Siege of Niuzao Temple",
		"Siege of Niuzao Temple",
		"Siege of Niuzao Temple",
		"Shadowglen",
		"Valley of Trials",
		"Camp Narache",
		"Echo Isles",
		"Spitescale Cavern",
		"Deathknell",
		"Night Web's Hollow",
		"Sunstrider Isle",
		"Ammen Vale",
		"New Tinkertown",
		"Frostmane Hold",
		"Mogu'shan Vaults",
		"Mogu'shan Vaults",
		"Mogu'shan Vaults",
		"Heart of Fear",
		"Heart of Fear",
		"Scholomance",
		"Scholomance",
		"Scholomance",
		"Scholomance",
		"Proving Grounds",
		"Crypt of Forgotten Kings",
		"Crypt of Forgotten Kings",
		"Dustwallow Marsh",
		nil,
		nil,
		"Krasarang Wilds",
		"A Little Patience",
		"Dagger in the Dark",
		"Dagger in the Dark",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Black Temple",
		"Krasarang Wilds",
		"Deeprun Tram",
		"Deeprun Tram", -- 500
		"Dalaran",
		"Dalaran",
		"Brawl'gar Arena",
		"Isle of Thunder",
		"Lightning Vein Mine",
		"The Swollen Vault",
		"Isle of Giants",
		"Throne of Thunder",
		"Throne of Thunder",
		"Throne of Thunder",
		"Throne of Thunder",
		"Throne of Thunder",
		"Throne of Thunder",
		"Throne of Thunder",
		"Throne of Thunder",
		"Isle of Thunder",
		"Lightning Vein Mine",
		"Thunder King's Citadel",
		"Deepwind Gorge",
		"Vale of Eternal Blossoms",
		"Vale of Eternal Blossoms",
		"The Secrets of Ragefire",
		"Dun Morogh",
		"Battle on the High Seas",
		[554] = "Timeless Isle",
		[555] = "Cavern of Lost Spirits",
		[556] = "Siege of Orgrimmar",
		[557] = "Siege of Orgrimmar",
		[558] = "Siege of Orgrimmar",
		[559] = "Siege of Orgrimmar",
		[560] = "Siege of Orgrimmar",
		[561] = "Siege of Orgrimmar",
		[562] = "Siege of Orgrimmar",
		[563] = "Siege of Orgrimmar",
		[564] = "Siege of Orgrimmar",
		[565] = "Siege of Orgrimmar",
		[566] = "Siege of Orgrimmar",
		[567] = "Siege of Orgrimmar",
		[568] = "Siege of Orgrimmar",
		[569] = "Siege of Orgrimmar",
		[570] = "Siege of Orgrimmar",
		[571] = "Celestial Tournament",
		[946] = "Cosmic",
		[947] = "Azeroth",
		[948] = "The Maelstrom",
		[987] = "Outland",
		[988] = "Northrend",
		[998] = "Undercity",
		[1467] = "Outland",
		[1554] = "Serpentshrine Cavern",
		[2104] = "Wintergrasp",
		[1375] = "Halls of Stone",
		[2473] = "Pandaria",
		[1464] = "Kalimdor",
		[2340] = "Tol Barad",
		[1463] = "Eastern Kingdoms",
		[1555] = "Tempest Keep"
	}
else
	DM.zoneNames = {
		[1425] = "The Hinterlands",
		[1450] = "Moonglade",
		[1441] = "Thousand Needles",
		[1452] = "Winterspring",
		[1417] = "Arathi Highlands",
		[1436] = "Westfall",
		[1418] = "Badlands",
		[1427] = "Searing Gorge",
		[1432] = "Loch Modan",
		--[1415] = "Eastern Kingdoms",
		[1458] = "Undercity",
		[1443] = "Desolace",
		[1460] = "Warsong Gulch",
		[1420] = "Tirisfal Glades",
		[1453] = "Stormwind City",
		[1447] = "Azshara",
		[1413] = "The Barrens",
		[1435] = "Swamp of Sorrows",
		--[947] = "Azeroth",
		[1416] = "Alterac Mountains",
		[1439] = "Darkshore",
		[1419] = "Blasted Lands",
		[1434] = "Stranglethorn Vale",
		[1423] = "Eastern Plaguelands",
		[1431] = "Duskwood",
		[1411] = "Durotar",
		[1454] = "Orgrimmar",
		[1440] = "Ashenvale",
		[1438] = "Teldrassil",
		[1433] = "Redridge Mountains",
		[1449] = "Un'Goro Crater",
		[1412] = "Mulgore",
		[1455] = "Ironforge",
		[1448] = "Felwood",
		[1446] = "Tanaris",
		[1442] = "Stonetalon Mountains",
		[1428] = "Burning Steppes",
		[1430] = "Deadwind Pass",
		[1426] = "Dun Morogh",
		[1422] = "Western Plaguelands",
		[1437] = "Wetlands",
		--[1414] = "Kalimdor",
		[1461] = "Arathi Basin",
		[1421] = "Silverpine Forest",
		[1457] = "Darnassus",
		[1444] = "Feralas",
		[1429] = "Elwynn Forest",
		[1459] = "Alterac Valley",
		[1456] = "Thunder Bluff",
		[1445] = "Dustwallow Marsh",
		[1424] = "Hillsbrad Foothills",
		[1451] = "Silithus",
		
		-- The Burning Crusade
		[1941] = "Eversong Woods",
		[1942] = "Ghostlands",
		[1943] = "Azuremyst Isle",
		[1944] = "Hellfire Peninsula",
		[1946] = "Zangarmarsh",
		[1947] = "The Exodar",
		[1948] = "Shadowmoon Valley",
		[1949] = "Blades Edge Mountains",
		[1950] = "Bloodmyst Isle",
		[1951] = "Nagrand",
		[1952] = "Terokkar Forest",
		[1953] = "Netherstorm",
		[1954] = "Silvermoon City",
		[1955] = "Shattrath City",
		[1957] = "Isle of Quel Danas",
		
		-- The Wrath of the Lich King
	    [114] = "Borean Tundra",
	    [115] = "Dragonblight",
	    [116] = "Grizzly Hills",
	    [117] = "Howling Fjord",
	    [118] = "Icecrown",
	    [119] = "Sholazar Basin",
	    [120] = "The Storm Peaks",
	    [121] = "Zul'Drak",
	    [123] = "Wintergrasp",
	    [125] = "Dalaran",
	    [126] = "The Underbelly",	
		[124] = "The Scarlet Enclave",	
		[127] = "Crystalsong Forest",
		[170] = "Hrothgar's Landing"
	}
end

DM.mapIDs = {}
for id, zone in pairs(DM.zoneNames) do
	if DM.mapIDs[zone] == nil then DM.mapIDs[zone] = id end
end

function DM.getZoneName(name)
	name = name:lower():gsub("[%s']", "")
	if name:sub(1, 3) == "the" then name = name:sub(4) end
	for zone, _ in pairs(DM.mapIDs) do
		local z = zone:lower():gsub("[%s']", "")
		if z:sub(1, 3) == "the" then z = z:sub(4) end
		if z == name then return zone end
	end
end
