-- MythicMate_Regions.lua
--
-- OAK-style region ("ping") tags for LFG listings. WoW's premade browser is locked to your
-- own physical region, but within the Americas region NA / Oceanic / Latin-America / Brazil
-- realms all share the same listings, so a friend's group can be a high-ping one. We map the
-- group leader's realm (parsed from "Name-Realm") to its sub-region and expose a tag.
--
-- Realm-name matching is normalized (lowercase, strip spaces/punctuation) so "Tol Barad",
-- "Quel'Thalas" etc. match regardless of formatting. Realms not in a notable-ping list return
-- nil (untagged — same-region / home), so most listings stay clean.

local function norm(s)
    if type(s) ~= "string" then return "" end
    return s:lower():gsub("[^%a%d]", "")
end

-- Build a lookup from a plain list of realm names to a region code.
local realmRegion = {}
local function register(code, names)
    for _, n in ipairs(names) do
        realmRegion[norm(n)] = code
    end
end

-- Oceanic (US region) — high ping for North-American players and vice-versa.
register("OCE", {
    "Aman'Thul", "Barthilas", "Caelestrasz", "Dath'Remar", "Dreadmaul", "Frostmourne",
    "Gundrak", "Jubei'Thos", "Khaz'goroth", "Nagrand", "Saurfang", "Thaurissan",
})

-- Brazil (US region, Portuguese).
register("BR", {
    "Azralon", "Gallywix", "Goldrinn", "Nemesis", "Tol Barad",
})

-- Latin America (US region, Spanish).
register("LATAM", {
    "Drakkari", "Quel'Thalas", "Ragnaros",
})

-- Parse the realm out of a leader name. Cross-realm listings are "Name-Realm"; same-realm
-- listings are just "Name" (no realm) → nil (home region, untagged).
local function realmOf(leaderName)
    if type(leaderName) ~= "string" then return nil end
    local realm = leaderName:match("%-(.+)$")
    return realm
end

-- Public: region code ("OCE"/"BR"/"LATAM") for a listing's leader, or nil when it's a home /
-- untagged realm. Guarded + global so the split LFG file can call it.
function MythicMate_RegionForLeader(leaderName)
    local realm = realmOf(leaderName)
    if not realm then return nil end
    return realmRegion[norm(realm)]
end

-- Display color per region code (used by the LFG list for the tag).
MythicMate_RegionColors = {
    OCE   = "ff37c8ff", -- cyan
    BR    = "ff35d24a", -- green
    LATAM = "ffffc93b", -- amber
}

-- All taggable region codes, for building filter toggles.
MythicMate_RegionCodes = { "OCE", "BR", "LATAM" }
