local locale = GetLocale()
local L = locale == "koKR" and {
	["Live Buffs"] = "생존기",
} or {}
setmetatable(L, { __index = function(t, k) rawset(t, k, k); return k; end })

----------------------------------------------------------------
local LiveBuffs = {
	[GetSpellInfo(41104)] = true,	-- 방패의 벽
	[GetSpellInfo(12975)] = true,	-- 최후의 저항
	[GetSpellInfo(15087)] = true,	-- 회피
	[GetSpellInfo(31224)] = true,	-- 그림자 망토
	[GetSpellInfo(33581)] = true,	-- 천상의 보호막
	[GetSpellInfo(41450)] = true,	-- 보호의 축복
	[GetSpellInfo(41590)] = true,	-- 얼음 방패
	[GetSpellInfo(5384)] = true,	-- 죽은척하기
}
----------------------------------------------------------------

GridStatusLiveBuffs = GridStatus:NewModule("GridStatusLiveBuffs")

local GridStatusLiveBuffs = GridStatusLiveBuffs
local UnitBuff = UnitBuff
local UnitName = UnitName
local db

GridStatusLiveBuffs.menuName = L["Live Buffs"]
GridStatusLiveBuffs.options = false
GridStatusLiveBuffs.defaultDB = {
	debug = false,
	alert_LiveBuffs = {
		text = L["Live Buffs"],
		enable = true,
		color = { r = 0.8, g = 0.4, b = 0.8, a = 1 },
		priority = 99,
		range = true,
	},
}

function GridStatusLiveBuffs:OnInitialize()
	self.super.OnInitialize(self)
	self:RegisterStatus("alert_LiveBuffs", L["Live Buffs"], nil, true)
	db = self.db.profile
end

function GridStatusLiveBuffs:OnEnable()
	self:RegisterEvent("UNIT_AURA")
end

local Special, name, settings
function GridStatusLiveBuffs:UNIT_AURA(unit)
	Special = false

	for i = 1, 40 do
		name = UnitBuff(unit, i)
		if not name then
			break
		end

		if LiveBuffs[name] then
			Special = true
			break
		end
	end

	if Special then
		settings = db.alert_LiveBuffs
		self.core:SendStatusGained(UnitName(unit), "alert_LiveBuffs", settings.priority, (settings.range and 40), settings.color, settings.text, nil, nil, nil)
	else
		self.core:SendStatusLost(UnitName(unit), "alert_LiveBuffs")
	end
end