if (UnitLevel("player") == 70) then
	return;
end

local f = InfoPanel_AddPlugin();
local startTime = GetTime();
local XP, maxXP, restXP;
local lastXP, lastMaxXP = 0;
local sessionXP, xpGain = 0

--------------------------------------------------------------------------------------------------------
--                                              Functions                                             --
--------------------------------------------------------------------------------------------------------

-- OnEnter
local function OnEnter(self)
	InfoPanel_MakeTip(f,"경험치 정보");

	GameTooltip:AddDoubleLine("현재 XP",XP,nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("최대 XP",maxXP,nil,nil,nil,1,1,1);
	if (restXP) then
		GameTooltip:AddDoubleLine("휴식 XP",restXP,nil,nil,nil,1,1,1);
	end

	if (xpGain) then
		GameTooltip:AddLine(" ");
		GameTooltip:AddDoubleLine("최근 획득한 XP",xpGain,nil,nil,nil,1,1,1);
		GameTooltip:AddDoubleLine("다음 레벨까지 필요한 반복 횟수",format("%.2f",(maxXP - XP) / xpGain),nil,nil,nil,1,1,1);
		GameTooltip:AddDoubleLine("획득률",format("%.2f%%",xpGain / maxXP * 100),nil,nil,nil,1,1,1);
	end

	if (sessionXP > 0) then
		GameTooltip:AddLine(" ");
		GameTooltip:AddDoubleLine("이번 세션에서 얻은 XP",sessionXP,nil,nil,nil,1,1,1);
		GameTooltip:AddDoubleLine("시간당 획득한 XP",format("%.1f",sessionXP / ((GetTime() - startTime) / 3600)),nil,nil,nil,1,1,1);
	end

	GameTooltip:AddLine(" ");
	GameTooltip:AddDoubleLine("다음 레벨까지 남은 XP",maxXP - XP,nil,nil,nil,1,1,1);

	GameTooltip:Show();
end

-- Gather Info
local function OnEvent(self,event,...)
	XP, maxXP, restXP = UnitXP("player"), UnitXPMax("player"), GetXPExhaustion();
	if (event == "PLAYER_XP_UPDATE") and (XP ~= lastXP) then
		xpGain = (XP > lastXP) and (XP - lastXP) or (XP + lastMaxXP - lastXP);
		sessionXP = (sessionXP + xpGain);
	end
	lastXP, lastMaxXP = XP, maxXP;
	InfoPanel_SetText(f,"%.2f%%",XP / maxXP * 100);
end

--------------------------------------------------------------------------------------------------------
--                                              Finalize                                              --
--------------------------------------------------------------------------------------------------------

f.icon:SetTexture("Interface\\Icons\\Spell_Fire_FelFlameRing");
f:SetScript("OnEnter",OnEnter);
f:SetScript("OnEvent",OnEvent);
f:RegisterEvent("PLAYER_LOGIN");
f:RegisterEvent("PLAYER_XP_UPDATE");