local _G = getfenv(0)

function Skinner:Tablet()

	self:SecureHook(AceLibrary("Tablet-2.0"), "Open", function(tablet, parent)
--		self:Debug("TabletOpen: [%s, %s]", tablet, parent:GetName())
		self:Skin_Tablet()
		end)
	self:SecureHook(AceLibrary("Tablet-2.0"), "Detach", function(tablet, parent)
--		self:Debug("TabletDetach: [%s, %s]", tablet, parent:GetName())
		self:Skin_Tablet()
		end)

	self:Skin_Tablet()

end

local tabletsSkinned = {}

function Skinner:Skin_Tablet()
	if not self.db.profile.Tooltips.skin then return end

	if Tablet20Frame then
--		self:Debug("Tablet20Frame")
		local frame = Tablet20Frame
		if not tabletsSkinned["Tablet20Frame"] then
			tabletsSkinned["Tablet20Frame"] = true
			frame:SetBackdropColor(self.db.profile.Backdrop.r, self.db.profile.Backdrop.g, self.db.profile.Backdrop.b, self.db.profile.Backdrop.a)
			self:applySkin(frame)
			-- hook this to stop the Backdrop colours from being changed 
			self:Hook(frame, "SetBackdropColor", function(r, g, b, a) end, true)
		end
		frame.tfade:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", -4, -math.ceil(frame:GetHeight()))
	end
	
	local i = 1
	while _G["Tablet20DetachedFrame"..i] do
--		self:Debug("Tablet20DetachedFrame"..i)
		local frame = _G["Tablet20DetachedFrame"..i]
		if not tabletsSkinned["Tablet20DetachedFrame"..i] then
			tabletsSkinned["Tablet20DetachedFrame"..i] = true
			frame:SetBackdropColor(self.db.profile.Backdrop.r, self.db.profile.Backdrop.g, self.db.profile.Backdrop.b, self.db.profile.Backdrop.a)
			self:applySkin(frame)
			-- hook this to stop the Backdrop colours from being changed 
			self:Hook(frame, "SetBackdropColor", function(r, g, b, a) end, true)
		end
		i = i + 1
		frame.tfade:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", -4, -math.ceil(frame:GetHeight()))
	end
	
end
