local name, ns = ...

--[===[@debug@
local PREFIX = ("|cff00ff00%s|r: "):format(name)

local DevTools_Dump
DevTools_Dump = function(value)
	if not _G.DevTools_Dump then
		LoadAddOn("Blizzard_DebugTools")
	end
	DevTools_Dump = _G.DevTools_Dump
	DevTools_Dump(value)
end

local origChatFrame = DEFAULT_CHAT_FRAME
local debugChatFrame = ChatFrame4

local function dump(value)
	DEFAULT_CHAT_FRAME = debugChatFrame
	DevTools_Dump(value)
	DEFAULT_CHAT_FRAME = origChatFrame
end

local function mystrjoin(arg1, ...)
	local text = tostring(arg1)
	for i = 1, select('#', ...) do
		text = text .. tostring(select(i, ...))
	end
	return text
end

local function printDebug(...)
	local text = mystrjoin(PREFIX, ...)
	debugChatFrame:AddMessage(text)
end

local doDebug
local function realDebug(arg1, arg2, ...)
	if not arg1 then return end
	if type(arg1) == 'table' then
		printDebug("+++ table-dump")
		dump(arg1)
		printDebug("--- end of table-dump")
	elseif type(arg2) == 'table' then
		printDebug("+++ |c00ff0000", arg1, "|r dump")
		dump(arg2)
		printDebug("+++ end |c00ff0000", arg1, "|r dump")
	else
		if arg2 then
			printDebug(arg1, arg2, ...)
		else
			printDebug(arg1)
		end
	end
end
--@end-debug@]===]

local function debug(...)
	--[===[@debug@
	realDebug(...)
	--@end-debug@]===]
end
ns.debug = debug