local addonName, addon = ...
_G[addonName] = addon

for id = 1, 9 do
	local frame = CreateFrame("Button", "GUIAnchorPoint" .. id, UIParent)
	frame:SetHeight(20)
	frame:SetWidth(140)
	frame.bg = frame:CreateTexture(nil, "BACKGROUND")
	frame.bg:SetTexture(0, 0, 0, .7)
	frame.bg:SetAllPoints()
	frame.txt = frame:CreateFontString(nil, "ARTWORK")
	frame.txt:SetFont([[Fonts\FRIZQT__.TTF]], 12)
	frame.txt:SetPoint("CENTER", frame, "CENTER")
	frame.txt:SetTextColor(1, 1, 1, 1)
	frame:RegisterForClicks("AnyUp")
	frame:SetScript("OnClick", function(self, button)
		if button == "RightButton" then
			frame:Hide()
		end
	end)
	frame:SetScript('OnEnter', function(self)
		GameTooltip:SetOwner(self, 'ANCHOR_TOP', 0, 1)
		GameTooltip:AddLine("|cffeda55fCtrl+Left Click|r to Move", 0.2, 1, 0.2)
		GameTooltip:AddLine("|cffeda55fRight Click|r to hide anchor", 0.2, 1, 0.2)
		GameTooltip:Show()
	end)
	frame:SetScript('OnLeave', addon.HideTooltip)
end


function addon:GUIDefaultAnchors()
	GUIAnchorPoint1:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 200, -70) --BattleNet Toast Frame Anchor
	GUIAnchorPoint2:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", -200, -70) --Achivement Alert Anchor
	GUIAnchorPoint3:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 328) --DungeonCompletion Alert Anchor
	GUIAnchorPoint4:SetPoint("TOP", UIParent, "TOP", 0, -50) --Loot Frame Anchor
	GUIAnchorPoint5:SetPoint("CENTER", UIParent, "CENTER", 0, -50) --Casting Bar Anchor
	GUIAnchorPoint6:SetPoint('BOTTOMLEFT', UIParent, 'BOTTOMLEFT', 35, 450) --Tooltip Anchor
	GUIAnchorPoint7:SetPoint("RIGHT", UIParent, "RIGHT", -250, 0) --Context Menu
	GUIAnchorPoint8:SetPoint("CENTER", UIParent, "CENTER", 0, 0) --PlayerAltPowerBar
	GUIAnchorPoint9:SetPoint("CENTER", UIParent, "CENTER", 0, 0) --BossTargetFrame
	
	GUIAnchorPoint1.txt:SetText("BattleNet Notification")
	GUIAnchorPoint2.txt:SetText("Achivement Alert")
	GUIAnchorPoint3.txt:SetText("Dungeon Complete")
	GUIAnchorPoint4.txt:SetText("Loot Frame")
	GUIAnchorPoint5.txt:SetText("Casting Bar")
	GUIAnchorPoint6.txt:SetText("Tooltip Anchor")
	GUIAnchorPoint7.txt:SetText("Context Menu")
	GUIAnchorPoint8.txt:SetText("Alt Power Bar")
	GUIAnchorPoint9.txt:SetText("Boss Target Frame")
end


function addon:ShowAnchorPoints()
	if not GUIAnchorPoint1:IsShown() then
		for id = 1, 9 do
			_G["GUIAnchorPoint"..id]:Show()
		end
	elseif GUIAnchorPoint1:IsShown() then
		for id = 1, 9 do
			_G["GUIAnchorPoint"..id]:Hide()
		end
	end
end

addon:GUIDefaultAnchors()

addon.RegisterEvent("InitializeAnchors", 'PLAYER_ENTERING_WORLD', function(self, event)
	addon.UnregisterEvent(self, event)
	for id = 1, 9 do
		_G["GUIAnchorPoint"..id]:Hide()
	end
end)