--[[
	Securely moves the Panel windows down below Skinner.TopFrame
	NB: Will not attempt to move a protected frame during combat. I.e. spellbook will apear in original position when opening/moving in combat.
]]

local self = Skinner

function Skinner:MovePanelFramesDown(frame,skipSetPoint)
	local offset = -self.db.profile.TopFrame.height or 0
		
	-- do nothing if we're disabled
	if not self.db.profile.TopFrame.adjustpanels then return end
	
	-- do nothing if UIParent skipped SetPoint
	if skipSetPoint then return end
	
	-- only move it down, dont move it up from normal (default offset is -104 so only if we're less then -104 do we continue)
	if offset > -104 then return end
	
	self:CheckAndMoveFrame(GetLeftFrame())
	self:CheckAndMoveFrame(GetCenterFrame())
	self:CheckAndMoveFrame(GetDoublewideFrame())
end 

function Skinner:CheckAndMoveFrame(frame)
	local debugInfo
	local offset = -self.db.profile.TopFrame.height or 0
	if frame and not (frame:IsProtected() and InCombatLockdown()) then 
		local info = UIPanelWindows[frame:GetName()]
		debugInfo = {frame:GetName(), UIPanelWindows[frame:GetName()]}
		if info.area == "center" then return debugInfo end -- if its a native center window just return debug info
    frame:ClearAllPoints() 
    frame:SetPoint("TOPLEFT","UIParent","TOPLEFT",0,offset) 
  end
	return debugInfo
end

self:SecureHook("SetLeftFrame", "MovePanelFramesDown") 
self:SecureHook("SetDoublewideFrame", "MovePanelFramesDown") 
self:SecureHook("SetCenterFrame", "MovePanelFramesDown") 
self:SecureHook("MovePanelToLeft", "MovePanelFramesDown") 
self:SecureHook("MovePanelToCenter", "MovePanelFramesDown") 