local _, core = ...;
core.libs = {};
core.nilPetsBg = nil;

local function tablelength(T)
	local count = 0
	for _ in pairs(T) do count = count + 1 end
	return count
end
core.libs.tablelength = tablelength;

local function getInfoByIdItem(idItem, idInfo)
	local tmp = Item:CreateFromItemID(idItem);
	local test = "Reload"
	tmp:ContinueOnItemLoad(function()
		test = {GetItemInfo(idItem)};
	end)
	---TEMP---
	-- if (test == "Reload") then
		-- return test;
	-- else
		-- return test[idInfo];
	-- end
	---END TEMP---
	return test[idInfo]--(tmp[idInfo]);
end
core.libs.getInfoByIdItem = getInfoByIdItem;
------- TRANSMO -------
local function getInfoByIdTransmog(idItem, stringInfo, modID)
	local appearanceID, sourceID = 0;
	if (modID ~= nil) then
		appearanceID, sourceID = C_TransmogCollection.GetItemInfo(idItem, modID);
	else
		appearanceID, sourceID = C_TransmogCollection.GetItemInfo(idItem);
	end
	local tmp = C_TransmogCollection.GetAppearanceSources(appearanceID);
	if (tmp ~= nil) then 
		return (tmp[1][stringInfo]);
	end
end
core.libs.getInfoByIdTransmog = getInfoByIdTransmog;

local function getAppearanceIDTransmog(idItem, modID)
	local appearanceID, sourceID = C_TransmogCollection.GetItemInfo(idItem, modID);
	return (appearanceID);
end
core.libs.getAppearanceIDTransmog = getAppearanceIDTransmog;

local function getCompletedTransmo(idItem)
	local _, sourceID = C_TransmogCollection.GetItemInfo(idItem);
	local _, _, _, _, completed, _, _, _ = C_TransmogCollection.GetAppearanceSourceInfo(sourceID);
	return (completed);
end
core.libs.getCompletedTransmo = getCompletedTransmo;

-------- PETS --------
local function getInfoByIdPet(idPet, idInfo)
	numPets = C_PetJournal.GetNumPets()
	for i = 1, numPets do
		local tmp = {C_PetJournal.GetPetInfoByIndex(i)};
		if (tmp[11] == idPet) then
			return (tmp[idInfo]);
		end
	end
	return "Err0r";
end
core.libs.getInfoByIdPet = getInfoByIdPet;

-------- MOUNTS --------
local function getInfoByIdMount(idMount, idInfo, extra)
	local tmp = {};
	if (extra ~= nil) then
		tmp = {C_MountJournal.GetMountInfoExtraByID(idMount)};
	else
		tmp = {C_MountJournal.GetMountInfoByID(idMount)};
	end
	return (tmp[idInfo]);
end
core.libs.getInfoByIdMount = getInfoByIdMount;

local function printCriteriaHF(hfID)
	local streturn = "";
	for i = 1, GetAchievementNumCriteria(hfID) do
		local getCriteria = {GetAchievementCriteriaInfo(hfID, i)}
		if (getCriteria[3] == true) then
			streturn = streturn.."|cff00ff00"..getCriteria[1]..'|r\n';
		else
			streturn = streturn..getCriteria[1]..'\n';
		end
	end
	return streturn;
end
core.libs.printCriteriaHF = printCriteriaHF;

--- COLOR ITEM ---
local function nameItemInColor(itemInfo, mode) -- 1 Tout; 2 Only icon; 3 Only text
	local ret = itemInfo[1];
	if (itemInfo[3] == 0) then
		ret = "|cff9d9d9d["..itemInfo[1].."]|r";
	elseif (itemInfo[3] == 1) then
		ret = "|cffffffff["..itemInfo[1].."]|r";
	elseif (itemInfo[3] == 2) then
		ret = "|cff1eff00["..itemInfo[1].."]|r";
	elseif (itemInfo[3] == 3) then
		ret = "|cff0070dd["..itemInfo[1].."]|r";
	elseif (itemInfo[3] == 4) then
		ret = "|cffa335ee["..itemInfo[1].."]|r";
	elseif (itemInfo[3] == 5) then
		ret = "|cffff8000["..itemInfo[1].."]|r";
	elseif (itemInfo[3] == 6) then
		ret = "|cffe6cc80["..itemInfo[1].."]|r";
	elseif (itemInfo[3] == 7 or itemInfo[3] == 8) then
		ret = "|cff00ccff["..itemInfo[1].."]|r";
	end
	if (itemInfo[10] ~= nil) then
		if (mode == 1) then
			ret = "|T"..itemInfo[10]..":16|t "..ret;
		elseif (mode == 2) then
			ret = "|T"..itemInfo[10]..":16|t";
		end
	end
	return ret;
end
core.libs.nameItemInColor = nameItemInColor;

local function printNPCDroppedLoot(loot)
	local stret = "";
	for i = 1, core.libs.tablelength(loot) do
		if (loot[i].pourcentageDrop ~= 0) then
			if (loot[i].pourcentageDrop == -1) then
				stret = stret..loot[i].nameNPC.." (??%)";
			else
				stret = stret..loot[i].nameNPC.." ("..loot[i].pourcentageDrop.."%)";
			end
		else
			stret = stret..loot[i].nameNPC;
		end
		if (i ~= core.libs.tablelength(loot)) then
			stret = stret.."|cffffffff, |r";
		end
	end
	return stret;
end
core.libs.printNPCDroppedLoot = printNPCDroppedLoot;

local function printNPCVendor(names)
	local stret = "";
	for i = 1, core.libs.tablelength(names) do
		stret = stret..names[i];
		if (i ~= core.libs.tablelength(names)) then
			stret = stret.."|cffffffff, |r";
		end
	end
	return stret;
end
core.libs.printNPCVendor = printNPCVendor;

local function printCompoCreate(create)
	local stret = "";
	for i = 1, core.libs.tablelength(create) do
		local compo = "";
		local item = Item:CreateFromItemID(create[i].compoId)
		item:ContinueOnItemLoad(function()
			compo = {GetItemInfo(create[i].compoId)};
		end)
		if (compo == "") then
			stret = stret.."Loading";
		else
			stret = stret..core.libs.nameItemInColor(compo, 1);
		end
		stret = stret.."|cffffffffx"..create[i].nbNeed.."|r";
		if (i ~= core.libs.tablelength(create)) then
			stret = stret.."|cffffffff, |r";
		end
	end
	return stret;
end
core.libs.printCompoCreate = printCompoCreate;

local function ifDoneNeed(pathTask)
	local pathSaved = {};
	local ret = false;
	for i = 1, #pathTask do
		pathSaved[i] = pathTask:sub(i, i)
	end
	local Saved = CreateFrame("Frame")
	Saved:RegisterEvent("ADDON_LOADED")
	function Saved:OnEvent(event, arg1)
		if event == "ADDON_LOADED" and arg1 == "WoWChallenger" then
			if (DoneMountTask[pathSaved[1]]["page"][pathSaved[2]]["step"][pathSaved[3]]["task"][pathSaved[4]]["done"] == false or DoneMountTask[pathSaved[1]]["page"][pathSaved[2]]["step"][pathSaved[3]]["task"][pathSaved[4]]["blank"] ~= nil) then
				ret = false;
			else
				ret = true;
			end
		end
	end
	Saved:SetScript("OnEvent", Saved.OnEvent);
	return ret;
end
core.libs.ifDoneNeed = ifDoneNeed;

local function ifDoneTask(task)
	if (task ~= nil) then
		if (task["hf"] ~= nil) then
			if (task["hf"][4] ~= true) then
				return false
			end
		elseif (task["quest"] ~= nil) then
			if (task["quest"].completed ~= true) then
				return false
			end
		end
		return true;
	end
	return false;
end
core.libs.ifDoneTask = ifDoneTask;

local function ifDoneStep(step)
	if (step ~= nil and step.task ~= nil) then
		for i = 1, tablelength(step.task) do
			if (step.task[i]["hf"] ~= nil) then
				if (step.task[i]["hf"][4] ~= true) then
					return false
				end
			elseif (step.task[i]["quest"] ~= nil) then
				if (step.task[i]["quest"].completed ~= true) then
					return false
				end
			elseif (step.task[i]["need"] ~= nil) then
				if (step.task[i]["need"].done ~= true) then
					return false
				end
			elseif (step.task[i]["custom"] ~= nil) then
				if (step.task[i]["custom"].done ~= true) then
					return false
				end
			end
		end
		return true;
	end
	return false;
end
core.libs.ifDoneStep = ifDoneStep;

local function ifDoneAllPrevStep(challengePage, stepID)
	if (challengePage ~= nil and challengePage.step ~= nil) then
		stepID = stepID - 1;
		while (stepID > 0) do
			if (ifDoneStep(challengePage.step[stepID]) ~= true) then
				return false
			end
			stepID = stepID - 1;
		end
		return true
	end
	return false;
end
core.libs.ifDoneAllPrevStep = ifDoneAllPrevStep;

local function ifDonePage(page)
	if (page ~= nil and page.step ~= nil) then
		for i = 1, tablelength(page.step) do
			if (ifDoneStep(page.step[i]) == false) then
				return false;
			end
		end
		return true;
	end
	return false;
end
core.libs.ifDonePage = ifDonePage;

local function ifDoneAllPrevPage(challenge, pageID)
	if (challenge ~= nil and challenge.page ~= nil) then
		pageID = pageID - 1;
		while (pageID > 0) do
			if (ifDonePage(challenge.page[pageID]) ~= true) then
				return false
			end
			pageID = pageID - 1;
		end
		return true
	end
	return false;
end
core.libs.ifDoneAllPrevPage = ifDoneAllPrevPage;

local function getPointsHFStep(step)
	local points = 0;
	if (step ~= nil and step.task ~= nil) then
		for i = 1, tablelength(step.task) do
			if (step.task[i]["type"] == "hf") then
				points = points + step.task[i]["hf"][3];
			end
		end
		return points;
	end
	return "ErrOr";
end
core.libs.getPointsHFStep = getPointsHFStep;

local function getLootTask(task)
	if (task ~= nil) then
		return task["hf"][11];
	end
	return "ErrOr";
end
core.libs.getLootTask = getLootTask;

local function getTotalPointsChallenge(challenge)
	local completed = 1;
	local pointsHF = 0;
	for i = 1, tablelength(challenge.tab) do
		if (challenge.tab[i].name == core.L["Alliance"] or challenge.tab[i].name == core.L["Horde"]) then
			local factionPlayer = UnitFactionGroup("player")
			if (factionPlayer == challenge.tab[i].faction) then
				for i2 = 1, tablelength(challenge.tab[i].page) do
					for i3 = 1, tablelength(challenge.tab[i].page[i2].step) do
						pointsHF = pointsHF + getPointsHFStep(challenge.tab[i].page[i2].step[i3]);
						if (ifDoneStep(challenge.tab[i].page[i2].step[i3]) == false) then
							completed = 0;
						end
					end
				end
			end
		else
			for i2 = 1, tablelength(challenge.tab[i].page) do
				for i3 = 1, tablelength(challenge.tab[i].page[i2].step) do
					pointsHF = pointsHF + getPointsHFStep(challenge.tab[i].page[i2].step[i3]);
					if (ifDoneStep(challenge.tab[i].page[i2].step[i3]) == false) then
						completed = 0;
					end
				end
			end
		end
	end
	if (completed == 1) then
		return "|cff00ff00"..pointsHF..core.L["HFPoints"].."|r\n";
	else
		return pointsHF..core.L["HFPoints"].."\n";
	end
end

local function getTotalLootsChallenge(challenge)
	local pointsHFstr = getTotalPointsChallenge(challenge);
	local lootHF = "";
	for i = 1, tablelength(challenge.tab) do
		if (challenge.tab[i].name == core.L["Alliance"] or challenge.tab[i].name == core.L["Horde"]) then
			local factionPlayer = UnitFactionGroup("player")
			if (factionPlayer == challenge.tab[i].faction) then
				for i2 = 1, tablelength(challenge.tab[i].page) do
					for i3 = 1, tablelength(challenge.tab[i].page[i2].step) do
						for i4 = 1, tablelength(challenge.tab[i].page[i2].step[i3].task) do
							if (challenge.tab[i].page[i2].step[i3].task[i4]["type"] == "hf") then
								if (ifDoneTask(challenge.tab[i].page[i2].step[i3].task[i4]) == true) then
									lootHF = lootHF.."|cff00ff00"..getLootTask(challenge.tab[i].page[i2].step[i3].task[i4]).."|r";
								else
									lootHF = lootHF..getLootTask(challenge.tab[i].page[i2].step[i3].task[i4]);
								end
								if (getLootTask(challenge.tab[i].page[i2].step[i3].task[i4]) ~= "") then
									lootHF = lootHF.."\n";
								end
							end
						end
					end
				end
			end
		else
			for i2 = 1, tablelength(challenge.tab[i].page) do
				for i3 = 1, tablelength(challenge.tab[i].page[i2].step) do
					for i4 = 1, tablelength(challenge.tab[i].page[i2].step[i3].task) do
						if (challenge.tab[i].page[i2].step[i3].task[i4]["type"] == "hf") then
							if (ifDoneTask(challenge.tab[i].page[i2].step[i3].task[i4]) == true) then
								lootHF = lootHF.."|cff00ff00"..getLootTask(challenge.tab[i].page[i2].step[i3].task[i4]).."|r";
							else
								lootHF = lootHF..getLootTask(challenge.tab[i].page[i2].step[i3].task[i4]);
							end
							if (getLootTask(challenge.tab[i].page[i2].step[i3].task[i4]) ~= "") then
								lootHF = lootHF.."\n";
							end
						end
					end
				end
			end
		end
	end
	return pointsHFstr..lootHF;
end
core.libs.getTotalLootsChallenge = getTotalLootsChallenge;

local function ifMAExalted(factionId)
	local friendshipInfo = {GetFriendshipReputation(factionId)};
	if (friendshipInfo[2] == 42000) then
		return true;
	end
	return false;
end
core.libs.ifMAExalted = ifMAExalted;

local function changeReputToTextMA(factionId)
	local friendshipInfo = {GetFriendshipReputation(factionId)};
	return friendshipInfo[5];
end
core.libs.changeReputToTextMA = changeReputToTextMA;

local function changeReputToText(reputation)
	local stateFaction = "Err0r";
	local valueMax = 0;
	local valueAct = 0;
	local factionInfo = {GetFactionInfoByID(reputation)}
	if (factionInfo[3] == 1) then
		stateFaction = getglobal("FACTION_STANDING_LABEL1");
		valueAct = factionInfo[6] + 42000
		valueMax = "36000";
	elseif (factionInfo[3] == 2) then
		stateFaction = getglobal("FACTION_STANDING_LABEL2");
		valueAct = factionInfo[6] + 6000
		valueMax = "3000";
	elseif (factionInfo[3] == 3) then
		stateFaction = getglobal("FACTION_STANDING_LABEL3");
		valueAct = factionInfo[6] + 3000
		valueMax = "3000";
	elseif (factionInfo[3] == 4) then
		stateFaction = getglobal("FACTION_STANDING_LABEL4");
		valueAct = factionInfo[6]
		valueMax = "3000";
	elseif (factionInfo[3] == 5) then
		stateFaction = getglobal("FACTION_STANDING_LABEL5");
		valueAct = factionInfo[6] - 3000
		valueMax = "6000";
	elseif (factionInfo[3] == 6) then
		stateFaction = getglobal("FACTION_STANDING_LABEL6");
		valueAct = factionInfo[6] - 9000
		valueMax = "12000";
	elseif (factionInfo[3] == 7) then
		stateFaction = getglobal("FACTION_STANDING_LABEL7");
		valueAct = factionInfo[6] - 21000
		valueMax = "21000";
	elseif (factionInfo[3] == 8) then
		stateFaction = getglobal("FACTION_STANDING_LABEL8");
		valueMax = "21000";
		valueAct = "21000";
	end
	return(stateFaction.." "..valueAct.."/"..valueMax)
end
core.libs.changeReputToText = changeReputToText;

local function heightBgTask(task)
	local height = 0;
	for i = 1, tablelength(task) do
		height = 40*i;
	end
	return height;
end
core.libs.heightBgTask = heightBgTask;

local function centerListObjectX(nb, nbmax, tailleImg)
	local x = 0;
	x =  (nb - 1) * tailleImg - nbmax * tailleImg / 2;
	return x;
end
core.libs.centerListObjectX = centerListObjectX;

local function centerListObjectXByWidth(nb, nbmax, width, tailleImg)
	local x = 0;
	x = (width - tailleImg * nbmax) / (nbmax + 1) * nb + tailleImg * (nb - 1);
	return x;
end
core.libs.centerListObjectXByWidth = centerListObjectXByWidth;

local function progressPourcent(challenge)
	local task = 0;
	local taskMax = 0;
	for i = 1, tablelength(challenge.tab) do
		if (challenge.tab[i].name == core.L["Alliance"] or challenge.tab[i].name == core.L["Horde"]) then
			local factionPlayer = UnitFactionGroup("player")
			if (factionPlayer == challenge.tab[i].faction) then
				for i2 = 1, tablelength(challenge.tab[i].page) do
					for i3 = 1, tablelength(challenge.tab[i].page[i2].step) do
						for i4 = 1, tablelength(challenge.tab[i].page[i2].step[i3].task) do
							if (ifDoneTask(challenge.tab[i].page[i2].step[i3].task[i4]) == true) then
								task = task + 1;
							end
							taskMax = taskMax + 1;
						end
					end
				end
			end
		else
			for i2 = 1, tablelength(challenge.tab[i].page) do
				for i3 = 1, tablelength(challenge.tab[i].page[i2].step) do
					for i4 = 1, tablelength(challenge.tab[i].page[i2].step[i3].task) do
						if (ifDoneTask(challenge.tab[i].page[i2].step[i3].task[i4]) == true) then
							task = task + 1;
						end
						taskMax = taskMax + 1;
					end
				end
			end
		end
	end
	if (taskMax == 0) then
		return (100);
	end
	return ((task/taskMax)*100);
end
core.libs.progressPourcent = progressPourcent;

local function checkFactionandClass(factionCollection, classCollection)
	local factionPlayer = UnitFactionGroup("player");
	if (factionPlayer ~= factionCollection and factionCollection ~= "Neutral") then
		return false;
	end
	if (classCollection ~= nil) then
		_, _, classIndex = UnitClass("player");
		for iclass = 1, #classCollection do
			if (classCollection[iclass] == classIndex) then
				return true;
			end
		end
		return false;
	end
	return true;
end
core.libs.checkFactionandClass = checkFactionandClass;

local function LeftButtonOnUpdate(self, elapsed)
	local x = GetCursorPosition();
	local newX = x - self.cursorX;
	local facing = self:GetFacing();
	self:SetFacing(facing + newX/100);
	self.cursorX = x;
end

local function ModelOnMouseDown(self,button)
	if button == "LeftButton" then
		self.cursorX = GetCursorPosition();
		self:SetScript("OnUpdate", LeftButtonOnUpdate)
	end
end
core.libs.ModelOnMouseDown = ModelOnMouseDown;

local function ModelOnMouseUp(self, button)
	self:SetScript("OnUpdate", nil)
end
core.libs.ModelOnMouseUp = ModelOnMouseUp;


-- DB toutes les quêtes et HF de l'addon pour refresh -- 1 = onglet HF ; 2 = onglet Mounts ; 3 = onglet Pets ; 4 = onglet Transmog
-- variable structure: {quest/hf id, onglets}
local WC_AllQuests = { {29145, 1}, {29195, 1}, {29196, 1}, {29197, 1}, {29198, 1}, {29199, 1},
						 {29200, 1}, {29201, 1}, {29181, 1}, {29272, 1}, {29283, 1}, {29214, 1},
						 {29245, 1}, {29249, 1}, {29254, 1}, {29279, 1}, {29203, 1}, {29298, 1},
						 {29302, 1}, {29303, 1}, {29310, 1}, {29311, 1}, {29281, 1}, {13667, 1},
						 {13718, 1}, {13717, 1}, {13714, 1}, {13716, 1}, {13715, 1}, {13668, 1},
						 {13697, 1}, {13721, 1}, {13720, 1}, {13722, 1}, {13719, 1}, {30252, 1},
						 {30535, 1}, {30254, 1}, {30255, 1}, {30256, 1}, {30257, 1}, {31945, 1},
						 {30260, 1}, {30516, 1}, {30523, 1}, {30524, 1}, {30529, 1}, {32682, 1},
						 {31338, 1}, {31339, 1}, {31340, 1}, {31341, 1}, {31534, 1}, {31537, 1},
						 {31538, 1}, {30517, 1}, {30518, 1}, {31947, 1}, {30521, 1}, {31320, 1},
						 {31321, 1}, {31322, 1}, {31323, 1}, {31529, 1}, {31530, 1}, {31531, 1},
						 {31532, 1}, {31521, 1}, {31311, 1}, {31470, 1}, {31472, 1}, {31475, 1},
						 {31478, 1}, {31479, 1}, {9739, 1}, {9743, 1}, {9919, 1}, {9806, 1},
						 {9726, 1}, {29691, 1}, {9729, 1}, {28100, 1}, {27989, 1}, {27994, 1},
						 {27995, 1}, {28338, 1}, {28366, 1}, {28362, 1}, {28364, 1}, {28521, 1},
						 {28524, 1}, {28460, 1}, {28464, 1}, {28467, 1}, {28530, 1}, {28469, 1},
						 {28470, 1}, {28472, 1}, {9835, 1}, {10115, 1}, {10116, 1}, {9792, 1},
						 {9888, 1}, {50343, 2}, {50553, 2}, {53347, 2}, {50393, 2}, {50394, 2},
						 {50402, 2}, {52305, 2}, {50395, 2}, {50401, 2}, {50412, 2}, {52447, 2},
						 {50396, 2}, {50886, 2}, {50887, 2}, {50900, 2}, {52748, 2}, {50397, 2},
						 {50940, 2}, {50942, 2}, {50943, 2}, {50944, 2}, {56205, 2}, {55530, 2},
						 {55529, 2}, {55983, 2}, {55529, 2}, {45470, 2}, {47207, 2}, {47208, 2},
						 {47209, 2}, {47210, 2}, {47211, 2}, {47212, 2}, {47213, 2}, {58802, 2},
						 {58803, 2}, {58804, 2}, {58807, 2}, {58809, 2}, {58808, 2}, {58810, 2},
						 {58811, 2}, {58812, 2}, {58813, 2}, {58825, 2}, {58817, 2}, {58818, 2},
						 {58826, 2}, {58829, 2}, {58863, 2}, {58865, 2}, {43730, 2}, {43731, 2},
						 {43732, 2}, {43733, 2}, {43734, 2}, {43735, 2}, {43736, 2}, {43737, 2},
						 {43760, 2}, {43761, 2}, {58076, 3}, {53817, 3}, {53816, 3}, {53818, 3},
						 {53819, 3}, {53815, 3}, {50098, 3}, {50099, 3}, {50100, 3}, {50101, 3},
						 {50102, 3}, {50103, 3}, {50104, 3}, {50105, 3}, {50106, 3}, {50107, 3},
						 {50108, 3}, {50109, 3}, {50140, 3}, {50141, 3}, {50142, 3}, {50143, 3},
						 {50144, 3}, {50145, 3}, {50146, 3}, {50147, 3}, {52819, 3}, {52809, 3},
						 {52810, 3}, {52818, 3}, {52817, 3}, {52816, 3}, {52815, 3}, {52814, 3},
						 {52813, 3}, {52812, 3}, {53632, 3}, {53633, 3}, {53634, 3}, {52827, 3},
						 {52822, 3}, {52823, 3}, {52824, 3}, {52826, 3}, {60605, 3}, {60606, 3},
						 {60614, 3}, {60615, 3}, {60616, 3}, {60617, 3}, {60619, 3}, {61839, 2},
						 {61840, 2}, {61842, 2}, {61844, 2}, {62044, 2}, {62045, 2}, {57205, 4},
						 {44093, 4}, {44094, 4}, {44095, 4}, {44096, 4}, {44097, 4}, {44159, 4}
						};
local WC_AllHF = { {5869, 1}, {5868, 1}, {5862, 1}, {5864, 1}, {5865, 1}, {5861, 1},
					 {5867, 1}, {5872, 1}, {5870, 1}, {5866, 1}, {5879, 1}, {5871, 1},
					 {5874, 1}, {5873, 1}, {5859, 1}, {2756, 1}, {2758, 1}, {2782, 1},
					 {2836, 1}, {2770, 1}, {2817, 1}, {2772, 1}, {2781, 1}, {2764, 1},
					 {2777, 1}, {2760, 1}, {2780, 1}, {2763, 1}, {2778, 1}, {2761, 1},
					 {2779, 1}, {2762, 1}, {2788, 1}, {2771, 1}, {2816, 1}, {2783, 1},
					 {2765, 1}, {2787, 1}, {2769, 1}, {2786, 1}, {2768, 1}, {2785, 1},
					 {2767, 1}, {2784, 1}, {2766, 1}, {2144, 1}, {911, 1}, {914, 1},
					 {912, 1}, {915, 1}, {1396, 1}, {6006, 1}, {910, 1}, {626, 1},
					 {1552, 1}, {1281, 1}, {937, 1}, {913, 1}, {2676, 1}, {2418, 1},
					 {2436, 1}, {2576, 1}, {2416, 1}, {2419, 1}, {2421, 1}, {2422, 1},
					 {2798, 1}, {1022, 1}, {1023, 1}, {1024, 1}, {6008, 1}, {6011, 1},
					 {1034, 1}, {1028, 1}, {1029, 1}, {1030, 1}, {6007, 1}, {6013, 1},
					 {1035, 1}, {1145, 1}, {263, 1}, {271, 1}, {272, 1}, {1038, 1},
					 {966, 1}, {963, 1}, {969, 1}, {972, 1}, {255, 1}, {981, 1},
					 {1261, 1}, {283, 1}, {288, 1}, {289, 1}, {1040, 1}, {291, 1},
					 {292, 1}, {1656, 1}, {260, 1}, {1279, 1}, {1695, 1}, {1697, 1},
					 {1702, 1}, {1703, 1}, {1188, 1}, {1291, 1}, {1696, 1}, {1699, 1},
					 {1701, 1}, {1704, 1}, {1693, 1}, {1791, 1}, {1789, 1}, {1786, 1},
					 {1788, 1}, {1792, 1}, {1790, 1}, {1793, 1}, {1185, 1}, {295, 1},
					 {1936, 1}, {2796, 1}, {303, 1}, {1683, 1}, {273, 1}, {1255, 1},
					 {277, 1}, {1687, 1}, {1688, 1}, {1690, 1}, {252, 1}, {1282, 1},
					 {279, 1}, {1686, 1}, {1689, 1}, {1691, 1}, {2497, 1}, {2420, 1},
					 {1026, 1}, {1025, 1}, {1027, 1}, {6009, 1}, {6012, 1}, {1036, 1},
					 {1032, 1}, {1031, 1}, {1033, 1}, {6010, 1}, {6014, 1}, {1037, 1},
					 {1039, 1}, {965, 1}, {967, 1}, {968, 1}, {1041, 1}, {1280, 1},
					 {1698, 1}, {1791, 1}, {259, 1}, {1685, 1}, {12951, 1}, {12891, 1},
					 {13467, 1}, {13163, 1}, {13504, 1}, {12954, 1}, {12510, 1}, {12515, 1},
					 {13076, 1}, {12081, 1}, {12066, 1}, {12243, 1}, {12414, 1}, {12076, 1},
					 {12242, 1}, {12291, 1}, {13557, 1}, {13553, 1}, {14013, 1}, {14014, 1},
					 {12957, 1}, {12509, 1}, {12518, 1}, {13077, 1}, {12292, 1}, {10059, 1},
					 {12245, 1}, {12415, 1}, {10778, 1}, {11340, 1}, {12244, 1}, {12413, 1},
					 {12950, 1}, {12479, 1}, {13466, 1}, {13161, 1}, {13503, 1}, {12949, 1},
					 {12478, 1}, {13206, 1}, {14002, 1}, {8935, 1}, {9833, 1}, {10348, 1},
					 {9564, 1}, {10350, 1}, {10018, 1}, {11188, 1}, {11189, 1}, {11157, 1},
					 {10672, 1}, {10994, 1}, {11190, 1}, {11543, 1}, {11545, 1}, {11446, 1},
					 {12988, 1}, {12593, 1}, {13144, 1}, {12947, 1}, {12989, 1}, {13712, 1},
					 {13776, 1}, {13250, 1}, {9923, 1}, {9562, 1}, {10349, 1}, {7292, 1},
					 {7293, 1}, {7294, 1}, {7295, 1}, {6544, 1}, {6552, 1}, {7306, 1},
					 {7325, 1}, {7300, 1}, {7301, 1}, {7302, 1}, {7303, 1}, {7304, 1},
					 {7305, 1}, {942, 1}, {900, 1}, {944, 1}, {899, 1}, {943, 1},
					 {901, 1}, {13062, 2}, {6402, 3}
	};
local WC_AllMounts = { {1057, 2}, {1013, 2}, {1258, 2}, {1260, 2}, {1028, 2}, {947, 2}, {1320, 2}, {838, 2}, {1397, 2}, {1362, 2}, {1360, 2}, {1414, 2} };
local WC_AllTransmo = { {core.libs.getAppearanceIDTransmog(162690), 4}, {core.libs.getAppearanceIDTransmog(152094), 4}, {core.libs.getAppearanceIDTransmog(151524), 4},
						{core.libs.getAppearanceIDTransmog(153115), 4}, {core.libs.getAppearanceIDTransmog(155880), 4}, {core.libs.getAppearanceIDTransmog(141006, 1), 4},
						{core.libs.getAppearanceIDTransmog(180273), 4}, {core.libs.getAppearanceIDTransmog(128935, 32), 4}, {core.libs.getAppearanceIDTransmog(128819, 32), 4},
						{core.libs.getAppearanceIDTransmog(128911, 30), 4}, {core.libs.getAppearanceIDTransmog(127829, 30), 4}, {core.libs.getAppearanceIDTransmog(128832, 26), 4},
						{core.libs.getAppearanceIDTransmog(128861, 30), 4}, {core.libs.getAppearanceIDTransmog(128826, 25), 4}, {core.libs.getAppearanceIDTransmog(128808, 25), 4},
						{core.libs.getAppearanceIDTransmog(128942, 21), 4}, {core.libs.getAppearanceIDTransmog(128943, 29), 4}, {core.libs.getAppearanceIDTransmog(128941, 25), 4},
						{core.libs.getAppearanceIDTransmog(128910, 29), 4}, {core.libs.getAppearanceIDTransmog(128908, 32), 4}, {core.libs.getAppearanceIDTransmog(128289, 23), 4},
						{core.libs.getAppearanceIDTransmog(128870, 27), 4}, {core.libs.getAppearanceIDTransmog(128872, 29), 4}, {core.libs.getAppearanceIDTransmog(128476, 31), 4},
						{core.libs.getAppearanceIDTransmog(128868, 22), 4}, {core.libs.getAppearanceIDTransmog(128825, 30), 4}, {core.libs.getAppearanceIDTransmog(128827, 30), 4},
					};

local function refreshUIAuto(item_id, item_type, nbTab)
	if (item_type == 2) then
		for i = 1, #WC_AllQuests do
			if (WC_AllQuests[i][1] == item_id) then
				if (WC_AllQuests[i][2] == nbTab) then
					return true
				else
					return false;
				end
			end
		end
		return false;
	elseif (item_type == 1) then
		for i = 1, #WC_AllHF do
			if (WC_AllHF[i][1] == item_id) then
				if (WC_AllHF[i][2] == nbTab) then
					return true
				else
					return false;
				end
			end
		end
		return false;
	elseif (item_type == 3) then
		for i = 1, #WC_AllMounts do
			if (WC_AllMounts[i][1] == item_id) then
				if (WC_AllMounts[i][2] == nbTab) then
					return true
				else
					return false;
				end
			end
		end
		return false;
	elseif (item_type == 4) then
		for i = 1, #WC_AllTransmo do
			if (WC_AllTransmo[i][1] == item_id) then
				if (WC_AllTransmo[i][2] == nbTab) then
					return true
				else
					return false;
				end
			end
		end
		return false;
	end
	return false;
end
core.libs.refreshUIAuto = refreshUIAuto;