local E, L, V, P, G = unpack(ElvUI);
local mPlugin = "mMediaTag"
local mMT = E:GetModule(mPlugin);
local DT = E:GetModule("DataTexts");
local addon, ns = ...
local mText = format("Dock %s", SPELLBOOK_ABILITIES_BUTTON)
local mTextName = "mSpellBook"

local function mDockCheckFrame()
	return ( SpellBookFrame and SpellBookFrame:IsShown() )
end

function mMT:CheckFrameSpellBook(self)
	mMT:DockTimerCheck(self, mDockCheckFrame())
end

local function OnEnter(self)
	mMT:mOnEnter(self, SPELLBOOK_ABILITIES_BUTTON)
end

local function OnEvent(self, event, ...)
	mMT:mOnEvent(self, nil, nil, nil, mDockCheckFrame(), E.db[mPlugin].mDock.textures.spellbook.path, "CheckFrameSpellBook")
end

local function OnLeave(self)
	mMT:mOnLeave(self, mDockCheckFrame())
end

local function OnClick(self)
	mMT:mClick(self, "CheckFrameSpellBook")
	if mMT:mCheckCombat() then
		ToggleSpellBook(BOOKTYPE_SPELL)
	end
end

DT:RegisterDatatext(mTextName, nil, nil, OnEvent, nil, OnClick, OnEnter, OnLeave, mText, nil)