--CHAT_MSG_WHISPER
function(_, msg, sender)
    msg = msg:lower()
    sender = sender:match("%a+")
    local cd, dur = GetSpellCooldown("Innervate")
    if msg == "innervate" and UnitGroupRolesAssigned(sender) == "HEALER" then
        if cd == 0 then
            aura_env.whisperT = math.floor(GetTime()) + 10
            aura_env.sender = sender
        end
        if cd > 0 then
            local readyin = math.floor(cd + dur - math.floor(GetTime()))
            SendChatMessage("Innervate on cd - Ready in " .. readyin .. " seconds", "WHISPER", "Common", sender)
        end
    end
end

--DISPLAY
function()
    local function GetClassColor(name)
        local color = "|cFF000000"
        local class = UnitClass(name)
        if class == "Death Knight" then color = "|cFFC41F3B" elseif
        class == "Demon Hunter" then color = "|cFFA330C9" elseif
        class == "Druid" then color = "|cFFFF7D0A" elseif
        class == "Hunter" then color = "|cFFABD473" elseif
        class == "Mage" then color = "|cFF40C7EB" elseif
        class == "Monk" then color = "|cFF00FF96" elseif
        class == "Paladin" then color = "|cFFF58CBA" elseif
        class == "Priest" then color = "|cFFFFFFFF" elseif
        class == "Rogue" then color = "|cFFFFF569" elseif
        class == "Shaman" then color = "|cFF0070DE" elseif
        class == "Warlock" then color = "|cFF8787ED" elseif
        class == "Warrior" then color = "|cFFC79C6E" end
        return color
    end
    if aura_env.whisperT > math.floor(GetTime()) then
        return "Innervate " .. GetClassColor(aura_env.sender) .. aura_env.sender .. "|r"
    else
        aura_env.sender = ""
        return ""
    end
end

--COMBAT_LOG_EVENT_UNFILTERED
function(...)
    local subevent = select(3, ...)
    if subevent == "SPELL_CAST_SUCCESS" then
        local caster = select(6, ...)
        local target = select(10, ...)
        local spell = select(14, ...)
        if caster == UnitName("player") and spell == "Innervate" then
            if target ~= aura_env.sender then
                SendChatMessage("Casting innervate on " .. target, "WHISPER", "Common", aura_env.sender)
            end
            if target == aura_env.sender then
                SendChatMessage("Casting innervate on you!", "WHISPER", "Common", aura_env.sender)
            end
            aura_env.whisperT = 0
            aura_env.sender = ""
        end
    end
end

--INIT
aura_env.whisperT = 0
aura_env.sender = ""
