-- ==================================================================================================================== --
--															--
--	File			Absorbs.lua ( modification of Interrupt.lua )						--
--															--
--															--
--	Author			Zarnivoop						| Basis, thx	|		--
--															--
--										| Version	   :	 12.0.1 |	--
--										| Curse-Project-ID :	  17718 |	--
--										| Wago-ID	   :   Q6aEVa6W |	--
--										| License	   :	  MIT/X |	--
--															--
--															--
--				Baltha							| Revision	|		--
--										| Version	   :	 12.0.1 |	--
--										| Curse-Project-ID :	1188318 |	--
--										| License	   :	  MIT/X |	--
--															--
--															--
--										| Initial Version  : 2024-11-18 |	--
--										| Current Version  : 2026-05-13 |	--
--										|		   : Release	|	--
--															--
--															--
--	Path ( Revision )	"..\World of Warcraft\_retail_\Interface\AddOns\Skada\Misc\Changelog\ChangeLog.txt"	--
--															--
-- ==================================================================================================================== --


local _, Skada	   = ...


local ModuleBase   = Skada.ModuleBase
local SecretHelper = Skada.SecretHelper


	-- ========================
	-- | hint: absorb effects |
	-- ========================

	-- | Absorption is a wide avoidance mechanic available to both NPCs and players. It is most commonly triggered by spells and items.
	-- |
	-- | Absorb can be general or school-specific:
	-- | Spells such as Power Word: Shield, Sacrifice, or Ice Barrier allow general absorption (Physical and all spell schools).
	-- | Items such as Fire Protection Potions and spells such as [Frost Ward] allow absorption of a specific spell school.
	-- |
	-- | Absorbing the damage of a spell does not make the player avoid the secondary effects of a spell (such as snares, etc.), except for pushback.
	-- | In addition to damage absorption, some enemies also inflict healing absorbs on players. These will absorb healing done to players, letting damage go through normally.
	-- | Heal through the healing absorb, then once the absorb has been depleted, healing will function normally to restore players' health.
 	-- |
	-- | e.g. https://warcraft.wiki.gg/wiki/Absorb


-- ==========================
-- | outer function : start |
-- ==========================
Skada:AddLoadableModule("Absorb", nil, function(Skada, L)

	if Skada.db.profile.modulesBlocked.Absorb then return end


	local mod	  = Skada:NewModule(L["Absorb"])
	local playermod	  = Skada:NewModule(L["Absorb spells"])


	-- ===============================================================================
	-- | e.g. https://warcraft.wiki.gg/wiki/API_C_DamageMeter.GetCombatSessionFromID |
	-- |										 |
	-- | Enum.DamageMeterType							 |
	-- |										 |
	-- |		Value	4							 |
	-- |		Field	Absorbs							 |
	-- ===============================================================================
	local DAMAGE_TYPE = 4


	function playermod:Enter(win, id, label)

		playermod.playerid = id
		playermod.title	   = tostring(label) .. L["'s Absorbs"]
	end




	function playermod:Update(win, set)

		ModuleBase:UpdateSpellList(win, self.playerid, set, DAMAGE_TYPE)
	end




	function mod:Update(win, set)

		ModuleBase:UpdateSimpleList(win, set,

							{

								     damageType = DAMAGE_TYPE		,
								       valueKey = "totalAmount"

							}

					   )

	end




	function mod:OnEnable()

		mod.metadata = {click1 = playermod, showspots = true, icon = "Interface\\Icons\\spell_shadow_antimagicshell"}


		Skada:AddMode(self)
	end




	function mod:OnDisable()

		Skada:RemoveMode(self)
	end




	function mod:AddToTooltip(set, tooltip)

		local total = ModuleBase:GetSetTotal(set, DAMAGE_TYPE)


		GameTooltip:AddDoubleLine("Absorbs", Skada:FormatNumberSecret(total), 1, 1, 1)
	end




	function mod:FormatSetSummary(datasetItem, set)

		local total = ModuleBase:GetSetTotal(set, DAMAGE_TYPE)


		Skada:FormatValueText(datasetItem, Skada:FormatNumberSecret(total), true)
	end

end)
-- ========================
-- | outer function : end |
-- ========================