local AddOnName, nsVars = ...
local ss = nsVars.SS

local setmetatable = setmetatable
local strlower, select, UnitBuff, UnitStagger, UnitHealthMax = strlower, select, UnitBuff, UnitStagger, UnitHealthMax
local string, GetTime = string, GetTime

local timeBuffer = 0.05

local getMinMax = function(buff)
  local duration, expires = select(6, UnitBuff("player", buff))
  return buff, (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Incanters Flow
local getIncantersFlowMinMax = function(buff)
  local cur, max, prog = select(3, UnitIncantersFlow())
  return buff, (cur and 1 or 0), 1, (max or 1), (prog and (GetTime() + (max * prog) + timeBuffer) or 1)
end

-- Bloodtalons
local getBloodtalonsMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Bloodtalons"))

  if spell == "Bloodtalons2" and stacks then
    duration = (stacks == 2) and duration or nil
    expires = (stacks == 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "bloodtalons", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Focused Rage
local getFocusedRageMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Focused Rage"))

  if spell == "Focused Rage3" and stacks then
    duration = (stacks == 3) and duration or nil
    expires = (stacks == 3) and expires or nil
  elseif spell == "Focused Rage2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "focusedrage", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Frenzy
local getFrenzyMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Frenzy"))

  if spell == "Frenzy3" and stacks then
    duration = (stacks == 3) and duration or nil
    expires = (stacks == 3) and expires or nil
  elseif spell == "Frenzy2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "frenzy", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Clearcasting
local getClearcastingMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Clearcasting"))

  if spell == "Clearcasting3" and stacks then
    duration = (stacks == 3) and duration or nil
    expires = (stacks == 3) and expires or nil
  elseif spell == "Clearcasting2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "clearcasting", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Earthwarden
local getEarthwardenMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Earthwarden"))

  if spell == "Earthwarden3" and stacks then
    duration = (stacks == 3) and duration or nil
    expires = (stacks == 3) and expires or nil
  elseif spell == "Earthwarden2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "earthwarden", (duration and 1 or 0), 1, 1, (GetTime() + 1)
end

-- Warrior of Elune
local getWarriorofEluneMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Warrior of Elune"))

  if spell == "Warrior of Elune3" and stacks then
    duration = (stacks == 3) and duration or nil
    expires = (stacks == 3) and expires or nil
  elseif spell == "Warrior of Elune2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "warriorofelune", (duration and 1 or 0), 1, 1, (GetTime() + 1)
end

-- Mok'Nathal Tactics
local getMokNathalTacticsMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Mok'Nathal Tactics"))

  if spell == "Mok'Nathal Tactics4" and stacks then
    duration = (stacks == 4) and duration or nil
    expires = (stacks == 4) and expires or nil
  elseif spell == "Mok'Nathal Tactics3" and stacks then
    duration = (stacks >= 3) and duration or nil
    expires = (stacks >= 3) and expires or nil
  elseif spell == "Mok'Nathal Tactics2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "moknathaltactics", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Lock and Load
local getLockandLoadMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Lock and Load"))

  if spell == "Lock and Load2" and stacks then
    duration = (stacks == 2) and duration or nil
    expires = (stacks == 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "lockandload", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Void Ray
local getVoidRayMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Void Ray"))

  if spell == "Void Ray4" and stacks then
    duration = (stacks == 4) and duration or nil
    expires = (stacks == 4) and expires or nil
  elseif spell == "Void Ray3" and stacks then
    duration = (stacks >= 3) and duration or nil
    expires = (stacks >= 3) and expires or nil
  elseif spell == "Void Ray2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "voidray", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Surge of Light
local getSurgeOfLightMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Surge of Light"))

  if spell == "Surge of Light2" and stacks then
    duration = (stacks == 2) and duration or nil
    expires = (stacks == 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "surgeoflight", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Thunder Focus Tea
local getThunderFocusTeaMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Thunder Focus Tea"))

  if spell == "Thunder Focus Tea2" and stacks then
    duration = (stacks == 2) and duration or nil
    expires = (stacks == 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "thunderfocustea", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Icefury
local getIcefuryMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Icefury"))

  if spell == "Icefury4" and stacks then
    duration = (stacks == 4) and duration or nil
    expires = (stacks == 4) and expires or nil
  elseif spell == "Icefury3" and stacks then
    duration = (stacks >= 3) and duration or nil
    expires = (stacks >= 3) and expires or nil
  elseif spell == "Icefury2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "icefury", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Icy Talons
local getIcyTalonsMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Icy Talons"))

  if spell == "Icy Talons3" and stacks then
    duration = (stacks == 3) and duration or nil
    expires = (stacks == 3) and expires or nil
  elseif spell == "Icy Talons2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "icytalons", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Bone Shield
local getBoneShieldMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Bone Shield"))

  if spell == "Bone Shield10" and stacks then
    duration = (stacks == 10) and duration or nil
    expires = (stacks == 10) and expires or nil
  elseif spell == "Bone Shield9" and stacks then
    duration = (stacks >= 9) and duration or nil
    expires = (stacks >= 9) and expires or nil
  elseif spell == "Bone Shield8" and stacks then
    duration = (stacks >= 8) and duration or nil
    expires = (stacks >= 8) and expires or nil
  elseif spell == "Bone Shield7" and stacks then
    duration = (stacks >= 7) and duration or nil
    expires = (stacks >= 7) and expires or nil
  elseif spell == "Bone Shield6" and stacks then
    duration = (stacks >= 6) and duration or nil
    expires = (stacks >= 6) and expires or nil
  elseif spell == "Bone Shield5" and stacks then
    duration = (stacks >= 5) and duration or nil
    expires = (stacks >= 5) and expires or nil
  elseif spell == "Bone Shield4" and stacks then
    duration = (stacks >= 4) and duration or nil
    expires = (stacks >= 4) and expires or nil
  elseif spell == "Bone Shield3" and stacks then
    duration = (stacks >= 3) and duration or nil
    expires = (stacks >= 3) and expires or nil
  elseif spell == "Bone Shield2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "boneshield", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Backdraft
local getBackdraftMinMax = function(spell)
  local stacks, _, duration, expires = select(4, UnitBuff("player", "Backdraft"))

  if spell == "Backdraft4" and stacks then
    duration = (stacks == 4) and duration or nil
    expires = (stacks == 4) and expires or nil
  elseif spell == "Backdraft3" and stacks then
    duration = (stacks >= 3) and duration or nil
    expires = (stacks >= 3) and expires or nil
  elseif spell == "Backdraft2" and stacks then
    duration = (stacks >= 2) and duration or nil
    expires = (stacks >= 2) and expires or nil
  elseif stacks then
    duration = (stacks >= 1) and duration or nil
    expires = (stacks >= 1) and expires or nil
  end

  return "backdraft", (duration and 1 or 0), 1, (duration or 1), (expires or 1)
end

-- Stagger
local getStaggerMinMax = function()
  local min, max = UnitStagger("player"), UnitHealthMax("player")
  return "Stagger", min, max
end

-- Global Cooldown
local getGCD = function(spell)
  local duration = ss.gcdWatch.max and ss.gcdWatch.max or 1
  local expires = (ss.gcdWatch.start and ss.gcdWatch.max) and (ss.gcdWatch.start + ss.gcdWatch.max) or 1

  if ss.gcdWatch.start and GetTime() >= expires - timeBuffer then
    ss.gcdWatch.start = nil
  end

  return spell, (duration ~= expires) and 1 or 0, 1, duration, expires
end

local mtBuffData = {
  ["demonhunter"] = {
    ["momentum"]       = { "Momentum", { r=0.824, g=0.526, b=0.157, a=1 }, getMinMax = getMinMax, name = "Momentum", },
    ["empowerwards"]   = { "Empower Wards", { r=0.471, g=0.784, b=0.294, a=1 }, getMinMax = getMinMax, name = "Empower Wards", },
    ["demonspikes"]    = { "Demon Spikes", { r=0.784, g=0.725, b=0.000, a=1 }, getMinMax = getMinMax, name = "Demon Spikes", },
    ["soulbarrier"]    = { "Soul Barrier", { r=0.392, g=0.529, b=0.137, a=1 }, getMinMax = getMinMax, name = "Soul Barrier", },
    ["immolationaura"] = { "Immolation Aura", { r=0.863, g=0.941, b=0.275, a=1 }, getMinMax = getMinMax, name = "Immolation Aura", },
    ["globalcooldown"] = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["druid"] = {
    ["guardianofelune"]      = { "Guardian of Elune", { r=0.451, g=0.039, b=0.725, a=1 }, getMinMax = getMinMax, name = "Guardian of Elune",},
    ["ironfur"]              = { "Ironfur", { r=0.529, g=0.686, b=1.000, a=1 }, getMinMax = getMinMax, name = "Ironfur", },
    ["markofursol"]          = { "Mark of Ursol", { r=0.490, g=0.196, b=1.000, a=1 }, getMinMax = getMinMax, name = "Mark of Ursol", },
    ["frenziedregeneration"] = { "Frenzied Regeneration", { r=0.588, g=0.353, b=0.157, a=1 }, getMinMax = getMinMax, name = "Frenzied Regeneration", },
    ["souloftheforest"]      = { "Soul of the Forest", { r=0.196, g=0.314, b=0.431, a=1 }, getMinMax = getMinMax, name = "Soul of the Forest", },
    ["pulverize"]            = { "Pulverize", { r=0.196, g=0.784, b=0.784, a=1 }, getMinMax = getMinMax, name = "Pulverize", },
    ["tigersfury"]           = { "Tiger's Fury", { r=0.961, g=0.804, b=0.431, a=1 }, getMinMax = getMinMax, name = "Tiger's Fury", },
    ["savageroar"]           = { "Savage Roar", { r=1.000, g=0.667, b=0.039, a=1 }, getMinMax = getMinMax, name = "Savage Roar", },
    ["warriorofelune"]       = { "Warrior of Elune", { r=0.153, g=0.216, b=0.471, a=1 }, getMinMax = getWarriorofEluneMinMax, name = "Warrior of Elune", },
    ["warriorofelune2"]      = { "Warrior of Elune2", { r=0.153, g=0.216, b=0.471, a=1 }, getMinMax = getWarriorofEluneMinMax, name = "Warrior of Elune", },
    ["warriorofelune3"]      = { "Warrior of Elune3", { r=0.153, g=0.216, b=0.471, a=1 }, getMinMax = getWarriorofEluneMinMax, name = "Warrior of Elune", },
    ["earthwarden"]          = { "Earthwarden", { r=0.471, g=0.961, b=0.725, a=1 }, getMinMax = getEarthwardenMinMax, name = "Earthwarden", },
    ["earthwarden2"]         = { "Earthwarden2", { r=0.471, g=0.961, b=0.725, a=1 }, getMinMax = getEarthwardenMinMax, name = "Earthwarden", },
    ["earthwarden3"]         = { "Earthwarden3", { r=0.471, g=0.961, b=0.725, a=1 }, getMinMax = getEarthwardenMinMax, name = "Earthwarden", },
    ["clearcasting"]         = { "Clearcasting", { r=0.118, g=0.608, b=1.000, a=1 }, getMinMax = getClearcastingMinMax, name = "Clearcasting", },
    ["clearcasting2"]        = { "Clearcasting2", { r=0.118, g=0.608, b=1.000, a=1 }, getMinMax = getClearcastingMinMax, name = "Clearcasting", },
    ["clearcasting3"]        = { "Clearcasting3", { r=0.118, g=0.608, b=1.000, a=1 }, getMinMax = getClearcastingMinMax, name = "Clearcasting", },
    ["bloodtalons"]          = { "Bloodtalons", { r=0.706, g=0.098, b=0.000, a=1 }, getMinMax = getBloodtalonsMinMax, name = "Bloodtalons", },
    ["bloodtalons2"]         = { "Bloodtalons2", { r=0.706, g=0.098, b=0.000, a=1 }, getMinMax = getBloodtalonsMinMax, name = "Bloodtalons", },
    ["globalcooldown"]       = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["mage"] = {
    ["kaelthassultimateability"] = { "Kael'thas's Ultimate Ability", { r=0.647, g=0.294, b=0.765, a=1 }, getMinMax = getMinMax, name = "Kael'thas's Ultimate Ability",},
    ["freneticspeed"]            = { "Frenetic Speed", { r=1.000, g=0.784, b=0.294, a=1 }, getMinMax = getMinMax, name = "Frenetic Speed",},
    ["chronoshift"]              = { "Chrono Shift", { r=0.882, g=0.686, b=0.451, a=1 }, getMinMax = getMinMax, name = "Chrono Shift",},
    ["incantersflow"]            = { "Incanter's Flow", { r=0.824, g=0.157, b=0.196, a=1 }, getMinMax = getIncantersFlowMinMax, name = "Incanter's Flow",},
    ["globalcooldown"]           = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["monk"] = {
    ["stagger"]                  = { "Stagger", ss.ClassResourceData.resourceColor("chi"), getMinMax = getStaggerMinMax, name = "Stagger", },
    ["hitcombo"]                 = { "Hit Combo", { r=1.000, g=0.686, b=0.157, a=1 }, getMinMax = getMinMax, name = "Hit Combo", },
    ["thunderfocustea"]          = { "Thunder Focus Tea", { r=0.490, g=0.667, b=0.941, a=1 }, getMinMax = getThunderFocusTeaMinMax, name = "Thunder Focus Tea", },
    ["thunderfocustea2"]         = { "Thunder Focus Tea2", { r=0.490, g=0.667, b=0.941, a=1 }, getMinMax = getThunderFocusTeaMinMax, name = "Thunder Focus Tea", },
    ["lifecyclesvivify"]         = { "Lifecycles (Vivify)", { r=0.196, g=0.824, b=0.490, a=1 }, getMinMax = getMinMax, name = "Lifecycles (Vivify)", },
    ["lifecyclesenvelopingmist"] = { "Lifecycles (Enveloping Mist)", { r=0.863, g=0.824, b=0.529, a=1 }, getMinMax = getMinMax, name = "Lifecycles (Enveloping Mist)", },
    ["ironskinbrew"]             = { "Ironskin Brew", { r=0.529, g=1.000, b=0.843, a=1 }, getMinMax = getMinMax, name = "Ironskin Brew", },
    ["elusivedance"]             = { "Elusive Dance", { r=0.392, g=0.882, b=0.510, a=1 }, getMinMax = getMinMax, name = "Elusive Dance", },
    ["globalcooldown"]           = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["shaman"] = {
    ["boulderfist"]                  = { "Boulderfist", { r=0.588, g=0.333, b=0.118, a=1 }, getMinMax = getMinMax, name = "Boulderfist",},
    ["flametongue"]                  = { "Flametongue", { r=1.000, g=0.725, b=0.451, a=1 }, getMinMax = getMinMax, name = "Flametongue",},
    ["crashlightning"]               = { "Crash Lightning", { r=0.098, g=0.588, b=1.000, a=1 }, getMinMax = getMinMax, name = "Crash Lightning",},
    ["doomwinds"]                    = { "Doom Winds", { r=0.471, g=0.882, b=0.353, a=1 }, getMinMax = getMinMax, name = "Doom Winds",},
    ["windsong"]                     = { "Windsong", { r=0.510, g=0.784, b=0.824, a=1 }, getMinMax = getMinMax, name = "Windsong",},
    ["landslide"]                    = { "Landslide", { r=0.627, g=0.176, b=0.176, a=1 }, getMinMax = getMinMax, name = "Landslide",},
    ["elementalblastcriticalstrike"] = { "Elemental Blast: Critical Strike", { r=0.804, g=0.745, b=1.000, a=1 }, getMinMax = getMinMax, name = "Elemental Blast: Critical Strike",},
    ["elementalblasthaste"]          = { "Elemental Blast: Haste", { r=0.647, g=0.333, b=0.686, a=1 }, getMinMax = getMinMax, name = "Elemental Blast: Haste",},
    ["elementalblastmastery"]        = { "Elemental Blast: Mastery", { r=1.000, g=0.706, b=0.000, a=1 }, getMinMax = getMinMax, name = "Elemental Blast: Mastery",},
    ["icefury"]                      = { "Icefury", { r=0.682, g=0.549, b=1.000, a=1 }, getMinMax = getIcefuryMinMax, name = "Icefury",},
    ["icefury2"]                     = { "Icefury2", { r=0.682, g=0.549, b=1.000, a=1 }, getMinMax = getIcefuryMinMax, name = "Icefury",},
    ["icefury3"]                     = { "Icefury3", { r=0.682, g=0.549, b=1.000, a=1 }, getMinMax = getIcefuryMinMax, name = "Icefury",},
    ["icefury4"]                     = { "Icefury4", { r=0.682, g=0.549, b=1.000, a=1 }, getMinMax = getIcefuryMinMax, name = "Icefury",},
    ["shockofthetwistingnether"]     = { "Shock of the Twisting Nether", { r=0.608, g=1.000, b=0.529, a=1 }, getMinMax = getMinMax, name = "Shock of the Twisting Nether",},
    ["chillofthetwistingnether"]     = { "Chill of the Twisting Nether", { r=0.608, g=0.882, b=1.000, a=1 }, getMinMax = getMinMax, name = "Chill of the Twisting Nether",},
    ["fireofthetwistingnether"]      = { "Fire of the Twisting Nether", { r=0.843, g=0.176, b=0.000, a=1 }, getMinMax = getMinMax, name = "Fire of the Twisting Nether",},
    ["globalcooldown"]               = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["warrior"] = {
    ["enrage"]              = { "Enrage", { r=1.000, g=0.215, b=0.000, a=1 }, getMinMax = getMinMax, name = "Enrage",},
    ["enragedregeneration"] = { "Enraged Regeneration", { r=0.804, g=0.255, b=0.137, a=1 }, getMinMax = getMinMax, name = "Enraged Regeneration",},
    ["meatcleaver"]         = { "Meat Cleaver", { r=0.314, g=0.608, b=0.765, a=1 }, getMinMax = getMinMax, name = "Meat Cleaver",},
    ["shieldblock"]         = { "Shield Block", { r=0.294, g=0.549, b=0.784, a=1 }, getMinMax = getMinMax, name = "Shield Block",},
    ["ignorepain"]          = { "Ignore Pain", { r=1.000, g=0.647, b=0.020, a=1 }, getMinMax = getMinMax, name = "Ignore Pain",},
    ["frothingberserker"]   = { "Frothing Berserker", { r=1.000, g=0.549, b=0.000, a=1 }, getMinMax = getMinMax, name = "Frothing Berserker",},
    ["dragonroar"]          = { "Dragon Roar", { r=0.392, g=0.177, b=0.177, a=1 }, getMinMax = getMinMax, name = "Dragon Roar",},
    ["bloodbath"]           = { "Bloodbath", { r=1.000, g=0.275, b=0.020, a=1 }, getMinMax = getMinMax, name = "Bloodbath",},
    ["berserkerrage"]       = { "Berserker Rage", { r=0.922, g=0.490, b=0.196, a=1 }, getMinMax = getMinMax, name = "Berserker Rage",},
    ["renewedfury"]         = { "Renewed Fury", { r=0.812, g=0.294, b=0.275, a=1 }, getMinMax = getMinMax, name = "Renewed Fury",},
    ["vengeancerevenge"]    = { "Vengeance: Revenge", { r=1.000, g=0.706, b=0.314, a=1 }, getMinMax = getMinMax, name = "Vengeance: Revenge",},
    ["vengeanceignorepain"] = { "Vengeance: Ignore Pain", { r=1.000, g=0.706, b=0.314, a=1 }, getMinMax = getMinMax, name = "Vengeance: Ignore Pain",},
    ["juggernaut"]          = { "Juggernaut", { r=0.922, g=0.824, b=0.510, a=1 }, getMinMax = getMinMax, name = "Juggernaut",},
    ["warmachine"]          = { "War Machine", { r=1.000, g=0.196, b=0.216, a=1 }, getMinMax = getMinMax, name = "War Machine",},
    ["frenzy"]              = { "Frenzy", { r=0.549, g=0.451, b=0.294, a=1 }, getMinMax = getFrenzyMinMax, name = "Frenzy",},
    ["frenzy2"]             = { "Frenzy2", { r=0.549, g=0.451, b=0.294, a=1 }, getMinMax = getFrenzyMinMax, name = "Frenzy",},
    ["frenzy3"]             = { "Frenzy3", { r=0.549, g=0.451, b=0.294, a=1 }, getMinMax = getFrenzyMinMax, name = "Frenzy",},
    ["focusedrage"]         = { "Focused Rage", { r=0.843, g=0.196, b=0.078, a=1 }, getMinMax = getFocusedRageMinMax, name = "Focused Rage",},
    ["focusedrage2"]        = { "Focused Rage2", { r=0.843, g=0.196, b=0.078, a=1 }, getMinMax = getFocusedRageMinMax, name = "Focused Rage",},
    ["focusedrage3"]        = { "Focused Rage3", { r=0.843, g=0.196, b=0.078, a=1 }, getMinMax = getFocusedRageMinMax, name = "Focused Rage",},
    ["globalcooldown"]      = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["deathknight"] = {
    ["soulgorge"]      = { "Soulgorge", { r=0.490, g=0.039, b=0.353, a=1 }, getMinMax = getMinMax, name = "Soulgorge",},
    ["unholyfrenzy"]   = { "Unholy Frenzy", { r=0.902, g=0.784, b=0.922, a=1 }, getMinMax = getMinMax, name = "Unholy Frenzy",},
    ["icytalons"]      = { "Icy Talons", { r=0.373, g=0.412, b=0.667, a=1 }, getMinMax = getIcyTalonsMinMax, name = "Icy Talons",},
    ["icytalons2"]     = { "Icy Talons2", { r=0.373, g=0.412, b=0.667, a=1 }, getMinMax = getIcyTalonsMinMax, name = "Icy Talons",},
    ["icytalons3"]     = { "Icy Talons3", { r=0.373, g=0.412, b=0.667, a=1 }, getMinMax = getIcyTalonsMinMax, name = "Icy Talons",},
    ["boneshield"]     = { "Bone Shield", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["boneshield2"]    = { "Bone Shield2", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["boneshield3"]    = { "Bone Shield3", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["boneshield4"]    = { "Bone Shield4", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["boneshield5"]    = { "Bone Shield5", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["boneshield6"]    = { "Bone Shield6", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["boneshield7"]    = { "Bone Shield7", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["boneshield8"]    = { "Bone Shield8", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["boneshield9"]    = { "Bone Shield9", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["boneshield10"]   = { "Bone Shield10", { r=0.498, g=0.686, b=0.118, a=1 }, getMinMax = getBoneShieldMinMax, name = "Bone Shield",},
    ["globalcooldown"] = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["hunter"] = {
    ["mongoosefury"]      = { "Mongoose Fury", { r=0.804, g=0.157, b=0.098, a=1 }, getMinMax = getMinMax, name = "Mongoose Fury",},
    ["steadyfocus"]       = { "Steady Focus", { r=1.000, g=0.922, b=0.000, a=1 }, getMinMax = getMinMax, name = "Steady Focus",},
    ["bombardment"]       = { "Bombardment", { r=0.961, g=0.804, b=0.000, a=1 }, getMinMax = getMinMax, name = "Bombardment",},
    ["lockandload"]       = { "Lock and Load", { r=0.961, g=0.000, b=0.000, a=1 }, getMinMax = getLockandLoadMinMax, name = "Lock and Load",},
    ["lockandload2"]      = { "Lock and Load2", { r=0.961, g=0.000, b=0.000, a=1 }, getMinMax = getLockandLoadMinMax, name = "Lock and Load",},
    ["moknathaltactics"]  = { "Mok'Nathal Tactics", { r=0.765, g=0.529, b=0.349, a=1 }, getMinMax = getMokNathalTacticsMinMax, name = "Mok'Nathal Tactics",},
    ["moknathaltactics2"] = { "Mok'Nathal Tactics2", { r=0.765, g=0.529, b=0.349, a=1 }, getMinMax = getMokNathalTacticsMinMax, name = "Mok'Nathal Tactics",},
    ["moknathaltactics3"] = { "Mok'Nathal Tactics3", { r=0.765, g=0.529, b=0.349, a=1 }, getMinMax = getMokNathalTacticsMinMax, name = "Mok'Nathal Tactics",},
    ["moknathaltactics4"] = { "Mok'Nathal Tactics4", { r=0.765, g=0.529, b=0.349, a=1 }, getMinMax = getMokNathalTacticsMinMax, name = "Mok'Nathal Tactics",},
    ["globalcooldown"]    = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["paladin"] = {
    ["zeal"]           = { "Zeal", { r=0.941, g=0.902, b=0.588, a=1 }, getMinMax = getMinMax, name = "Zeal",},
    ["seraphim"]       = { "Seraphim", { r=0.569, g=0.451, b=0.137, a=1 }, getMinMax = getMinMax, name = "Seraphim",},
    ["globalcooldown"] = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["priest"] = {
    ["norgannonsforesight"] = { "Norgannon's Foresight", { r=0.000, g=0.922, b=1.000, a=1 }, getMinMax = getMinMax, name = "Norgannon's Foresight", },
    ["twistoffate"]         = { "Twist of Fate", { r=0.451, g=0.333, b=0.843, a=1 }, getMinMax = getMinMax, name = "Twist of Fate",},
    ["voidray"]             = { "Void Ray", { r=0.804, g=0.275, b=0.804, a=1 }, getMinMax = getVoidRayMinMax, name = "Void Ray",},
    ["voidray2"]            = { "Void Ray2", { r=0.804, g=0.275, b=0.804, a=1 }, getMinMax = getVoidRayMinMax, name = "Void Ray",},
    ["voidray3"]            = { "Void Ray3", { r=0.804, g=0.275, b=0.804, a=1 }, getMinMax = getVoidRayMinMax, name = "Void Ray",},
    ["voidray4"]            = { "Void Ray4", { r=0.804, g=0.275, b=0.804, a=1 }, getMinMax = getVoidRayMinMax, name = "Void Ray",},
    ["surgeoflight"]        = { "Surge of Light", { r=0.902, g=0.569, b=0.294, a=1 }, getMinMax = getSurgeOfLightMinMax, name = "Surge of Light",},
    ["surgeoflight2"]       = { "Surge of Light2", { r=0.902, g=0.569, b=0.294, a=1 }, getMinMax = getSurgeOfLightMinMax, name = "Surge of Light",},
    ["globalcooldown"]      = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["rogue"] = {
    ["truebearing"]         = { "True Bearing", { r=1.000, g=0.824, b=0.373, a=1 }, getMinMax = getMinMax, name = "True Bearing",},
    ["sharkinfestedwaters"] = { "Shark Infested Waters", { r=0.333, g=0.550, b=0.725, a=1 }, getMinMax = getMinMax, name = "Shark Infested Waters",},
    ["broadsides"]          = { "Broadsides", { r=1.000, g=0.627, b=0.059, a=1 }, getMinMax = getMinMax, name = "Broadsides",},
    ["grandmelee"]          = { "Grand Melee", { r=0.725, g=0.333, b=0.176, a=1 }, getMinMax = getMinMax, name = "Grand Melee",},
    ["jollyroger"]          = { "Jolly Roger", { r=0.725, g=0.686, b=0.686, a=1 }, getMinMax = getMinMax, name = "Jolly Roger",},
    ["buriedtreasure"]      = { "Buried Treasure", { r=1.000, g=0.843, b=0.000, a=1 }, getMinMax = getMinMax, name = "Buried Treasure",},
    ["envenom"]             = { "Envenom", { r=0.431, g=1.000, b=0.255, a=1 }, getMinMax = getMinMax, name = "Envenom",},
    ["shivarransymmetry"]   = { "Shivarran Symmetry", { r=1.000, g=0.765, b=0.588, a=1 }, getMinMax = getMinMax, name = "Shivarran Symmetry",},
    ["alacrity"]            = { "Alacrity", { r=1.000, g=1.000, b=0.392, a=1 }, getMinMax = getMinMax, name = "Alacrity",},
    ["sliceanddice"]        = { "Slice and Dice", { r=1.000, g=0.294, b=0.000, a=1 }, getMinMax = getMinMax, name = "Slice and Dice",},
    ["elaborateplanning"]   = { "Elaborate Planning", { r=0.941, g=0.784, b=0.078, a=1 }, getMinMax = getMinMax, name = "Elaborate Planning",},
    ["subterfuge"]          = { "Subterfuge", { r=0.882, g=0.843, b=1.000, a=1 }, getMinMax = getMinMax, name = "Subterfuge",},
    ["symbolsofdeath"]      = { "Symbols of Death", { r=1.000, g=0.216, b=0.980, a=1 }, getMinMax = getMinMax, name = "Symbols of Death",},
    ["envelopingshadows"]   = { "Enveloping Shadows", { r=0.882, g=0.451, b=0.882, a=1 }, getMinMax = getMinMax, name = "Enveloping Shadows",},
    ["globalcooldown"]      = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown",},
  },
  ["warlock"] = {
    ["empoweredlifetap"] = { "Empowered Life Tap", { r=0.686, g=0.217, b=1.000, a=1 }, getMinMax = getMinMax, name = "Empowered Life Tap", },
    ["backdraft"]        = { "Backdraft", { r=1.000, g=0.726, b=0.235, a=1 }, getMinMax = getBackdraftMinMax, name = "Backdraft", },
    ["backdraft2"]       = { "Backdraft2", { r=1.000, g=0.726, b=0.235, a=1 }, getMinMax = getBackdraftMinMax, name = "Backdraft", },
    ["backdraft3"]       = { "Backdraft3", { r=1.000, g=0.726, b=0.235, a=1 }, getMinMax = getBackdraftMinMax, name = "Backdraft", },
    ["backdraft4"]       = { "Backdraft4", { r=1.000, g=0.726, b=0.235, a=1 }, getMinMax = getBackdraftMinMax, name = "Backdraft", },
    ["globalcooldown"]   = { "Global Cooldown", { r=0.482, g=1.000, b=0.827, a=1 }, getMinMax = getGCD, name = "Global Cooldown", },
  },
};

mtBuffData.hasBuffs = function()
  return mtBuffData[strlower(ss.curClass)] and true or nil
end

mtBuffData.get = function(class, buff)
  local res = mtBuffData[strlower(class)][strlower(buff)]
  res.ssClass = "BuffData"
  return res
end

mtBuffData.init = function(resource)
  local index = strlower(string.gsub(resource[1], " ", ""))
  index = string.gsub(index, "'", "")
  index = string.gsub(index, ":", "")
  index = string.gsub(index, "%(", "")
  index = string.gsub(index, "%)", "")

  if mtBuffData[strlower(ss.curClass)][index] then
    resource[1]        = mtBuffData[strlower(ss.curClass)][index][1]
    resource[2]        = mtBuffData[strlower(ss.curClass)][index][2]
    resource.getMinMax = mtBuffData[strlower(ss.curClass)][index].getMinMax
  else
    resource.getMinMax = function() return "",0,0,0,0 end
  end
end

ss["BuffData"] = setmetatable({}, { __index = mtBuffData });
