local E = unpack(ElvUI)
local GetNumQuestWatches = C_QuestLog.GetNumQuestWatches
local GetQuestIDForQuestWatchIndex = C_QuestLog.GetQuestIDForQuestWatchIndex
local GetInfo = C_QuestLog.GetInfo
local GetLogIndexForQuestID = C_QuestLog.GetLogIndexForQuestID
----------------------------------------------------------------------------------------
--	Quest level
----------------------------------------------------------------------------------------
local function Showlevel()
	if not E.db.euiscript.QuestLevel then return; end
	for button in pairs(QuestScrollFrame.titleFramePool.activeObjects) do
		local title = button.info.title
		local isHeader = button.info.isHeader
		local level = button.info.level
		if title and not isHeader then
			local title = "["..level.."] "..title or title
			local height = button.Text:GetHeight()
			button.Text:SetText(title)
			button.Text:SetWidth(190)
			button.Check:SetPoint("LEFT", button.Text, button.Text:GetWrappedWidth() + 2, 0)
			button:SetHeight(button:GetHeight() - height + button.Text:GetHeight())
		end
	end
end
hooksecurefunc("QuestLogQuests_Update", Showlevel)

hooksecurefunc(QUEST_TRACKER_MODULE, "Update", function()
	if not E.db.euiscript.QuestLevel then return; end

	for i = 1, GetNumQuestWatches() do
		local questID = GetQuestIDForQuestWatchIndex(i)
		if not questID then
			break
		end
		local questLogIndex = GetLogIndexForQuestID(questID);
		local questInfo = GetInfo(questLogIndex)
		local block = QUEST_TRACKER_MODULE:GetExistingBlock(questID)
		if block then
			block.HeaderText:SetText("["..questInfo.difficultyLevel.."] "..questInfo.title)
		end
	end
end)

----------------------------------------------------------------------------------------
--	Ctrl+Click to abandon a quest or Alt+Click to share a quest(by Suicidal Katt)
----------------------------------------------------------------------------------------
hooksecurefunc("QuestMapLogTitleButton_OnClick", function(self)
	if IsControlKeyDown() then
		CloseDropDownMenus()
		QuestMapQuestOptions_AbandonQuest(self.questID)
	elseif IsAltKeyDown() and C_QuestLog.IsPushableQuest(self.questID) then
		CloseDropDownMenus()
		QuestMapQuestOptions_ShareQuest(self.questID)
	end
end)

hooksecurefunc(QUEST_TRACKER_MODULE, "OnBlockHeaderClick", function(_, block)
	if IsControlKeyDown() then
		CloseDropDownMenus()
		QuestMapQuestOptions_AbandonQuest(block.id)
	elseif IsAltKeyDown() and C_QuestLog.IsPushableQuest(block.id) then
		CloseDropDownMenus()
		QuestMapQuestOptions_ShareQuest(block.id)
	end
end)