local ElvUI_EltreumUI, E, L, V, P, G = unpack(select(2, ...))

local instancedifficulty = CreateFrame("FRAME")
instancedifficulty:SetSize(40, 40)
instancedifficulty:SetPoint("CENTER", _G.Minimap , -50, 50)
instancedifficulty:Hide()
instancedifficulty.Text = instancedifficulty:CreateFontString(nil,"ARTWORK")
instancedifficulty:RegisterEvent("ZONE_CHANGED_NEW_AREA")
instancedifficulty:RegisterEvent("PLAYER_ENTERING_WORLD")
E:CreateMover(instancedifficulty, "MoverEltruismInstanceDifficulty", "EltruismInstanceDifficulty", nil, nil, nil, "ALL,SOLO,PARTY,RAID")
instancedifficulty:SetScript("OnEvent", function(_,event)
	local _, instanceType = IsInInstance()
	if (instanceType == "raid" or instanceType == "party" or instanceType == "scenario") and E.db.ElvUI_EltreumUI.instances.enable then
		instancedifficulty:Show()
		instancedifficulty.Text:Show()
		instancedifficulty.Text:SetFont(E.LSM:Fetch('font', E.db.general.font), E.db.ElvUI_EltreumUI.instances.fontsize, E.db.general.fontStyle)
		instancedifficulty.Text:SetTextColor(E.db.ElvUI_EltreumUI.instances.r, E.db.ElvUI_EltreumUI.instances.g, E.db.ElvUI_EltreumUI.instances.b)
		instancedifficulty.Text:SetPoint("CENTER", _G["MoverEltruismInstanceDifficulty"])
		instancedifficulty.Text:SetParent(_G.Minimap)
		local DifficultyID = select(3, GetInstanceInfo())  --https://wowpedia.fandom.com/wiki/DifficultyID
		if DifficultyID == 1 then
			instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.DungeonNormal)
		elseif DifficultyID == 2 then
			instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.DungeonHeroic)
		elseif DifficultyID == 23 then
			instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.DungeonMythic)
		elseif DifficultyID == 8 then
			local keylevel = C_ChallengeMode.GetActiveKeystoneInfo()
			if keylevel == 0 then
				instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.DungeonMythicPlus)
			else
				instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.DungeonMythicPlus.." +"..keylevel)
			end
		elseif DifficultyID == 24 then
			instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.DungeonTimewalker)
		elseif DifficultyID == 3 or DifficultyID == 4 or DifficultyID == 9 or DifficultyID == 14 or DifficultyID == 173 then
			instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.Raid)
		elseif DifficultyID == 5 or DifficultyID == 6 or DifficultyID == 174 or DifficultyID == 15 or DifficultyID == 148 or DifficultyID == 175 or DifficultyID == 176 then
			instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.RaidHeroic)
		elseif DifficultyID == 16 then
			instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.MythicRaid)
		elseif DifficultyID == 7 or DifficultyID == 17 then
			instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.RaidLFR)
		elseif DifficultyID == 33 then
			instancedifficulty.Text:SetText(E.db.ElvUI_EltreumUI.instances.RaidTimewalker)
		--else
			--print("unknown instance type")
			--instancedifficulty.Text:SetText(DifficultyID)
		end
		if E.Retail then
			if _G["MiniMapInstanceDifficulty"] and (_G["MiniMapInstanceDifficulty"]:IsShown() == true or _G["MiniMapInstanceDifficulty"]:GetAlpha() == 1) then
				_G["MiniMapInstanceDifficulty"]:SetAlpha(0)
			end
			if _G["MiniMapChallengeMode"] and (_G["MiniMapChallengeMode"]:IsShown() == true or _G["MiniMapChallengeMode"]:GetAlpha() == 1) then
				_G["MiniMapChallengeMode"]:SetAlpha(0)
			end
			if _G["GuildInstanceDifficulty"] and (_G["GuildInstanceDifficulty"]:IsShown() == true or _G["GuildInstanceDifficulty"]:GetAlpha() == 1) and _G["GuildFrameTabardEmblem"] then
				local normaltext = instancedifficulty.Text:GetText()
				instancedifficulty.Text:SetText(normaltext.." "..E.db.ElvUI_EltreumUI.instances.guild)
				_G["GuildInstanceDifficulty"]:SetAlpha(0)
			end
		end
		instancedifficulty:Show()
	else
		instancedifficulty:Hide()
		instancedifficulty.Text:Hide()
	end
end)
