local _,ns = ...
ns.ADDUIEVENT("PLAYER_LOGIN", function()
if AddUIDB.smapicon ==  false  then return end
--------------------------------
--老V 更新--https://nga.178.com/read.php?tid=8064400
--------------------------------

--不想隐藏的框架
local notbuttons = {
	['TimeManagerClockButton'] = true,
	--['LibDBIcon10_BugSack'] = true,
	['MiniMapTracking'] = true,
	['MiniMapWorldMapButton'] = true,
	['MiniMapBattlefieldFrame'] = true,
}

--想隐藏但没隐藏的框架
local buttons = {
	--['AddonCompartmentFrame'] = true,
	["ExpansionLandingPageMinimapButton"] = true,
}


local g = getfenv(0)
local addon = CreateFrame('Frame', 'MinimapButtons', UIParent)

local isMinimapButton = function(frame)
	if frame and frame:GetObjectType() == 'Button' and frame:GetNumRegions() >= 3 then
		return true
	end
end

function addon:findButtons(frame)
	for i, child in ipairs({frame:GetChildren()}) do
		local name = child:GetName()
		if isMinimapButton(child) and not notbuttons[name] then
			self:addButton(child)
		else
			self:findButtons(child)
		end
	end
end

function addon:findSpecialButtons()
	for button, get in pairs(buttons) do
		if g[button] and get == true then
			self:addButton(g[button])
		end
	end
end

function addon:addButton(button)
	if button:GetParent() ~= self then
		button:SetParent(self)
		self:SetScale(0.8)
	end
end

function addon:scan()
	self:findButtons(Minimap)
	self:findSpecialButtons()
end

local time = 0
local onUpdate = function(self, elapsed)
	time = time + elapsed
	if time > 5 then
		time = 0
		self:scan()
		self:SetScript('OnUpdate', nil)
	end
end

function addon:delayedScan()
	self:SetScript('OnUpdate', onUpdate)
end

function addon:enable(settings)
	self:SetScript('OnEvent', self.delayedScan)
	self:RegisterEvent'PLAYER_LOGIN'
	self:RegisterEvent'ADDON_LOADED'
	self:RegisterEvent'UPDATE_BATTLEFIELD_STATUS'
end

Minimap:HookScript('OnEnter', function(self) UIFrameFadeIn(MinimapButtons, 0.3, MinimapButtons:GetAlpha(), 1)   end) --鼠标进入小地图0.3秒出现小地图按钮
Minimap:HookScript('OnLeave', function(self) UIFrameFadeOut(MinimapButtons, 5, MinimapButtons:GetAlpha(), 0)   end) --鼠标离开小地图6秒渐隐


local f = CreateFrame("Frame") 
f:RegisterEvent("PLAYER_ENTERING_WORLD") 
f:SetScript("OnEvent", function(self, event) 
	if event == "PLAYER_ENTERING_WORLD" then 
		UIFrameFadeOut(MinimapButtons, 0.6, MinimapButtons:GetAlpha(), 0)
	end 
end)

MinimapButtons:enable({})

end)