---------------------------------------------------------------------------------
--
-- Prat - A framework for World of Warcraft chat mods
--
-- Copyright (C) 2006-2007  Prat Development Team
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 2
-- of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to:
--
-- Free Software Foundation, Inc., 
-- 51 Franklin Street, Fifth Floor, 
-- Boston, MA  02110-1301, USA.
--
--
-------------------------------------------------------------------------------



-- Gotta have Prat
if not Prat then return end

if not AceLibrary:HasInstance("FuBarPlugin-2.0") then return end

local L = AceLibrary("AceLocale-2.2"):new("PratFu")

L:RegisterTranslations("enUS", function() return {
    ["Prat"] = true,
    ["Fubar Options"] = true,
    ["FuBar"] = true,
    ["minimap"] = true,
    ["Minimap"] = true,
    ["Toggle the minimap button."] = true,
    ["Show it again with /prat minimap."] = true,
    ["%s icon is now %s."] = true,
    ["hidden"] = true,
    ["shown"] = true,
    ["The standard FuBar options."] = true,
    ["FuBar Options"] = true,

-- Note These Will Go Away By Release
-- So You dont need to localize them
	["Color Key"] = true,
	["Module Uses Prat Events"] = true,
	["Module Is Defective"] = true,
	["Module Needs Categorization"] = true,
    ["Module Hidden From the User"] = true,
    ["Module Status Normal"] = true,
} end)

L:RegisterTranslations("koKR", function() return {
    ["Prat"] = "Prat",
    ["Fubar Options"] = "Fubar 설정",
    ["FuBar"] = "Fubar",
--    ["minimap"] = true,
    ["Minimap"] = "미니맵",
    ["Toggle the minimap button."] = "미니맵 버튼 켜고/끄기",
    ["Show it again with /prat minimap."] = "/prat minimap 명령으로 미니맵 아이콘을 다시 표시할 수 있습니다.",
    ["%s icon is now %s."] = "%s 아이콘 : %s",
    ["hidden"] = "숨김",
    ["shown"] = "표시",
    ["The standard FuBar options."] = "기본 FuBar 설정입니다.",
    ["FuBar Options"] = "FuBar 설정",
    ["Color Key"] = "색상 분류",
    ["Module Uses Prat Events"] = "Prat 이벤트 사용 모듈",
    ["Module Is Defective"] = "불완전한 모듈",
    ["Module Needs Categorization"] = "분류 되어야 할 모듈",
    ["Module Hidden From the User"] = "숨겨진 모듈",
    ["Module Status Normal"] = "정상 상태 모듈",
} end)

L:RegisterTranslations("deDE", function() return {
    ["Prat"] = "Prat",
    ["Fubar Options"] = "Options Men\195\188",
    ["FuBar"] = "FuBar",
    ["minimap"] = "minimap",
    ["Minimap"] = "Minimap",
    ["Toggle the minimap button."] = "Aktiviere die Minimap Taste.",
    ["Show it again with /prat minimap."] = "Zeige es wieder mit /prat minimap.",
    ["%s icon is now %s."] = "%s Symbol ist nun %s.",
    ["hidden"] = "versteckt",
    ["shown"] = "sichtbar",
    ["The standard FuBar options."] = "Die Standart FuBar Optionen.",
    ["FuBar Options"] = "FuBar Optionen",
	["Color Key"] = "Farben Schl\195\188ssel",
	["Module Uses Prat Events"] = "Modul benutzt Prat Events",
	["Module Is Defective"] = "Modul ist Defekt",
	["Module Needs Categorization"] = "Modul ist nicht 2.0 Kompatibel",
    ["Module Hidden From the User"] = "Modul ist versteckt von dem Benutzer",
    ["Module Status Normal"] = "Modul Status Normal",
} end)

L:RegisterTranslations("frFR", function() return {
    ["Prat"] = "Prat",
    ["Fubar Options"] = "Menu d'options",
    ["FuBar"] = "FuBar",
    ["minimap"] = "mini-carte",
    ["Minimap"] = "Mini-carte",
    ["Toggle the minimap button."] = "Activer/d\195\169sactiver le bouton sur la mini-carte.",
    ["Show it again with /prat minimap."] = "Affichez le de nouveau avec /prat minimap.",
    ["%s icon is now %s."] = "L'ic\195\180ne %s est maintenant %s.",
    ["hidden"] = "cach\195\169e",
    ["shown"] = "affich\195\169e",
    ["The standard FuBar options."] = "Les options standard de FuBar.",
    ["FuBar Options"] = "Options de FuBar",
	["Color Key"] = "Codes couleurs",
	["Module Uses Prat Events"] = "Module utilisant les évènements de Prat",
	["Module Is Defective"] = "Module défectueux",
	["Module Needs Categorization"] = "Module non compatible avec Prat 2.0",
    ["Module Hidden From the User"] = "Module caché à l'utilisateur",
    ["Module Status Normal"] = "Module standard",
} end)

L:RegisterTranslations("esES", function() return {
    ["Prat"] = "Prat",
    ["Fubar Options"] = "Men\195\186 de Opciones",
    ["FuBar"] = "FuBar",
    ["minimap"] = "minimapa",
    ["Minimap"] = "Minimapa",
    ["Toggle the minimap button."] = "Determina si se activa el bot\195\179n del minimapa",
    ["Show it again with /prat minimap."] = "Mu\195\169stralo de nuevo con /prat minimap",
    ["%s icon is now %s."] = "El icono de %s es ahora %s.",
    ["hidden"] = "oculto",
    ["shown"] = "mostrado",
    ["The standard FuBar options."] = "Las opciones est\195\161ndar de FuBar",
    ["FuBar Options"] = "Opciones de FuBar",

-- Note These Will Go Away By Release
-- So You dont need to localize them
	["Color Key"] = "Clave de Colores",
	["Module Uses Prat Events"] = "El m\195\179dulo usa eventos de Prat",
	["Module Is Defective"] = "El m\195\179dulo es Defectuoso",
	["Module Needs Categorization"] = "El m\195\179dulo necesita categorizaci\195\179n",
    ["Module Hidden From the User"] = "M\195\179dulo oculto al usuario",
    ["Module Status Normal"] = "M\195\179dulo normal",
} end)

PratFu = AceLibrary("AceAddon-2.0"):new("FuBarPlugin-2.0", "AceDebug-2.0", "AceDB-2.0", "AceEvent-2.0")

-- Code from bigwigs can be used to provide a console command)
local mm = Prat:NewModule(Prat:RequestModuleName("minimap"))
mm.moduleHidden = true
mm.hasFuBar = IsAddOnLoaded("FuBar") and FuBar
function mm:GetModuleOptions()
    self.moduleOptions = not mm.hasFuBar and {
    	type = "toggle",
    	name = L["Minimap"],
    	desc = L["Toggle the minimap button."],
    	get = function() return PratFu.minimapFrame and PratFu.minimapFrame:IsVisible() or false end,
    	set = function(v)
    		if v then
    			PratFu:Show()
    		else
    			PratFu:Hide()
    			Prat:Print(L["Show it again with /prat minimap."])
    		end
    	end,
    	map = {[false] = L["hidden"], [true] = L["shown"]},
    	message = L["%s icon is now %s."],
    	hidden = function() return mm.hasFuBar end,
    }

    return self.moduleOptions
end

PratFu:RegisterDB("PratFuDB")
PratFu.title = "Prat"
PratFu.name = "FuBar - Prat"

PratFu.hasIcon = "Interface\\Addons\\Prat\\textures\\prat"
PratFu.cannotDetachTooltip = true
PratFu.hideWithoutStandby = true
PratFu.hideMenuTitle = true

PratFu.OnMenuRequest = Prat.Options

local args = AceLibrary("FuBarPlugin-2.0"):GetAceOptionsDataTable(PratFu)
if not PratFu.OnMenuRequest.args[L["Fubar Options"]] then
	PratFu.OnMenuRequest.args[L["Fubar Options"]] = {
		type = "group",
		name = L["Fubar Options"],
		desc = L["Fubar Options"],
		args = args,
		order = 340,
	}
end
Prat.hideMenuTitle = true

function PratFu:OnEnable()
	self:RegisterEvent("Prat_DebugModeChanged", "Update")
	self:RegisterEvent("Prat_ModuleDisabled", "ModuleUpdate")
	self:RegisterEvent("Prat_ModuleEnabled", "ModuleUpdate")
    self:SetDebugging(Prat:IsDebugging())
end

local dewdrop = AceLibrary("Dewdrop-2.0")

function PratFu:ModuleUpdate()
    dewdrop:Refresh(1)
end

function PratFu:OnTextUpdate()
	local str = self:GetTitle()..CLR:Colorize(Prat.Colors.VERSION2,"2.0")
	
	if Prat:IsDebugging() then 
		str = str.." - "
	
		if Prat:IsDebugging() then 
			str = str..CLR:Colorize("ff8080", "Debug  ")
		end
		
		str = str..CLR:Colorize(Prat.Colors.VERSION2, Prat.db.profile.doReplace and "Replacing" or "")
	end

	self:SetText(str)
end
function PratFu:OnClick()
	if Prat:IsDebugging() then
		if IsShiftKeyDown() then 
			ReloadUI()
		end
	end
end

function PratFu:OnDebugEnable()
    if not Prat:IsDebugging() then 
        Prat:SetDebugging(true)
    end
end 

function PratFu:OnDebugDisable()
    Prat:SetDebugging(false)
end 

local tablet =  AceLibrary("Tablet-2.0")

function PratFu:OnTooltipUpdate()
    local pc = Prat.Colors

	if tablet then
		tablet:SetTitle(Prat.VERSION_STRING)
	end
end







