local addonName, addon = ...
addonName = addonName:match("^(.+)_DevTools$")
addon = _G[addonName]
if not addon then return end

local GUI_DevBar = CreateFrame('Frame', "GUI_DevBar", UIParent)
GUI_DevBar:SetSize(145, 145)
GUI_DevBar:SetBackdrop{
		bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
		edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
		tile = true,
		tileSize = 32,
		edgeSize = 32,
		insets = {
			left = 11,
			right = 12,
			top = 12,
			bottom = 11
		}
	}

function addon:GrimUIMemUse()
	UpdateAddOnMemoryUsage()
	local GUIMemUse = GetAddOnMemoryUsage("GrimUI")
	print("|cff33ff99" .. addonName .. "|r: Current memory usage = ", GUIMemUse)
end

addon:GUI_BasicButtonCreate('DevBarButton1', GUI_DevBar,"Reload")
DevBarButton1:SetPoint("CENTER", 0, -40)
DevBarButton1:SetScript("OnClick", ReloadUI)
addon:GUI_BasicButtonCreate('DevBarButton2', GUI_DevBar,"Memory Use")
DevBarButton2:SetPoint("CENTER", 0, 0)
DevBarButton2:SetScript("OnClick", function() addon:GrimUIMemUse() end)
addon:GUI_BasicButtonCreate('DevBarButton3', GUI_DevBar,"Frame Stack")
DevBarButton3:SetPoint("CENTER", 0, 40)
DevBarButton3:SetScript("OnClick", function() SlashCmdList.FRAMESTACK() end)

function addon:GUI_ResetDevBar()
	GUI_DevBar:ClearAllPoints()
	GUI_DevBar:SetPoint("RIGHT", UIParent, "RIGHT", 0, 0)
end
addon:GUI_ResetDevBar()

function GUI_ShowDevBar()
	if addon.settings.showDevBar then
		addon:ShowFrame('GUI_DevBar')
	else
		addon:HideFrame('GUI_DevBar')
	end
end

function addon:BlizBuildInfo()
	local version, build, bdate, toc = GetBuildInfo()
	print(string.format("version = %s, build = %s, builddate = '%s', tocversion = %s.", version, build, bdate, toc))
end

addon.RegisterEvent("GDevBar-Initialize", 'ADDON_LOADED', function(self, event, name)
	addon.UnregisterEvent(self, event)
	GUI_ShowDevBar()
end)