--[[
Name: Prat_Justify
Developed by: Curney of Uther
Thanks to: Wubin for helping me understand variables better
Website: http://wiki.wowace.com/Prat_Justify
SVN: http://svn.wowace.com/root/trunk/Prat_Justify
Description: Module for Prat that sets the justification for chat windows (default=Left).
Dependencies: Prat
]]

Prat_Justify = Prat:NewModule('justify')

function Prat_Justify:OnInitialize()

    self.db = Prat:AcquireDBNamespace('Justify')

    Prat:RegisterDefaults('Justify', 'profile', {
        on = true,
        default = "LEFT",
        chatframe = {"LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT"}
    })

    Prat.Options.args.justify = {
        name = "Justify",
        desc = "Set the justification for chat windows (default=Left)",
        type = "group",
        args = {
            toggle = {
                name = "Toggle",
                desc = "Toggles the module on and off",
                type = "toggle",
                get = function() return self.db.profile.on end,
                set = function(v)
                    if v then
                        self:OnEnable()
                    else
                        self:OnDisable()
                    end
                    self.db.profile.on = v
                end
            },
        		chat1 = {
        			 name = "Chat1Justify",
        	    	 type = "text",
        	    	 desc = "Sets justification for chat window 1",
        	    	 get = function() return self.db.profile.chatframe[1] end,
        	    	 set = function(v)
                    self.db.profile.chatframe[1] = v
                    self:Set(1,v)
                end,
        	    	 validate = {["LEFT"] = "Left", ["RIGHT"] = "Right", ["CENTER"] = "Center"}
        		},
        		chat2 = {
                name = "Chat2Justify",
        	    	 type = "text",
        	    	 desc = "Sets justification for chat window 2",
        	    	 get = function() return self.db.profile.chatframe[2] end,
        	    	 set = function(v)
                    self.db.profile.chatframe[2] = v
                    self:Set(2,v)
                end,
        	    	 validate = {["LEFT"] = "Left", ["RIGHT"] = "Right", ["CENTER"] = "Center"}
        		},
        		chat3 = {
        			 name = "Chat3Justify",
        	    	 type = "text",
        	    	 desc = "Sets justification for chat window 3",
        	    	 get = function() return self.db.profile.chatframe[3] end,
        	    	 set = function(v)
                    self.db.profile.chatframe[3] = v
                    self:Set(3,v)
                end,
        	    	 validate = {["LEFT"] = "Left", ["RIGHT"] = "Right", ["CENTER"] = "Center"}
        		},
        		chat4 = {
        			 name = "Chat4Justify",
        	    	 type = "text",
        	    	 desc = "Sets justification for chat window 4",
        	    	 get = function() return self.db.profile.chatframe[4] end,
        	    	 set = function(v)
                    self.db.profile.chatframe[4] = v
                    self:Set(4,v)
                end,
        	    	 validate = {["LEFT"] = "Left", ["RIGHT"] = "Right", ["CENTER"] = "Center"}
        		},
        		chat5 = {
        			 name = "Chat5Justify",
        	    	 type = "text",
        	    	 desc = "Sets justification for chat window 5",
        	    	 get = function() return self.db.profile.chatframe[5] end,
        	    	 set = function(v)
                    self.db.profile.chatframe[5] = v
                    self:Set(5,v)
                end,
        	    	 validate = {["LEFT"] = "Left", ["RIGHT"] = "Right", ["CENTER"] = "Center"}
        		},
        		chat6 = {
        			 name = "Chat6Justify",
        	    	 type = "text",
        	    	 desc = "Sets justification for chat window 6",
        	    	 get = function() return self.db.profile.chatframe[6] end,
        	    	 set = function(v)
                    self.db.profile.chatframe[6] = v
                    self:Set(6,v)
                end,
        	    	 validate = {["LEFT"] = "Left", ["RIGHT"] = "Right", ["CENTER"] = "Center"}
        		},
        		chat7 = {
        			 name = "Chat7Justify",
        	    	 type = "text",
        	    	 desc = "Sets justification for chat window 7",
        	    	 get = function() return self.db.profile.chatframe[7] end,
        	    	 set = function(v)
                    self.db.profile.chatframe[7] = v
                    self:Set(7,v)
                end,
        	    	 validate = {["LEFT"] = "Left", ["RIGHT"] = "Right", ["CENTER"] = "Center"}
        		}
        }
    }
end

function Prat_Justify:OnEnable()
    for i=1,7 do
        self:Set(i,self.db.profile.chatframe[i])
    end
end

function Prat_Justify:OnDisable()
    for i=1,7 do
        self:Set(i,self.db.profile.default)
    end
end

function Prat_Justify:Set(frame,justification)
    local a = getglobal("ChatFrame"..frame)
    a:SetJustifyH(justification)
end
