--[[
			DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
					Version 2, December 2004

	Copyright (C) 2010 Christof Bruyland <christof.bruyland@gmail.com>

	Everyone is permitted to copy and distribute verbatim or modified
	copies of this license document, and changing it is allowed as long
	as the name is changed.
	
	This program is free software. It comes without any warranty, to
	the extent permitted by applicable law. You can redistribute it
	and/or modify it under the terms of the Do What The Fuck You Want
	To Public License, Version 2, as published by Sam Hocevar.

			DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
	TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

	0. You just DO WHAT THE FUCK YOU WANT TO.
]]--

CombatHideTooltip = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0","AceHook-2.1","AceConsole-2.0")

local inCombat = false

if CombatHideTooltipDB == nil then
    CombatHideTooltipDB = { }
    CombatHideTooltipDB.Unit = false
    CombatHideTooltipDB.Spell = false
    CombatHideTooltipDB.PetBar = false
    CombatHideTooltipDB.ShapeShift = false
end

CombatHideTooltip:RegisterChatCommand({ "/cht", "/combathidetooltip" }, {
    type = 'group',
    args = {
        Unit = {
            name = "Hide Mouseover/Unit Tooltips",
            desc = "Hide Mouseover/Unit Tooltips",
            type = 'toggle',
            get =   function()
                        return CombatHideTooltip:GetOption("Unit")
                    end,
            set =   function(v)
                        CombatHideTooltip:SetOption("Unit", v)
                    end,
        },
        Spell = {
            name = "Hide Spell/Ability Tooltips",
            desc = "Hide Spell/Ability Tooltips",
            type = 'toggle',
            get =   function()
                        return CombatHideTooltip:GetOption("Spell")
                    end,
            set =   function(v)
                        CombatHideTooltip:SetOption("Spell", v)
                    end,
        },
        PetBar = {
            name = "Hide PetBar Tooltips",
            desc = "Hide PetBar Tooltips",
            type = 'toggle',
            get =   function()
                        return CombatHideTooltip:GetOption("PetBar")
                    end,
            set =   function(v)
                        CombatHideTooltip:SetOption("PetBar", v)
                    end,
        },
        ShapeShift = {
            name = "Hide Shape Shift/Stance Tooltips",
            desc = "Hide Shape Shift/Stance Tooltips",
            type = 'toggle',
            get =   function()
                        return CombatHideTooltip:GetOption("ShapeShift")
                    end,
            set =   function(v)
                        CombatHideTooltip:SetOption("ShapeShift", v)
                    end,
        },
    },
})

function CombatHideTooltip:GetOption(key)
    return CombatHideTooltipDB[key]
end

function CombatHideTooltip:SetOption(key, value)
    CombatHideTooltipDB[key] = value
end

function CombatHideTooltip:OnEnable()
    self:RegisterEvent("PLAYER_REGEN_DISABLED")
    self:RegisterEvent("PLAYER_REGEN_ENABLED")
    self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
    self:Hook(GameTooltip, "SetUnit", true)
    self:Hook(GameTooltip, "SetAction", true)
    self:Hook(GameTooltip, "SetPetAction", true)
    self:Hook(GameTooltip, "SetShapeshift", true)
end

function CombatHideTooltip:PLAYER_REGEN_DISABLED()
    inCombat = true
end

function CombatHideTooltip:PLAYER_REGEN_ENABLED()
    inCombat = false
end

function CombatHideTooltip:UPDATE_MOUSEOVER_UNIT(unit, anchor)
    if inCombat and CombatHideTooltipDB.Unit then
        GameTooltip:Hide()
    end
end

function CombatHideTooltip:SetUnit(tooltip, unit, anchor)
    if inCombat and CombatHideTooltipDB.Unit then
        GameTooltip:Hide()
    else
        self.hooks[GameTooltip]["SetUnit"](tooltip, unit, anchor)
    end
end

function CombatHideTooltip:SetAction(tooltip,slot)
    if inCombat and CombatHideTooltipDB.Spell then
        GameTooltip:Hide()
    else
        self.hooks[GameTooltip]["SetAction"](tooltip,slot)
    end
end

function CombatHideTooltip:SetPetAction(tooltip,slot)
    if inCombat and CombatHideTooltipDB.PetBar then
        GameTooltip:Hide()
    else
        self.hooks[GameTooltip]["SetPetAction"](tooltip,slot)
    end
end

function CombatHideTooltip:SetShapeshift(tooltip,slot)
    if inCombat and CombatHideTooltipDB.ShapeShift then
        GameTooltip:Hide()
    else
        self.hooks[GameTooltip]["SetShapeshift"](tooltip,slot)
    end
end

