--[[
Name: Prat_Buttons
Developed by: Prat Development Team
Inspired by: idChat2_Buttons by Industrial
Website: http://www.wowace.com/mediawiki/index.php?title=Prat_Buttons
Description: Module for Prat that toggles the chat menu and chat window buttons on and off (default=off).
Dependencies: Prat
]]

Prat_Buttons = Prat:NewModule("buttons")

function Prat_Buttons:OnInitialize()
    self.db = Prat:AcquireDBNamespace("Buttons")
    Prat:RegisterDefaults("Buttons", "profile", {
        on = true,
        normal = true,
        chatmenu = false,
        chatbuttons = {false, false, false, false, false, false, false}
    })
    Prat.Options.args.buttons = {
        name = "Buttons",
        desc = "Chat window menu and buttons options",
        type = "group",
        args = {
            toggle = {
                name = "Toggle",
                desc = "Toggle the module on and off",
                type = "toggle",
                get = function() return self.db.profile.on end,
                set = function() self.db.profile.on = Prat:ToggleModuleActive("buttons") end
            },
        	chatmenu = {
        		name = "ChatMenu",
        	    type = "toggle",
        	    desc = "Toggles chat menu on and off",
        	    get = function() return self.db.profile.chatmenu end,
                set = function(v)
                    self.db.profile.chatmenu = v
                    self:ChatMenu(v)
                end
        	},
            chatbuttons = {
                name = "ChatButtons",
                type = "group",
                desc = "Toggle chat windows buttons on and off",
                args = {
            	    chat1 = {
            	 	    name = "Chat1Buttons",
            	    	type = "toggle",
            	    	desc = "Toggles buttons on and off for chat window 1",
            	    	get = function() return self.db.profile.chatbuttons[1] end,
                        set = function(v)
                            self.db.profile.chatbuttons[1] = v
                            self:ChatButtons(1,v)
                        end
            		},
            		chat2 = {
            		 	name = "Chat2Buttons",
            	    	type = "toggle",
            	    	desc = "Toggles buttons on and off for chat window 2",
            	    	get = function() return self.db.profile.chatbuttons[2] end,
                        set = function(v)
                            self.db.profile.chatbuttons[2] = v
                            self:ChatButtons(2,v)
                        end
            		},
            		chat3 = {
            		 	name = "Chat3Buttons",
            	    	type = "toggle",
            	    	desc = "Toggles buttons on and off for chat window 3",
            	    	get = function() return self.db.profile.chatbuttons[3] end,
                        set = function(v)
                            self.db.profile.chatbuttons[3] = v
                            self:ChatButtons(3,v)
                        end
            		},
            		chat4 = {
            		 	name = "Chat4Buttons",
            	    	type = "toggle",
            	    	desc = "Toggles buttons on and off for chat window 4",
            	    	get = function() return self.db.profile.chatbuttons[4] end,
                        set = function(v)
                            self.db.profile.chatbuttons[4] = v
                            self:ChatButtons(4,v)
                        end
            		},
            		chat5 = {
            		 	name = "Chat5Buttons",
            	    	type = "toggle",
            	    	desc = "Toggles buttons on and off for chat window 5",
            	    	get = function() return self.db.profile.chatbuttons[5] end,
                        set = function(v)
                            self.db.profile.chatbuttons[5] = v
                            self:ChatButtons(5,v)
                        end
            		},
            		chat6 = {
            		 	name = "Chat6Buttons",
            	     	type = "toggle",
            	    	desc = "Toggles buttons on and off for chat window 6",
            	    	get = function() return self.db.profile.chatbuttons[6] end,
                        set = function(v)
                            self.db.profile.chatbuttons[6] = v
                            self:ChatButtons(6,v)
                        end
            		},
            		chat7 = {
            		    name = "Chat7Buttons",
            	    	type = "toggle",
            	    	desc = "Toggles buttons on and off for chat window 7",
            	    	get = function() return self.db.profile.chatbuttons[7] end,
                        set = function(v)
                            self.db.profile.chatbuttons[7] = v
                            self:ChatButtons(7,v)
                        end
                    }
                }
            }
        }
    }
end

function Prat_Buttons:OnEnable()
    self:Hook("ChatFrame_OnUpdate")
end

function Prat_Buttons:OnDisable()
    self:ChatMenu(self.db.profile.normal)
    for i = 1,NUM_CHAT_WINDOWS do
        self:ChatButtons(i,self.db.profile.normal)
    end
end

function Prat_Buttons:ChatFrame_OnUpdate(elapsed)
    self.hooks["ChatFrame_OnUpdate"](elapsed)
    self:ChatMenu(self.db.profile.chatmenu)
    for i = 1,NUM_CHAT_WINDOWS do
        self:ChatButtons(i,self.db.profile.chatbuttons[i])
    end
end

function Prat_Buttons:ChatMenu(visible)
    if visible then
        ChatFrameMenuButton:Show()
    else
        ChatFrameMenuButton:Hide()
    end
end

function Prat_Buttons:ChatButtons(frame,visible)
    if visible then
        getglobal("ChatFrame"..frame.."UpButton"):Show()
        getglobal("ChatFrame"..frame.."DownButton"):Show()
        getglobal("ChatFrame"..frame.."BottomButton"):Show()
    else
        getglobal("ChatFrame"..frame.."UpButton"):Hide()
        getglobal("ChatFrame"..frame.."DownButton"):Hide()
        getglobal("ChatFrame"..frame.."BottomButton"):Hide()
    end
end
