local _, core = ...;
local AceSerializer = LibStub("AceSerializer-3.0");

function TableLength(T)
	local count = 0
	for _ in pairs(T) do count = count + 1 end
	return count
end

OnEnterSpellAdventure = function(self, motion)
	local anchor = self.Anchor or {"ANCHOR_LEFT", 0, 0};
	GameTooltip:SetOwner(self, anchor[1], anchor[2], anchor[3]);
	if self.infoSpell then
		local name = self.infoSpell.name;
		if self.addon and self.addon == "WCC" and self.infoSpell.note and self.infoSpell.note ~= "" then
			name = name.." ("..self.infoSpell.note..")";
		end
	
		if self.infoSpell.isEffect then
			if self.infoSpell.attributes.isPositive then
				GameTooltip:AddLine(name, 0, 1, 0);
			else
				GameTooltip:AddLine(name, 1, 0, 0);			
			end
			if self.infoSpell.attributes.isHidden then
				GameTooltip:AddLine(core.L["Effet caché"], 0.5, 0.5, 0.5);
			end
			local desc = self.infoSpell.desc;
			if (self.infoSpell.attributes.chargeMax ~= 0) then
				desc = desc.."\n|cffffffff"..self.infoSpell.attributes.chargeMax.." "..core.L["Charge(s) maximale(s)"];
			end
			if (self.infoSpell.attributes.duration ~= 0) then
				desc = desc.."\n|cffffffff"..self.infoSpell.attributes.duration.." "..core.L["tour(s) restant(s)"].."|r";
			end
			GameTooltip:AddLine(desc, 1, 0.82, 0, true);
			GameTooltip:AddTexture(self.infoSpell.icon, {width = 32, height = 32});
		else
			GameTooltip:AddLine(name, 1, 1, 1);
			GameTooltip:AddTexture(self.infoSpell.icon, {width = 16, height = 16});
			if self.infoSpell.isPassive then
				GameTooltip:AddLine(self.infoSpell.desc.."\n"..core.L["Passif"], 1, 0.82, 0, true);
			elseif self.infoSpell.cooldown == 0 then
				GameTooltip:AddLine(self.infoSpell.desc.."\n"..core.L["Sort de base"], 1, 0.82, 0, true);
			else
				GameTooltip:AddLine(self.infoSpell.desc.."\n|cffffffff"..self.infoSpell.cooldown.." "..core.L["Tour(s) de recharge"].."|r", 1, 0.82, 0, true);
			end
		end

		if self.isPlayer and not self.infoSpell.isPassive then
			if self.infoSpell.attributes.needTarget then
				GameTooltip:AddLine(" ");
				if self.isTargeting then
					GameTooltip:AddLine("|cffff0000"..core.L["ClickToCancel"].."|r", 0.6, 0.6, 0.6);
				else
					GameTooltip:AddLine(core.L["ClickThenChoose"], 0.6, 0.6, 0.6);
				end
			else
				GameTooltip:AddLine(" ");
				GameTooltip:AddLine(core.L["Instant"], 0.6, 0.6, 0.6);
			end
		elseif self.onEditSpell then
			GameTooltip:AddLine(" ");
			GameTooltip:AddLine("<"..core.L["Cliquer pour choisir une icone"]..">", 0, 1, 0);
		elseif self.OnEditUnit then
			GameTooltip:AddLine(" ");
			GameTooltip:AddLine("<"..core.L["Clique-gauche pour déplacer à gauche"]..">", 0, 1, 0);
			GameTooltip:AddLine("<"..core.L["Clique-droit pour déplacer à droite"]..">", 0, 1, 0);
		end
	else
		GameTooltip:AddLine(core.L["Compétence introuvable"], 1, 0, 0);
	end
	GameTooltip:Show();
end

OnEnterTooltipEnnemyAdventureNotFight = function(self, motion)
	local anchor = self.Anchor or {"ANCHOR_LEFT", 0, 0};
	GameTooltip:SetOwner(self, anchor[1], anchor[2], anchor[3]);
	local unit = self.unit or WC_Lib.SearchThingInAdventureByID(self.idUnit, 2, self.addon);
	
	local note = "";
	if self.addon == "WCC" and unit.note and unit.note ~= "" then
		note = " ("..unit.note..")";
	end
	GameTooltip:AddLine(unit.name..note, 1, 1, 1);
	GameTooltip:AddDoubleLine(core.L["Points de vie"]..core.L["2points"].."|cffffffff"..unit.pdv.."|r", core.L["Points d'attaque"]..core.L["2points"].."|cffffffff"..unit.damage.."|r");

	local firstSpell  = true;
	local firstEffect = true;
	for i = 1, #unit.spells do
		local spell = WC_Lib.SearchThingInAdventureByID(unit.spells[i], 3, self.addon);
		if spell then
			GameTooltip:AddLine(" ");
			if not spell.isEffect then
				if firstSpell == true then
					GameTooltip:AddLine(core.L["Sort(s)"]);
					firstSpell = false;
				end
				
				GameTooltip:AddLine(spell.name, 1, 1, 1);
				if (spell.isPassive == true) then
					GameTooltip:AddLine(spell.desc.."\n"..core.L["Passif"], 1, 0.82, 0, true);
				elseif (spell.cooldown == 0) then
					GameTooltip:AddLine(spell.desc.."\n"..core.L["Sort de base"], 1, 0.82, 0, true);
				else
					GameTooltip:AddLine(spell.desc.."\n|cffffffff"..spell.cooldown.." "..core.L["Tour(s) de recharge"].."|r", 1, 0.82, 0, true);
				end
				GameTooltip:AddTexture(spell.icon, {width = 32, height = 32});
			else
				if firstEffect == true then
					GameTooltip:AddLine(core.L["Effects"]);
					firstEffect = false;
				end
				
				GameTooltip:AddLine(spell.name, 1, 1, 1);
				if (spell.isPositive == true) then
					GameTooltip:AddLine(spell.name, 0, 1, 0);
				else
					GameTooltip:AddLine(spell.name, 1, 0, 0);
				end
				
				local displayPhrase = spell.desc;
				-- if (EffectCurrEnnemy[self.id][i].chargeEffect ~= nil and EffectCurrEnnemy[self.id][i].chargeEffect < spell.chargeMax) then
					-- displayPhrase = displayPhrase.."\n|cffffffff"..EffectCurrEnnemy[self.id][i].chargeEffect.." "..core.L["charge(s)"];
				-- end
				if (spell.duration ~= 0) then
					displayPhrase = displayPhrase.."\n|cffffffff"..spell.duration.." "..core.L["Tour(s) restant(s)"].."|r";
				end
				GameTooltip:AddLine(displayPhrase, 1, 0.82, 0, true);
				GameTooltip:AddTexture(spell.icon, {width = 32, height = 32});
			end
		end
	end
	GameTooltip:Show();
end

function WC_Lib.SearchThingInAdventureByID(id, idType, addon) -- 1 adventure ; 2 unit ; 3 spell
	if id == "0" or id == 0 then return nil end
	local list = {};
	if addon == "WC" then
		if idType == 1 then
			list = WC_AdventuresData.adventures;
		elseif idType == 2 then
			list = WC_AdventuresData.units;
		elseif idType == 3 then
			list = WC_AdventuresData.spells;		
		end
	elseif addon == "WCC" then
		if idType == 1 then
			list = YourAdventures;
		elseif idType == 2 then
			list = YourUnits;
		elseif idType == 3 then
			list = YourSpells;		
		end
	end
	for i = 1, #list do
		if list[i].id == id then
			return list[i];
		end
	end
	
	local strType = "";
	if idType == 1 then
		strType = "adventure";
	elseif idType == 2 then
		strType = "unit";
	elseif idType == 3 then
		strType = "spell or effect";
	end
	--print("|cffff0000[WC Error]: "..strType.." not found (id: "..(id or 'nil')..")");
	
	return nil;
end

function WC_Lib.SearchThingUnitInAdventure(idUnit, addon)
	if addon == "WC" then
		list = WC_AdventuresData.adventures;
	elseif addon == "WCC" then
		list = YourAdventures;
	end
	for i = 1, #list do
		for j = 1, #list[i].fights do
			for k = 1, #list[i].fights[j].mobs do
				if list[i].fights[j].mobs[k] == idUnit then
					return list[i];
				end
			end
			for k = 1, #list[i].fights[j].idPlayer do
				if list[i].fights[j].idPlayer[k] == idUnit then
					return list[i];
				end
			end
			for k = 1, #list[i].fights[j].idEnnemies do
				if list[i].fights[j].idEnnemies[k] == idUnit then
					return list[i];
				end
			end
		end
	end
	return nil;
end

function WC_Lib.SearchThingSpellInUnit(idSpell, addon)
	local list = {};
	if addon == "WC" then
		list = WC_AdventuresData.units;
	elseif addon == "WCC" then
		list = YourUnits;
	end
	for i = 1, #list do
		for j = 1, #list[i].spells do
			if list[i].spells[j] == idSpell then
				return list[i];
			end
		end
		for j = 1, #list[i].effects do
			if list[i].effects[j] == idSpell then
				return list[i];
			end
		end
	end
	return nil;
end

function WC_Lib.SearchThingUnitInTriggers(idUnit, addon)
	local list = {};
	if addon == "WC" then
		list = WC_AdventuresData.spells;
	elseif addon == "WCC" then
		list = YourSpells;
	end
	for i = 1, #list do
		for j = 1, #list[i].triggers.actions do
			if list[i].triggers.actions[j].mainParam == "SUMMON" and list[i].triggers.actions[j].params[1] == idUnit then
				return true;
			end
		end
	end
	return false;
end

function WC_Lib.SearchThingSpellInTriggers(idSpell, addon)
	local list = {};
	if addon == "WC" then
		list = WC_AdventuresData.spells;
	elseif addon == "WCC" then
		list = YourSpells;
	end
	for i = 1, #list do
		for j = 1, #list[i].triggers.actions do
			if list[i].triggers.actions[j].mainParam == "ADD_EFFECT" and list[i].triggers.actions[j].params[2] == idSpell then
				return true;
			end
		end
	end
	return false;
end

function DeleteInAdventure(id, idType, addon) -- 1 = adventures, 2 = units, 3 = spells
	local list = {};
	if addon == "WC" then
		if idType == 1 then
			list = WC_AdventuresData.adventures;
		elseif idType == 2 then
			list = WC_AdventuresData.units;
		elseif idType == 3 then
			list = WC_AdventuresData.spells;		
		end
	elseif addon == "WCC" then
		if idType == 1 then
			list = YourAdventures;
		elseif idType == 2 then
			list = YourUnits;
		elseif idType == 3 then
			list = YourSpells;		
		end
	end
	for i = 1, #list do
		if list[i].id == id then
			table.remove(list, i);
			break;
		end
	end
end

-- ===== LOAD NATIVE ADVENTURES ===== --
local function checkStatusImportAdventures(thing, idType)
	local list = {};
	if idType == 1 then
		list = WC_AdventuresData.adventures;
	elseif idType == 2 then
		list = WC_AdventuresData.units;
	elseif idType == 3 then
		list = WC_AdventuresData.spells;
	end
	for i = 1, #list do
		if (thing.id == list[i].id) then
			if (thing.av_settings.version == list[i].av_settings.version) then
				return 2;
			else
				return 1;
			end
		end
	end
	return 0;
end

local function OnImportAdventuresWC(thing, idType, bReplace)
	local list = {};
	if idType == 1 then
		list = WC_AdventuresData.adventures;
	elseif idType == 2 then
		list = WC_AdventuresData.units;
	elseif idType == 3 then
		list = WC_AdventuresData.spells;
	end

	if (bReplace ~= nil and bReplace == true) then
		for i = 1, #list do
			if (thing.id == list[i].id) then
				list[i] = thing;
				break;
			end
		end
	else
		table.insert(list, thing);
	end
end

function LoadAllAdventures()
	local localization = GetLocale();
	for i = 1, #WC_Lib.adventures do
		local strThing           = WC_Lib.TransformEnterLetter(WC_Lib.adventures[i], false);
		local bGood, arrayThings = AceSerializer:Deserialize(strThing);
		if (bGood == true) then
			for j = 1, #arrayThings do
				local bStatus = checkStatusImportAdventures(arrayThings[j].thing, arrayThings[j].idType); -- 0: Pas présent; 1: présent; 2: présent + même version					
				if (bStatus == 0) then
					OnImportAdventuresWC(arrayThings[j].thing, arrayThings[j].idType, false);
				elseif (bStatus == 1) then
					OnImportAdventuresWC(arrayThings[j].thing, arrayThings[j].idType, true);
				end
			end
		else
			return false;
		end
	end
	return true;
end

-- ===== IMPORT FUNCTIONS ===== --
local function OnImportThing(thing, idType, bReplace, addon)
	local list = nil;
	if addon == "WC" then
		if idType == 1 then
			list = WC_AdventuresData.adventures;
		elseif idType == 2 then
			list = WC_AdventuresData.units;
		elseif idType == 3 then
			list = WC_AdventuresData.spells;
		end
	elseif addon == "WCC" then
		if idType == 1 then
			list = YourAdventures;
		elseif idType == 2 then
			list = YourUnits;
			if not bReplace then
				thing.folder = WCCreator_Lib.structures.adventures.currentPathFolderUnits[#WCCreator_Lib.structures.adventures.currentPathFolderUnits];
			end
		elseif idType == 3 then
			list = YourSpells;
			if not bReplace then
				thing.folder = WCCreator_Lib.structures.adventures.currentPathFolderSpells[#WCCreator_Lib.structures.adventures.currentPathFolderSpells];
			end
		end
	end
	
	if list == nil then return end
	
	local found = 0;
	for i = 1, #list do
		if (thing.id == list[i].id) then
			list[i] = thing;
			found = i;
			break;
		end
	end
	if found == 0 then
		table.insert(list, thing);
	else
		if (bReplace ~= nil and bReplace == true) then
			if found > 0 then
				list[found] = thing;
			end
		end
	end
	if idType == 1 then
		if addon == "WC" and _G["WC_ListAdventures"] then
			RefreshListAdventures("WC");
		elseif addon == "WCC" and _G["WCC_ListAdventures"] then
			RefreshListAdventures("WCC");
		end
	elseif idType == 2 and addon == "WCC" then
		RefreshListUnits();
		local list = GetUnitsInOrderInFolder(WCCreator_Lib.structures.adventures.currentPathFolderUnits[#WCCreator_Lib.structures.adventures.currentPathFolderUnits]);
		local haveBtnInCurrentFolder = false;
		for i = 1, #list do
			if  _G["WCC_BtnUnit"..i] and _G["WCC_BtnUnit"..i]:IsShown() and _G["WCC_BtnUnit"..i].btn.infoUnit.id == thing.id then
				_G["WCC_BtnUnit"..i].btn:Click();
				haveBtnInCurrentFolder = true;
				break;
			end
		end
		if not haveBtnInCurrentFolder then
			if _G["WCC_UnitEditFrames"] then
				_G["WCC_UnitEditFrames"]:Hide();
			end
			oldSelectedUnit = {
				frameName = "",
				id        = "",
			};
		end
	elseif idType == 3 and addon == "WCC" then
		RefreshListSpells();
	end
	PlaySound("39673", "sfx");
end

local function checkSameVersionThing(thing, idType, addon)
	local thingInDB = WC_Lib.SearchThingInAdventureByID(thing.id, idType, addon);
	if (thingInDB ~= nil and thing.av_settings.version == thingInDB.av_settings.version) then
		return true;
	else
		return false;
	end
end

local function checkSameThing(thing, idType, addon)
	local list = nil;
	if addon == "WC" then
		if idType == 1 then
			list = WC_AdventuresData.adventures;
		elseif idType == 2 then
			list = WC_AdventuresData.units;
		elseif idType == 3 then
			list = WC_AdventuresData.spells;
		end
	elseif addon == "WCC" then
		if idType == 1 then
			list = YourAdventures;
		elseif idType == 2 then
			list = YourUnits;
		elseif idType == 3 then
			list = YourSpells;
		end
	end
	for i = 1, #list do
		if (thing.id == list[i].id) then
			return true;
		end
	end
	return false;
end

local function checkingImportThing(thing, idType, arrayThing, addon)
	if (checkSameThing(thing, idType, addon) == true) then
		if (checkSameVersionThing(thing, idType, addon) == true) then
			local message = nil;
			local title   = nil;
			if idType == 1 then
				title   = thing.title;
				message = core.L["Vous possedez déjà cette aventure avec la même version"];
			elseif idType == 2 then
				title   = thing.name;
				message = core.L["Vous possedez déjà ce personnage avec la même version"];
			elseif idType == 3 then
				title   = thing.name;
				message = core.L["Vous possedez déjà cette compétence avec la même version"];
			end
			local dialogSameGuideSameVersion = StaticPopup_Show("WC_ConfirmDialog", message..core.L["2points"].."|cFFF5CC00"..title.."|r (|cFFF5CC00v"..thing.av_settings.version.."|r).\n"..core.L["Importer"].."?");
			dialogSameGuideSameVersion.func = function()
				for i = 1, #arrayThing do
					OnImportThing(arrayThing[i].thing, arrayThing[i].idType, true, addon);
				end
			end
		else
			local message = nil;
			local title   = nil;
			if idType == 1 then
				title   = thing.title;
				message = core.L["Vous possedez déjà cette aventure avec une version différente"];
			elseif idType == 2 then
				title   = thing.name;
				message = core.L["Vous possedez déjà ce personnage avec une version différente"];
			elseif idType == 3 then
				title   = thing.name;
				message = core.L["Vous possedez déjà cette compétence avec une version différente"];
			end
			local thingInDB = WC_Lib.SearchThingInAdventureByID(thing.id, idType, addon);
			local DBTitle   = thingInDB.name;
			if idType == 1 then
				DBTitle = thingInDB.title;
			end
			local dialogSameGuideDiffVersion = StaticPopup_Show("WC_ConfirmDialog", message..core.L["2points"].."|cFFF5CC00"..title.."|r (|cFFF5CC00v"..thing.av_settings.version.."|r) - |cFFF5CC00"..DBTitle.."|r (|cFFF5CC00v"..thingInDB.av_settings.version.."|r) ("..core.L["possédé"]..").\n"..core.L["Importer"].."?");
			dialogSameGuideDiffVersion.func = function()
				for i = 1, #arrayThing do
					OnImportThing(arrayThing[i].thing, arrayThing[i].idType, true, addon);
				end
			end
		end
		return false;
	end
	return true;
end

local function checkArrayIsGood(arrayThing)
	if #arrayThing == 0 then
		return false;
	end
	for i = 1, #arrayThing do
		if not arrayThing[i].thing or not arrayThing[i].idType then
			return false;
		end
	end
	return true;
end

function BeforeImportAventures(strThing, idType, addon)
	strThing                = WC_Lib.TransformEnterLetter(strThing, false);
	local bGood, arrayThing = AceSerializer:Deserialize(strThing);
	if bGood == true and checkArrayIsGood(arrayThing) then
		if idType == arrayThing[1].idType then
			if (checkingImportThing(arrayThing[1].thing, arrayThing[1].idType, arrayThing, addon) == true) then
				for i = 1, #arrayThing do
					OnImportThing(arrayThing[i].thing, arrayThing[i].idType, false, addon);
				end
			end
		else
			local message = "";
			if idType == 1 then
				message = core.L["Le contenu n'est pas une aventure."];
			elseif idType == 2 then
				message = core.L["Le contenu n'est pas un personnage."];
			elseif idType == 3 then
				message = core.L["Le contenu n'est pas une compétence."];
			end
			UIErrorsFrame:AddMessage(message, 1, 0, 0);
			PlaySound("47355", "sfx", true);
		end
	else
		UIErrorsFrame:AddMessage(core.L["Impossible d'importer : erreur de désérialisation."], 1, 0, 0);
		PlaySound("47355", "sfx", true);
	end
end

function ShowPopupImportAdventures(idType, addon)
	if (_G["WC_PopupImportAdventures"] == nil) then
		local PopupImport = CreateFrame("Frame", "WC_PopupImportAdventures", UIParent, BackdropTemplateMixin and "BackdropTemplate");
		PopupImport:SetSize(550, 350);
		PopupImport:SetFrameLevel(519);
		PopupImport:SetMovable(true);
		PopupImport:EnableMouse(true);
		PopupImport:RegisterForDrag("LeftButton");
		PopupImport:SetScript("OnDragStart", PopupImport.StartMoving);
		PopupImport:SetScript("OnDragStop", PopupImport.StopMovingOrSizing);
		PopupImport:SetPoint("CENTER", UIParent, "CENTER");
		PopupImport:SetBackdrop({bgFile = "Interface/Collections/CollectionsBackgroundTile",
								edgeFile = "Interface/FriendsFrame/UI-Toast-Border",
								edgeSize = 16,
								insets = { left = 7, right = 5, top = 5, bottom = 6 }});
								
		PopupImport.close = CreateFrame("Button", nil, PopupImport, "UIPanelCloseButton");
		PopupImport.close:SetSize(25, 25);
		PopupImport.close:SetPoint("TOPRIGHT", PopupImport, "TOPRIGHT", -5, -5);
		PopupImport.close:SetFrameLevel(PopupImport:GetFrameLevel() + 1);
		PopupImport.close:SetScript("OnClick", function(self)
			PopupImport:Hide();
			PlaySound("854", "sfx");
		end);
		
		PopupImport.title = PopupImport:CreateFontString(nil, "OVERLAY", nil, PopupImport);
		PopupImport.title:SetFontObject("GameFontHighlightLarge");
		PopupImport.title:SetSize(PopupImport:GetWidth(), 0);
		PopupImport.title:SetPoint("TOP", PopupImport, "TOP", 0, -13);

		
		PopupImport.editBox = CreateFrame("Button", nil, PopupImport, BackdropTemplateMixin and "BackdropTemplate");
		PopupImport.editBox:SetSize(460, 225);
		PopupImport.editBox:SetPoint("BOTTOM", PopupImport, "BOTTOM", 0, 40);
		PopupImport.editBox:SetScript("OnClick", function(self) self.multiline:SetFocus() end);
		PopupImport.editBox:SetBackdrop({bgFile = [[Interface\GLUES\COMMON\Glue-Tooltip-Background]],
								edgeFile = [[Interface\GLUES\COMMON\TextPanel-Border]],
								edgeSize = 14,
								insets = {left = 5, right = 1, top = 1, bottom = 4},
													});
													
		PopupImport.text = PopupImport:CreateFontString(nil, "OVERLAY", nil, PopupImport);
		PopupImport.text:SetFontObject("GameFontNormal");
		PopupImport.text:SetSize(PopupImport.editBox:GetWidth(), 0);
		PopupImport.text:SetPoint("BOTTOMLEFT", PopupImport.editBox, "TOPLEFT", 0, 15);
		
		local scroll = CreateFrame("ScrollFrame", nil, PopupImport.editBox, "UIPanelScrollFrameTemplate");
		scroll:SetSize(PopupImport.editBox:GetWidth()-20, PopupImport.editBox:GetHeight()-15);
		scroll:SetPoint("CENTER", PopupImport.editBox, "CENTER", -4, 0);
		
		PopupImport.editBox.multiline = CreateFrame("EditBox", nil, editBox);
		PopupImport.editBox.multiline:SetMultiLine(true);
		PopupImport.editBox.multiline:SetAutoFocus(true);
		PopupImport.editBox.multiline:SetFontObject("GameFontWhite");
		PopupImport.editBox.multiline:SetWidth(435);
		PopupImport.editBox.multiline:SetScript("OnTextChanged", function(self)
			if (self:GetText() == "") then
				PopupImport.BtnGoImportGuide:Disable();
			else
				PopupImport.BtnGoImportGuide:Enable();
			end
		end);
		
		scroll:SetScrollChild(PopupImport.editBox.multiline);
		
		PopupImport.BtnGoImportGuide = CreateFrame("Button", nil, PopupImport, "UIPanelButtonTemplate");
		PopupImport.BtnGoImportGuide:SetSize(120, 25);
		PopupImport.BtnGoImportGuide:SetPoint("TOP", PopupImport.editBox, "BOTTOM", 0, -5);
		PopupImport.BtnGoImportGuide:Disable();
		PopupImport.BtnGoImportGuide:SetText(core.L["Importer"]);
		PopupImport.BtnGoImportGuide:SetScript("OnClick", function(self)
			BeforeImportAventures(PopupImport.editBox.multiline:GetText(), self:GetParent().idType, self:GetParent().addon)
			self:GetParent():Hide();
		end);
	end
	
	local titleText = "";
	local descText  = "";
	if idType == 1 then
		titleText = core.L["Importer une aventure"];
		descText  = core.L["Collez ci-dessous le code d'une aventure. Veuillez à toujours faire attention à ce que vous importez."];
	elseif idType == 2 then
		titleText = core.L["Importer un personnage"];
		descText  = core.L["Collez ci-dessous le code d'un personnage. Veuillez à toujours faire attention à ce que vous importez."];
	elseif idType == 3 then
		titleText = core.L["Importer une compétence"];
		descText  = core.L["Collez ci-dessous le code d'une compétence. Veuillez à toujours faire attention à ce que vous importez."];
	end
	_G["WC_PopupImportAdventures"].title:SetText(titleText);
	_G["WC_PopupImportAdventures"].text:SetText(descText);
	_G["WC_PopupImportAdventures"].editBox.multiline:SetText("");
	_G["WC_PopupImportAdventures"].idType = idType;
	_G["WC_PopupImportAdventures"].addon  = addon;
	_G["WC_PopupImportAdventures"]:Show();
	PlaySound("681", "sfx");
end

function FullImport(idType, addon)
	local loaded = C_AddOns.IsAddOnLoaded("WoWChallenger_ImpExport");
	if loaded then
		BeforeImportAventures(WoWChallenger_ImpExport, idType, addon, true);
	else
		StaticPopup_Show("WC_ImpExport_NOACTIVE");
	end
end