local E, L, V, P, G = unpack(ElvUI);
local mPlugin = "mMediaTag"
local mMT = E:GetModule(mPlugin);
local addon, ns = ...
local LSM = E.Libs.LSM

-- Lib Globals
local unpack = unpack

-- WoW Globals
local _G = _G
local ObjectiveTrackerFrame = _G.ObjectiveTrackerFrame
local ObjectiveTrackerBlocksFrame = _G.ObjectiveTrackerBlocksFrame
local WORLD_QUEST_TRACKER_MODULE = _G.WORLD_QUEST_TRACKER_MODULE
local BONUS_OBJECTIVE_TRACKER_MODULE = _G.BONUS_OBJECTIVE_TRACKER_MODULE
local maxNumQuestsCanAccept = C_QuestLog.GetMaxNumQuestsCanAccept()
local HeaderTitel = ObjectiveTrackerBlocksFrame.QuestHeader.Text:GetText()
local width = _G.ObjectiveTrackerFrame:GetWidth()


-- Variables
local QuestSort = nil
local _, unitClass = UnitClass("PLAYER")
local mClassColor = ElvUF.colors.class[unitClass]
local mFontFlags = {
	NONE = L["NONE"],
	OUTLINE = 'Outline',
	THICKOUTLINE = 'Thick',
	MONOCHROME = '|cffaaaaaaMono|r',
	MONOCHROMEOUTLINE = '|cffaaaaaaMono|r Outline',
	MONOCHROMETHICKOUTLINE = '|cffaaaaaaMono|r Thick',
}
local positionValues = {
	LEFT = 'LEFT',
	RIGHT = 'RIGHT',
	CENTER = 'CENTER',
	TOP = 'TOP',
	TOPLEFT = 'TOPLEFT',
	TOPRIGHT = 'TOPRIGHT',
	BOTTOM = 'BOTTOM',
	BOTTOMLEFT = 'BOTTOMLEFT',
	BOTTOMRIGHT = 'BOTTOMRIGHT',
}

local QuestDotIcon, QuestDoneIcon = nil, nil
local TextureList, mIconsList = nil, nil

local function mTGAtoIcon(file, i)
	return format("|T%s:16:16:0:0.8:64:64|t %s - %s", file, L["Icon"], i)
end

local function mGetTexturePath(file)
	return format("Interface\\AddOns\\ElvUI_mMediaTag\\media\\misc\\dot%s.tga", file)
end

local function SetupDotIconList()
	if not mIconsList then
        local tmpIcon = {}
        for i=1, 7, 1 do
            local path = mGetTexturePath(i)
            tmpIcon[i] = {["file"] = path, ["icon"] = mTGAtoIcon(path, i)}
        end
        mIconsList = tmpIcon
    end
end

local function mTextureList()
	if not TextureList then
		SetupDotIconList()
        local tmpTexture = {}
        local i = 0
        for i in pairs(mIconsList) do
            tmpTexture[i] = mIconsList[i].icon
        end
        TextureList = tmpTexture
    end
	return TextureList
end

local function mDashIcon(icon) 
	return format ("|T%s:8:8:-1:-3.8:64:64|t", icon)
end

local function mQuestColors(text, dash)
	local current, required, details = strmatch(text, "^(%d-)/(%d-) (.+)")
	if not (current and required and details) then
		details, current, required = strmatch(text, "(.+): (%d-)/(%d-)$")
	end

	if (current and required and details) then
		local Progress = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.enable
		local Percent = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.percent

		local QuestColor = ""
		local QuestColorEnd = ""
		local QuestProgressPercent = ""
		local NumberCurrent, NumberRequired = tonumber(current), tonumber(required)
		local TempPercent = mMT:round((NumberCurrent/NumberRequired)*100 or 0)

		if Progress then
			local cGr, cGg, cGb = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.good.r, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.good.g, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.good.b
			local cTr, cTg, cTb = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.transition.r, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.transition.g, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.transition.b
			local cBr, cBg, cBb = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.bad.r, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.bad.g, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.bad.b
			local pr, pg, pb = E:ColorGradient(TempPercent * 0.01, cBr, cBg, cBb, cTr, cTg, cTb, cGr, cGg, cGb)
			QuestColor = E:RGBToHex(pr, pg, pb)
			QuestColorEnd = "|r"
		end

		if Percent then
			QuestProgressPercent = TempPercent
		end

		if NumberRequired >= 2 then
			text = format("[%s%s/%s%s] - %s%s%s%s %s", QuestColor, current, required, QuestColorEnd, QuestColor, QuestProgressPercent, "%", QuestColorEnd, details)
		else
			text = format("[%s%s/%s%s] %s", QuestColor, current, required, QuestColorEnd, details)
		end

		return text
	end
	return nill
end

local function mFontSetting(_, quest)
	local mTitelEnable = E.db[mPlugin].mObjectiveTracker.quests.titel.enable
	local mTitelFont = LSM:Fetch('font', E.db[mPlugin].mObjectiveTracker.quests.titel.font)
	local mTitelFontSize = E.db[mPlugin].mObjectiveTracker.quests.titel.fontsize
	local mTitelFontFlag = E.db[mPlugin].mObjectiveTracker.quests.titel.fontflag
	local mTitelFontColor = {r = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor.r, g = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor.g, b = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor.b,}
	local mQuestCompleteFontColor = {r = E.db[mPlugin].mObjectiveTracker.quests.other.completefontcolor.r, g = E.db[mPlugin].mObjectiveTracker.quests.other.completefontcolor.g, b = E.db[mPlugin].mObjectiveTracker.quests.other.completefontcolor.b,}
		
	if E.db[mPlugin].mObjectiveTracker.quests.titel.fontstyle == "class" then
		mTitelFontColor = {r = mClassColor[1], g = mClassColor[2], b = mClassColor[3],}
	end

	local mQuestEnable = E.db[mPlugin].mObjectiveTracker.quests.other.enable
	local mQuestFont = LSM:Fetch('font', E.db[mPlugin].mObjectiveTracker.quests.other.font)
	local mQuestFontSize = E.db[mPlugin].mObjectiveTracker.quests.other.fontsize
	local mQuestFontFlag = E.db[mPlugin].mObjectiveTracker.quests.other.fontflag
	local mQuestFontColor = {r = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor.r, g = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor.g, b = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor.b,}
	
	if E.db[mPlugin].mObjectiveTracker.quests.other.fontstyle == "class" then
		mQuestFontColor = {r = mClassColor[1], g = mClassColor[2], b = mClassColor[3],}
	end

	local DashStyle = E.db[mPlugin].mObjectiveTracker.quests.questtext.dashstyle
	local DashCustom = E.db[mPlugin].mObjectiveTracker.quests.questtext.dashcustom

	if quest then
		if quest.HeaderText and mTitelEnable == true then
			quest.HeaderText:SetFont(mTitelFont, mTitelFontSize, mTitelFontFlag)
		end
	
		if quest.currentLine and mTitelEnable == true or mQuestEnable == true then
			if quest.currentLine.objectiveKey == 0 and mTitelEnable == true then
				quest.currentLine.Text:SetFont(mTitelFont, mTitelFontSize, mTitelFontFlag)
			else
				quest.currentLine.Text:SetFont(mQuestFont, mQuestFontSize, mQuestFontFlag)
				local mQuestText = quest.currentLine.Text:GetText()

				if (quest.currentLine.Dash) and DashStyle ~= "blizzard" and DashStyle ~= "none" then
					if DashStyle == "dot" then
						quest.currentLine.Dash:SetText(QuestDotIcon)
					elseif DashStyle == "custom" then
						quest.currentLine.Dash:SetText(DashCustom)
					end
				elseif DashStyle == "none" then
					quest.currentLine.Dash:Hide()
					quest.currentLine.Text:ClearAllPoints()
					quest.currentLine.Text:Point("TOPLEFT", quest.currentLine.Dash, "TOPLEFT", 0, 0)
				end

				if quest.currentLine.Check then
					if DashStyle == "none" then
						quest.currentLine.Check:ClearAllPoints()
						quest.currentLine.Check:Point("TOPRIGHT", quest.currentLine.Dash, "TOPLEFT", 0, 0)
					end
					quest.currentLine.Check:SetTexture("Interface\\AddOns\\ElvUI_mMediaTag\\media\\misc\\check.tga")
					quest.currentLine.Check:SetVertexColor(mQuestCompleteFontColor.r, mQuestCompleteFontColor.g, mQuestCompleteFontColor.b, 1)
				end

				if quest.Check then
					if DashStyle == "none" then
						quest.Check:ClearAllPoints()
						quest.Check:Point("TOPRIGHT", quest.currentLine.Dash, "TOPLEFT", 0, 0)
					end
					quest.Check:SetTexture("Interface\\AddOns\\ElvUI_mMediaTag\\media\\misc\\check.tga")
					quest.Check:SetVertexColor(mQuestCompleteFontColor.r, mQuestCompleteFontColor.g, mQuestCompleteFontColor.b, 1)
				end

				quest.currentLine.Dash:SetHeight(quest.currentLine.Dash:GetStringHeight())

				if mQuestText then
					mQuestText = mQuestColors(mQuestText, quest.currentLine.Dash)
					if mQuestText then
						quest.currentLine.Text:SetText(mQuestText)
					end
				end
			end
			quest.currentLine.Text:SetHeight(quest.currentLine.Text:GetStringHeight())
		end
    end
end

local function mSenario()
	local mTitelEnable = E.db[mPlugin].mObjectiveTracker.quests.titel.enable
	local mTitelFont = LSM:Fetch('font', E.db[mPlugin].mObjectiveTracker.quests.titel.font)
	local mTitelFontSize = E.db[mPlugin].mObjectiveTracker.quests.titel.fontsize
	local mTitelFontFlag = E.db[mPlugin].mObjectiveTracker.quests.titel.fontflag
	local mTitelFontColor = {r = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor.r, g = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor.g, b = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor.b,}
	
	if E.db[mPlugin].mObjectiveTracker.quests.titel.fontstyle == "class" then
		mTitelFontColor = {r = mClassColor[1], g = mClassColor[2], b = mClassColor[3],}
	end

	local mQuestEnable = E.db[mPlugin].mObjectiveTracker.quests.other.enable
	local mQuestFont = LSM:Fetch('font', E.db[mPlugin].mObjectiveTracker.quests.other.font)
	local mQuestFontSize = E.db[mPlugin].mObjectiveTracker.quests.other.fontsize
	local mQuestFontFlag = E.db[mPlugin].mObjectiveTracker.quests.other.fontflag
	local mQuestFontColor = {r = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor.r, g = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor.g, b = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor.b,}
	
	if E.db[mPlugin].mObjectiveTracker.quests.other.fontstyle == "class" then
		mQuestFontColor = {r = mClassColor[1], g = mClassColor[2], b = mClassColor[3],}
	end

	local DashStyle = E.db[mPlugin].mObjectiveTracker.quests.questtext.dashstyle
	local DashCustom = E.db[mPlugin].mObjectiveTracker.quests.questtext.dashcustom

	if _G.ScenarioObjectiveBlock then
        local childs = {_G.ScenarioObjectiveBlock:GetChildren()}
        for _, child in pairs(childs) do
            if child.Text then
                child.Text:SetFont(mTitelFont, mTitelFontSize, mTitelFontFlag)

				if child.Check then
					child.Check:SetTexture("Interface\\AddOns\\ElvUI_mMediaTag\\media\\misc\\check.tga")
					child.Check:SetVertexColor(0, 1, 0, 1)
				end
				child.Text:SetHeight(child.Text:GetStringHeight())
            end
        end
    end
end

local function mSkinObjectiveTrackerFrame()
	local Frame = ObjectiveTrackerFrame.MODULES
	local _, numQuests = C_QuestLog.GetNumQuestLogEntries()
	local barstyle = E.db[mPlugin].mObjectiveTracker.titel.barstyle
	local BarColor = {r = mClassColor[1], g = mClassColor[2], b = mClassColor[3],}
	local TitelFont = LSM:Fetch('font', E.db[mPlugin].mObjectiveTracker.titel.font)
	local TitelFontSize = E.db[mPlugin].mObjectiveTracker.titel.fontsize
	local TitelFontFlag = E.db[mPlugin].mObjectiveTracker.titel.fontflag
	local mFontStyle = E.db[mPlugin].mObjectiveTracker.titel.fontstyle
	local BarYOffset = E.db[mPlugin].mObjectiveTracker.titel.baroffsety
	local BarXOffset = E.db[mPlugin].mObjectiveTracker.titel.baroffsetx
	local BarAnchor = E.db[mPlugin].mObjectiveTracker.titel.baranchor
	local HeaderFontColor = {r = mClassColor[1], g = mClassColor[2], b = mClassColor[3],}
	local mQuestEnable = E.db[mPlugin].mObjectiveTracker.quests.other.enable
	local mTitelEnable = E.db[mPlugin].mObjectiveTracker.quests.titel.enable
	local QuestAmount = E.db[mPlugin].mObjectiveTracker.titel.quests
	local ColorQuestAmount, ColorQuestAmountEnd = "", ""
	width = width + E.db[mPlugin].mObjectiveTracker.titel.barwidth

	if barstyle == "custom" then
		BarColor = {r = E.db[mPlugin].mObjectiveTracker.titel.barcolor.r, g = E.db[mPlugin].mObjectiveTracker.titel.barcolor.g, b = E.db[mPlugin].mObjectiveTracker.titel.barcolor.b,}
	end

	if mFontStyle == "custom" then
		HeaderFontColor = {r = E.db[mPlugin].mObjectiveTracker.titel.fontcolor.r, g = E.db[mPlugin].mObjectiveTracker.titel.fontcolor.g, b = E.db[mPlugin].mObjectiveTracker.titel.fontcolor.b,}
	end

	if QuestAmount == "colorleft" or QuestAmount == "colorright"then
		local cGr, cGg, cGb = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.good.r, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.good.g, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.good.b
		local cTr, cTg, cTb = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.transition.r, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.transition.g, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.transition.b
		local cBr, cBg, cBb = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.bad.r, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.bad.g, E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.bad.b
		local TempPercent = mMT:round((tonumber(numQuests)/tonumber(maxNumQuestsCanAccept))*100 or 0)
		local pr, pg, pb = E:ColorGradient(TempPercent * 0.01, cGr, cGg, cGb, cTr, cTg, cTb, cBr, cBg, cBb)

		ColorQuestAmount = E:RGBToHex(pr, pg, pb)
		ColorQuestAmountEnd = "|r"

		if QuestAmount == "colorright" then
			local HeaderText = format("%s [%s%s/%s%s]", HeaderTitel, ColorQuestAmount, numQuests, maxNumQuestsCanAccept, ColorQuestAmountEnd)
			ObjectiveTrackerBlocksFrame.QuestHeader.Text:SetText(HeaderText)
		else
			local HeaderText = format("[%s%s/%s%s] %s", ColorQuestAmount, numQuests, maxNumQuestsCanAccept, ColorQuestAmountEnd, HeaderTitel)
			ObjectiveTrackerBlocksFrame.QuestHeader.Text:SetText(HeaderText)
		end
	end

	if QuestAmount == "right" then
		local HeaderText = format("%s [%s/%s]", HeaderTitel, numQuests, maxNumQuestsCanAccept)
		ObjectiveTrackerBlocksFrame.QuestHeader.Text:SetText(HeaderText)
	elseif QuestAmount == "left" then
		local HeaderText = format("[%s/%s] %s", numQuests, maxNumQuestsCanAccept, HeaderTitel)
		ObjectiveTrackerBlocksFrame.QuestHeader.Text:SetText(HeaderText)
	end

	if (Frame) then
		for i = 1, #Frame do
			
			local Modules = Frame[i]
			if (Modules) then
				Modules.Header.Text:SetFont(TitelFont, TitelFontSize, TitelFontFlag)
				Modules.Header.Text:SetTextColor(HeaderFontColor.r, HeaderFontColor.g, HeaderFontColor.b)
				Modules.Header.Text:SetHeight(Modules.Header.Text:GetStringHeight())

				if not (Modules.IsSkinned) then
					if E.db[mPlugin].mObjectiveTracker.titel.barenable then
						local HeaderBar = CreateFrame("StatusBar", nil, Modules.Header)
						HeaderBar:SetFrameStrata("BACKGROUND")
						HeaderBar:SetSize(width, E.db[mPlugin].mObjectiveTracker.titel.barhigth)
						HeaderBar:SetPoint(BarAnchor, BarXOffset, BarYOffset)
						HeaderBar:SetStatusBarTexture(LSM:Fetch("statusbar", E.db[mPlugin].mObjectiveTracker.titel.texture))
						HeaderBar:SetStatusBarColor(BarColor.r, BarColor.g, BarColor.b)

						if E.db[mPlugin].mObjectiveTracker.titel.barshadow then
							HeaderBar:CreateShadow()
						end
					end
					
					if mQuestEnable or mTitelEnable then
						hooksecurefunc(Modules, "AddObjective", mFontSetting)
					end

					Modules.IsSkinned = true
				end
			end
		end
	end
	ObjectiveTrackerBlocksFrame.QuestHeader.Text:SetHeight(ObjectiveTrackerBlocksFrame.QuestHeader.Text:GetStringHeight())
end

local function mObjectiveTrackerOptions()
	E.Options.args.mMediaTag.args.general.args.objectivetracker.args = {
		objectivetrackerenable = {
			order = 1,
			type = 'toggle',
			name = L["Enable"],
			desc = L["Enable ObjectiveTracker (Questwatch) Skin."],
			get = function(info)
				return E.db[mPlugin].mObjectiveTracker.enable
			end,
			set = function(info, value)
				E.db[mPlugin].mObjectiveTracker.enable = value
				if value == true and E.private.skins.blizzard.objectiveTracker == false then
					E.private.skins.blizzard.objectiveTracker = true
				end
				E:StaticPopup_Show("CONFIG_RL")
			end,
		},
		objectivetrackertitel = {
			order = 10,
			type = "group",
			name = L['ObjectiveTracker Header'],
			disabled = function() return not E.db[mPlugin].mObjectiveTracker.enable end,
			args = {
				headertitle= {
					order = 200,
					type = "header",
					name = L["Title Bar"],
				},
				titlebarenable = {
					order = 210,
					type = 'toggle',
					name = L["Enable Title Bar"],
					desc = L["Enable ObjectiveTracker Title Bar"],
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.titel.barenable
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.titel.barenable = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
				},
				titlebarspacer1 = {
					order = 211,
					type = "description",
					name = "\n",
				},
				titlebartexture = {
					order = 212,
					type = "select",
					dialogControl = 'LSM30_Statusbar',
					name = L["Title Bar Texture"],
					values = LSM:HashTable('statusbar'),
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.titel.texture
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.titel.texture = value;
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
				},
				
				titlebaranchor = {
					order = 213,
					type = 'select',
					name = L["Anchor Point"],
					values = positionValues,
					get = function(info) return E.db[mPlugin].mObjectiveTracker.titel.baranchor end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.titel.baranchor = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
				},
				titlebarspacer2 = {
					order = 214,
					type = "description",
					name = "\n",
				},
				objectivetrackertitlebarcolorstyle = {
					order = 215,
					type = 'select',
					name = L["Title Bar Color Style"],
					get = function(info) return E.db[mPlugin].mObjectiveTracker.titel.barstyle end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.titel.barstyle = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
					values = {
						class = L["Class"],
						custom = L["Custom"],
					},
				},
				objectivetrackertitlebarcolor = {
					type = 'color',
					order = 216,
					name = L["Title Bar Color"],
					hasAlpha = false,
					get = function(info)
						local t = E.db[mPlugin].mObjectiveTracker.titel.barcolor
						return t.r, t.g, t.b
					end,
					set = function(info, r, g, b)
						local t = E.db[mPlugin].mObjectiveTracker.titel.barcolor
						t.r, t.g, t.b = r, g, b
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
				},
				titlebarspacer3 = {
					order = 217,
					type = "description",
					name = "\n",
				},
				titlebarhigth = {
					order = 218,
					name = L["Title Bar higth"],
					type = "range",
					min = 0, max = 128, step = 1,
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.titel.barhigth
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.titel.barhigth = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
				},
				titlebarwidth = {
					order = 219,
					name = L["Title Bar width"],
					type = "range",
					min = -512, max = 512, step = 1,
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.titel.barwidth
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.titel.barwidth = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
				},
				titlebarspacer4 = {
					order = 220,
					type = "description",
					name = "\n",
				},
				titlebaryOffset = {
					order = 221,
					type = 'range',
					name = L["Y-Offset"],
					min = -128, max = 128, step = 1,
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.titel.baroffsety
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.titel.baroffsety = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
				},
				titlebarxOffset = {
					order = 222,
					type = 'range',
					name = L["X-Offset"],
					min = -128, max = 128, step = 1,
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.titel.baroffsetx
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.titel.baroffsetx = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
				},
				titlebarspacer5 = {
					order = 223,
					type = "description",
					name = "\n",
				},
				titlebarshadow = {
					order = 224,
					type = 'toggle',
					name = L["Title Bar Shadow"],
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.titel.barshadow
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.titel.barshadow = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
				},
				titlebarspacer6 = {
					order = 225,
					type = "description",
					name = "\n",
				},
				titlequests = {
					order = 226,
					type = 'select',
					name = L["Show Quest Amount"],
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.titel.quests
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.titel.quests = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
					values = {
						none = L["None"],
						left = L["Left"],
						right = L["Right"],
						colorleft = L["Colorful left"],
						colorright = L["Colorful right"],
					},
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.titel.barenable end,
				},
				headertitlefont= {
					order = 300,
					type = "header",
					name = L["Title Font"],
				},
				titlefont = {
					type = 'select', dialogControl = 'LSM30_Font',
					order = 301,
					name = L["Default Font"],
					values = LSM:HashTable('font'),
					get = function(info) return E.db[mPlugin].mObjectiveTracker.titel.font end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.titel.font = value; end,
				},
				titlefontSize = {
					order = 302,
					name = L["Font Size"],
					type = 'range',
					min = 6, max = 64, step = 1,
					softMin = 8, softMax = 32,
					get = function(info) return E.db[mPlugin].mObjectiveTracker.titel.fontsize end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.titel.fontsize = value; end,
				},
				titlefontflag = {
					type = 'select',
					order = 303,
					name = L["Font contour"],
					values = mFontFlags,
					get = function(info) return E.db[mPlugin].mObjectiveTracker.titel.fontflag end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.titel.fontflag = value; end,
				},
				titlefontspacer5 = {
					order = 304,
					type = "description",
					name = "\n",
				},
				fontcolorstyle = {
					order = 305,
					type = 'select',
					name = L["Font Color Style"],
					get = function(info) return E.db[mPlugin].mObjectiveTracker.titel.fontstyle end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.titel.fontstyle = value; end,
					values = {
						class = L["Class"],
						custom = L["Custom"],
					},
				},
				titlefontcolor = {
					type = 'color',
					order = 306,
					name = L["Font Color"],
					hasAlpha = false,
					get = function(info)
						local t = E.db[mPlugin].mObjectiveTracker.titel.fontcolor
						return t.r, t.g, t.b
					end,
					set = function(info, r, g, b)
						local t = E.db[mPlugin].mObjectiveTracker.titel.fontcolor
						t.r, t.g, t.b = r, g, b
					end,
				},
			},
		},
		objectivetrackerquests = {
			order = 20,
			type = "group",
			name = L['ObjectiveTracker Quests'],
			disabled = function() return not E.db[mPlugin].mObjectiveTracker.enable end,
			args = {
				questsheadertitlefont= {
					order = 100,
					type = "header",
					name = L["Quests Title Font"],
				},
				queststitlefontenable = {
					order = 101,
					type = 'toggle',
					name = L["Quests Title Font"],
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.quests.titel.enable
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.quests.titel.enable = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
				},
				queststitlefont = {
					type = 'select', dialogControl = 'LSM30_Font',
					order = 102,
					name = L["Default Font"],
					values = LSM:HashTable('font'),
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.titel.font end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.quests.titel.font = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.titel.enable end,
				},
				queststitlefontSize = {
					order = 103,
					name = L["Font Size"],
					type = 'range',
					min = 6, max = 64, step = 1,
					softMin = 8, softMax = 32,
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.titel.fontsize end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.quests.titel.fontsize = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.titel.enable end,
				},
				queststitlefontflag = {
					type = 'select',
					order = 104,
					name = L["Font contour"],
					values = mFontFlags,
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.titel.fontflag end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.quests.titel.fontflag = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.titel.enable end,
				},
				queststitlefontspacer5 = {
					order = 105,
					type = "description",
					name = "\n",
				},
				queststitlefontcolorstyle = {
					order = 106,
					type = 'select',
					name = L["Font Color Style"],
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.titel.fontstyle end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.quests.titel.fontstyle = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.titel.enable end,
					values = {
						class = L["Class"],
						custom = L["Custom"],
					},
				},
				queststitlefontcolor = {
					type = 'color',
					order = 107,
					name = L["Font Color"],
					hasAlpha = false,
					get = function(info)
						local t = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor
						return t.r, t.g, t.b
					end,
					set = function(info, r, g, b)
						local t = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor
						t.r, t.g, t.b = r, g, b
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.titel.enable end,
				},
				questsheaderfont= {
					order = 200,
					type = "header",
					name = L["Quests Font"],
				},
				questsfontenable = {
					order = 201,
					type = 'toggle',
					name = L["Quests Font"],
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.quests.other.enable
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.quests.other.enable = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
				},
				questsfont = {
					type = 'select', dialogControl = 'LSM30_Font',
					order = 202,
					name = L["Default Font"],
					values = LSM:HashTable('font'),
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.other.font end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.quests.other.font = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.other.enable end,
				},
				questsfontSize = {
					order = 203,
					name = L["Font Size"],
					type = 'range',
					min = 6, max = 64, step = 1,
					softMin = 8, softMax = 32,
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.other.fontsize end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.quests.other.fontsize = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.other.enable end,
				},
				questsfontflag = {
					type = 'select',
					order = 204,
					name = L["Font contour"],
					values = mFontFlags,
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.other.fontflag end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.quests.other.fontflag = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.other.enable end,
				},
				questsfontspacer5 = {
					order = 205,
					type = "description",
					name = "\n",
				},
				questsfontcolorstyle = {
					order = 206,
					type = 'select',
					name = L["Font Color Style"],
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.other.fontstyle end,
					set = function(info, value) E.db[mPlugin].mObjectiveTracker.quests.other.fontstyle = value; end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.other.enable end,
					values = {
						class = L["Class"],
						custom = L["Custom"],
					},
				},
				questsfontcolor = {
					type = 'color',
					order = 207,
					name = L["Font Color"],
					hasAlpha = false,
					get = function(info)
						local t = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor
						return t.r, t.g, t.b
					end,
					set = function(info, r, g, b)
						local t = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor
						t.r, t.g, t.b = r, g, b
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.other.enable end,
				},
				questsfontspacer6 = {
					order = 208,
					type = "description",
					name = "\n",
				},
				questscompletefontcolor = {
					type = 'color',
					order = 209,
					name = L["Complete Font Color"],
					hasAlpha = false,
					get = function(info)
						local t = E.db[mPlugin].mObjectiveTracker.quests.other.completefontcolor
						return t.r, t.g, t.b
					end,
					set = function(info, r, g, b)
						local t = E.db[mPlugin].mObjectiveTracker.quests.other.completefontcolor
						t.r, t.g, t.b = r, g, b
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.other.enable end,
				},
				questsfontspacer7 = {
					order = 210,
					type = "description",
					name = "\n",
				},
				questsfailedfontcolor = {
					type = 'color',
					order = 211,
					name = L["Failed Font Color"],
					hasAlpha = false,
					get = function(info)
						local t = E.db[mPlugin].mObjectiveTracker.quests.other.failedfontcolor
						return t.r, t.g, t.b
					end,
					set = function(info, r, g, b)
						local t = E.db[mPlugin].mObjectiveTracker.quests.other.failedfontcolor
						t.r, t.g, t.b = r, g, b
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.other.enable end,
				},
			},
		},
		objectivetrackerquesttext = {
			order = 30,
			type = "group",
			name = L['ObjectiveTracker Progress'],
			disabled = function() return not E.db[mPlugin].mObjectiveTracker.enable end,
			args = {
				questtextdash= {
					order = 100,
					type = "header",
					name = L["Dash Style"],
				},
				questtextdashstyle = {
					order = 101,
					type = 'select',
					name = L["Dash Style"],
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.questtext.dashstyle end,
					set = function(info, value) 
							E.db[mPlugin].mObjectiveTracker.quests.questtext.dashstyle = value
							E:StaticPopup_Show("CONFIG_RL")
					end,
					values = {
						blizzard = L["Blizzard"],
						dot = L["Dot Texture"],
						custom = L["Custom"],
						none = L["None"],
					},
				},
				questtextdashtexture = {
					order = 102,
					type = 'select',
					name = L["Icon"],
					disabled = function() return not (E.db[mPlugin].mObjectiveTracker.quests.questtext.dashstyle == "dot") end,
					get = function(info) return E.db[mPlugin].mObjectiveTracker.quests.questtext.dashdotname end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.quests.questtext.dashdotname = value
						E.db[mPlugin].mObjectiveTracker.quests.questtext.dashdottexture = mIconsList[value].file
						E:StaticPopup_Show("CONFIG_RL")
					end,
					values = mTextureList(),
				},
				questtextdashcustom = {
					order = 103,
					name = L["Custom Dash Symbol"],
					desc = L["Custom Dash Symbol, enter any character you want."],
					type = 'input',
					width = 'smal',
					disabled = function() return not (E.db[mPlugin].mObjectiveTracker.quests.questtext.dashstyle == "custom") end,
					get = function() return E.db[mPlugin].mObjectiveTracker.quests.questtext.dashcustom end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.quests.questtext.dashcustom = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
				},
				questtextdashspacer1 = {
					order = 110,
					type = "description",
					name = "\n",
				},
				questtextprogress = {
					order = 120,
					type = "header",
					name = L["Progress Settings"],
				},
				questtextprogresspercent = {
					order = 121,
					type = 'toggle',
					name = L["Show Progress percent"],
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.percent
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.percent = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
				},
				questtextdashspacer2 = {
					order = 122,
					type = "description",
					name = "\n",
				},
				questtextprogressenable = {
					order = 123,
					type = 'toggle',
					name = L["Colorful Progress"],
					get = function(info)
						return E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.enable
					end,
					set = function(info, value)
						E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.enable = value
						E:StaticPopup_Show("CONFIG_RL")
					end,
				},
				questtextdashspacer3 = {
					order = 124,
					type = "description",
					name = "\n",
				},
				questtextprogresscolorgood = {
					type = 'color',
					order = 125,
					name = L["God Color"],
					hasAlpha = false,
					get = function(info)
						local t = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.good
						return t.r, t.g, t.b
					end,
					set = function(info, r, g, b)
						local t = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.good
						t.r, t.g, t.b = r, g, b
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.enable end,
				},
				questtextprogresscolortransition = {
					type = 'color',
					order = 126,
					name = L["Transit Color"],
					hasAlpha = false,
					get = function(info)
						local t = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.transition
						return t.r, t.g, t.b
					end,
					set = function(info, r, g, b)
						local t = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.transition
						t.r, t.g, t.b = r, g, b
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.enable end,
				},
				questtextprogresscolorbad = {
					type = 'color',
					order = 127,
					name = L["Bad Color"],
					hasAlpha = false,
					get = function(info)
						local t = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.bad
						return t.r, t.g, t.b
					end,
					set = function(info, r, g, b)
						local t = E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.bad
						t.r, t.g, t.b = r, g, b
						E:StaticPopup_Show("CONFIG_RL")
					end,
					disabled = function() return not E.db[mPlugin].mObjectiveTracker.quests.questtext.progress.enable end,
				},
			},
		},
	}
end

function mMT:mStartObjectiveTracker()
	if E.db[mPlugin].mObjectiveTracker.enable  == true then
		local mFontStyle = E.db[mPlugin].mObjectiveTracker.titel.fontstyle
		local HeaderFontColor = {r = E.db[mPlugin].mObjectiveTracker.titel.fontcolor.r, g = E.db[mPlugin].mObjectiveTracker.titel.fontcolor.g, b = E.db[mPlugin].mObjectiveTracker.titel.fontcolor.b,}
		if mFontStyle == "class" then
			HeaderFontColor = {r = mClassColor[1], g = mClassColor[2], b = mClassColor[3],}
		end

		local mTitelEnable = E.db[mPlugin].mObjectiveTracker.quests.titel.enable
		local mTitelFontColor = {r = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor.r, g = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor.g, b = E.db[mPlugin].mObjectiveTracker.quests.titel.fontcolor.b,}
		if E.db[mPlugin].mObjectiveTracker.quests.titel.fontstyle == "class" then
			mTitelFontColor = {r = mClassColor[1], g = mClassColor[2], b = mClassColor[3],}
		end

		local mQuestEnable = E.db[mPlugin].mObjectiveTracker.quests.other.enable
		local mQuestFontColor = {r = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor.r, g = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor.g, b = E.db[mPlugin].mObjectiveTracker.quests.other.fontcolor.b,}
		local mQuestCompleteFontColor = {r = E.db[mPlugin].mObjectiveTracker.quests.other.completefontcolor.r, g = E.db[mPlugin].mObjectiveTracker.quests.other.completefontcolor.g, b = E.db[mPlugin].mObjectiveTracker.quests.other.completefontcolor.b,}
		local mQuestFailedFontColor = {r = E.db[mPlugin].mObjectiveTracker.quests.other.failedfontcolor.r, g = E.db[mPlugin].mObjectiveTracker.quests.other.failedfontcolor.g, b = E.db[mPlugin].mObjectiveTracker.quests.other.failedfontcolor.b,}
		if E.db[mPlugin].mObjectiveTracker.quests.other.fontstyle == "class" then
			mQuestFontColor = {r = mClassColor[1], g = mClassColor[2], b = mClassColor[3],}
		end

		OBJECTIVE_TRACKER_COLOR = {
			["Normal"] = { r = mQuestFontColor.r, g = mQuestFontColor.g, b = mQuestFontColor.b },
			["NormalHighlight"] = { r = mQuestFontColor.r + .2, g = mQuestFontColor.g + .2, b = mQuestFontColor.b +.2 },
			["Failed"] = { r = mQuestFailedFontColor.r, g = mQuestFailedFontColor.g, b = mQuestFailedFontColor.b },
			["FailedHighlight"] = { r = mQuestFailedFontColor.r +.2, g = mQuestFailedFontColor.g +.2, b = mQuestFailedFontColor.b +.2},
			["Header"] = {r = mTitelFontColor.r, g = mTitelFontColor.g, b = mTitelFontColor.b},
			["HeaderHighlight"] = { r = mTitelFontColor.r +.2, g = mTitelFontColor.g +.2, b = mTitelFontColor.b +.2},
			["Complete"] = { r = mQuestCompleteFontColor.r, g = mQuestCompleteFontColor.g, b = mQuestCompleteFontColor.b},
			["TimeLeft"] = { r = DIM_RED_FONT_COLOR.r, g = DIM_RED_FONT_COLOR.g, b = DIM_RED_FONT_COLOR.b },
			["TimeLeftHighlight"] = { r = RED_FONT_COLOR.r, g = RED_FONT_COLOR.g, b = RED_FONT_COLOR.b },
		};
		OBJECTIVE_TRACKER_COLOR["Normal"].reverse = OBJECTIVE_TRACKER_COLOR["NormalHighlight"];
		OBJECTIVE_TRACKER_COLOR["NormalHighlight"].reverse = OBJECTIVE_TRACKER_COLOR["Normal"];
		OBJECTIVE_TRACKER_COLOR["Failed"].reverse = OBJECTIVE_TRACKER_COLOR["FailedHighlight"];
		OBJECTIVE_TRACKER_COLOR["FailedHighlight"].reverse = OBJECTIVE_TRACKER_COLOR["Failed"];
		OBJECTIVE_TRACKER_COLOR["Header"].reverse = OBJECTIVE_TRACKER_COLOR["HeaderHighlight"];
		OBJECTIVE_TRACKER_COLOR["HeaderHighlight"].reverse = OBJECTIVE_TRACKER_COLOR["Header"];
		OBJECTIVE_TRACKER_COLOR["TimeLeft"].reverse = OBJECTIVE_TRACKER_COLOR["TimeLeftHighlight"];
		OBJECTIVE_TRACKER_COLOR["TimeLeftHighlight"].reverse = OBJECTIVE_TRACKER_COLOR["TimeLeft"];
		OBJECTIVE_TRACKER_COLOR["Complete"] = OBJECTIVE_TRACKER_COLOR["Complete"];
		OBJECTIVE_TRACKER_COLOR["CompleteHighlight"] = OBJECTIVE_TRACKER_COLOR["Complete"];

		local DashStyle = E.db[mPlugin].mObjectiveTracker.quests.questtext.dashstyle

		if (DashStyle == "dot") then
			local TexturePath = E.db[mPlugin].mObjectiveTracker.quests.questtext.dashdottexture
			QuestDotIcon = mDashIcon(TexturePath)
		end
		
		hooksecurefunc("ObjectiveTracker_Update", mSkinObjectiveTrackerFrame)
		hooksecurefunc(_G.SCENARIO_CONTENT_TRACKER_MODULE, "UpdateCriteria", mSenario)
	end
end

table.insert(ns.Config, mObjectiveTrackerOptions)