---------------------------------------------------------------------------------
--
-- 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

-- Get Utility Libraries
local util, DBG, CLR = GetPratUtils()

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,
    ['|cffffff00Left-Click|r to open the Waterfall configuration menu'] = 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 설정",
    ['|cffffff00Left-Click|r to open the Waterfall configuration menu'] = "|cffffff00클릭|r시 Waterfall 설정창을 엽니다",
} end)

--Chinese Translate: 月色狼影@CWDG
--CWDG site: http://Cwowaddon.com
L:RegisterTranslations("zhCN", function() return {
    ["Prat"] = "Prat",
    ["Fubar Options"] = "FuBar设置",
    ["FuBar"] = "Fubar",
    ["minimap"] = "小地图",
    ["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设置",
    ['|cffffff00Left-Click|r to open the Waterfall configuration menu'] = "|cffffff00左击|r打开Waterfall设置目录",
} end)

L:RegisterTranslations("deDE", function() return {
    ["Prat"] = "Prat",
    ["Fubar Options"] = "FuBar Optionsmen\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",
    ['|cffffff00Left-Click|r to open the Waterfall configuration menu'] = '|cffffff00Links-Klick|r um das Waterfall Konfigurationsmenü zu öffnen.',
} 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",
} 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",
} end)

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

PratFu.title			= "Prat"
PratFu.name			= "FuBar - Prat"
PratFu.category			= 'Chat/Communication'
PratFu.hasIcon			= "Interface\\Addons\\Prat\\textures\\chat-bubble"
PratFu.cannotDetachTooltip	= true
PratFu.hideWithoutStandby	= true
PratFu.waterfallavailable	= AceLibrary:HasInstance("Waterfall-1.0")
PratFu.OnMenuRequest		= Prat.Options
PratFu.defaultPosition		= 'CENTER'
PratFu.hideMenuTitle		= true
PratFu.hasNoColor		= true



--
-- 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()
	-- module options heeyah
	self.moduleOptions = not mm.hasFuBar and {
	
	    args = {
		toggleminimap = {
			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."],		
			},

		toggleicon = {
			type	= 'toggle',
			name	= 'Icon',
			desc	= 'Toggle the FuBar icon',
			get	= function() return PratFu:IsIconShown() end,
			set	= function() return PratFu:ToggleIconShown() end,
			},

		toggletext = {
			type	= 'toggle',
			name	= 'Text',
			desc	= 'Toggle the FuBar title',
			get	= function() return PratFu:IsTextShown() end,
			set	= function() return PratFu:ToggleTextShown() end,
			},
			},
			
			hidden = function() return mm.hasFuBar end,
			disabled = false
			
		}

	return self.moduleOptions
end

if PratFu.waterfallavailable then
	local W = AceLibrary('Waterfall-1.0')
end

local clrstr = function(str, type)
	str = str or ''

	return CLR:Colorize(Prat.Colors.type, str)
end

local clrpratversion = function(ver)
	return clrstr(ver, 'VERSION2')
end

local clrdebugging = function(str)
	return clrstr(str, 'DEBUGGING')
end

local clrprofiling = function(str)
	return clrstr(str, 'PROFILING')
end

function PratFu:OnTextUpdate()
	local title	= 'Prat'
	local space	= nil
	local tags	= {}

	-- check if we're debugging
	if Prat:IsDebugging() then
		table.insert(tags, clrdebugging('Debugging'))
	end

	-- check if we're profiling
	if Prat:IsProfiling() then
		table.insert(tags, clrprofiling('Profiling'))
	end

	-- build a string to append if needed
	local tagstr	= table.concat(tags, ', ')

	-- build the title
	title	= title .. clrpratversion('2.0') .. (#tags > 0 and (' - ' .. tagstr) or '')
	-- title = 'Prat v2.0'

	self:SetText(title)
end

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


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:OnClick(button)
	if button == 'LeftButton' then
		if Prat:IsDebugging() and IsShiftKeyDown() then
			ReloadUI()
		elseif IsAltKeyDown() and IsControlKeyDown() then
			util:print('|cff80ff80Fin|r says: |r|cffffb200drink more beer.|r This has been a PSA brought to you by the letter |cffff8080AWESOME|r.')
		elseif self.waterfallavailable then
			PratWaterfall:Toggle()
		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 hint	= 'Prat - a framework for chat addons'

	if self.waterfallavailable then
		hint = hint .. "\n\n"
		hint = hint .. L['|cffffff00Left-Click|r to open the Waterfall configuration menu']
	end

	tablet:SetTitle('Prat ' .. Prat.VERSION_STRING)
	tablet:SetHint(hint)

	--[[
	local cat	= tablet:AddCategory({ 'columns', 2 })

	cat:AddLine(
		'text',		'Version:',
		'text2',	'2.0',
		)

	cat:AddLine(
		'text',		'Credits:',
		'text2',	'Sylvanaar, Fin, Krtek, Curney, and others',
		)

	cat:AddLine(
		'text',		'Beer:',
		'text2',	'Good',
		)
	]]
end
