local C = Broker_Everything.color
local login_money = 0

local gold_onevent = function(self)
	local dataobj = self.obj or LibStub:GetLibrary("LibDataBroker-1.1"):GetDataObjectByName(L["GOLD"])
	if login_money == 0 then
		login_money = GetMoney()
	end
	dataobj.text = GetCoinTextureString(GetMoney())
end


local gold_events = {
	"PLAYER_LOGIN",
	"PLAYER_MONEY",
	"PLAYER_TRADE_MONEY",
	"TRADE_MONEY_CHANGED",
}


local gold_onclick = function()
	ToggleCharacter("TokenFrame")
end


local gold_tooltip = function(t)
	local now = GetMoney()
	local x = ''
	if now == login_money then
		x = C.white(GetCoinTextureString(0))
	elseif now > login_money then
		x = C.green("+" .. GetCoinTextureString(now - login_money))
	else
		x = C.red("-" .. GetCoinTextureString(login_money - now))
	end
	t:AddLine(L["GOLD"])
	t:AddLine (" ")
	t:AddDoubleLine(C.white(L["PROFITLOSS"]), x)
	t:AddLine (" ")
	t:AddLine(C.green(L["GOLDHINTLEFT"]))
end


Broker_Everything:Register(L["GOLD"],
	"Interface\\Minimap\\TRACKING\\Auctioneer", --GetItemIcon(43641),
	0,
	gold_onevent,
	gold_events,
	gold_onclick,
	gold_tooltip,
	nil,
	nil)
