local MER, F, E, L, V, P, G = unpack(select(2, ...))
local module = MER:GetModule('MER_Loot')
local LCG = LibStub('LibCustomGlow-1.0')
local M = E:GetModule('Misc')

local _G = _G

local GetLootSlotInfo = GetLootSlotInfo
local GetNumLootItems = GetNumLootItems
local hooksecurefunc = hooksecurefunc

function module:LOOT_OPENED(_, autoloot)
	local lootFrame = _G.ElvLootFrame

	local items = GetNumLootItems()
	if items > 0 then
		for i=1, items do
			local slot = lootFrame.slots[i] or createSlot(i) -- Monitor this
			local _, _, _, _, _, _, isQuestItem, questId, isActive = GetLootSlotInfo(i)

			local questTexture = slot.questTexture
			if ( questId and not isActive ) then
				questTexture:Show()
				LCG.PixelGlow_Start(slot.iconFrame)
			elseif ( questId or isQuestItem ) then
				questTexture:Hide()
				LCG.PixelGlow_Start(slot.iconFrame)
			else
				LCG.PixelGlow_Stop(slot.iconFrame)
			end
		end
	end
end

function module:Initialize()
	hooksecurefunc(M, "LOOT_OPENED", module.LOOT_OPENED)
end

MER:RegisterModule(module:GetName())
