local f = InfoPanel_AddPlugin();
local UPDATE_INTERVAL = 0.8;
local nextUpdate = 0;
local zoneChange, lastZoneChange;

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

-- OnEnter
local function OnEnter(self)
	InfoPanel_MakeTip(f,"지역 정보");

--	local x, y = GetPlayerMapPosition("player");
--	GameTooltip:AddDoubleLine("현재 좌표",format("(%.1f , %.1f)",x * 100,y * 100),nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("대 지역명",GetZoneText(),nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("실 지역명",GetRealZoneText(),nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("소 지역명",GetSubZoneText(),nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("미니맵 표시지역",GetMinimapZoneText(),nil,nil,nil,1,1,1);

	local pvpType, isFFA, faction = GetZonePVPInfo();
	if (pvpType) then
		GameTooltip:AddLine(" ");
		GameTooltip:AddDoubleLine("상호 관계",pvpType,nil,nil,nil,1,1,1);
		GameTooltip:AddDoubleLine("투기 지역",tostring(isFFA),nil,nil,nil,1,1,1);
		GameTooltip:AddDoubleLine("지역 진영",tostring(faction),nil,nil,nil,1,1,1);
	end

	local inInstance, instanceType = IsInInstance();
	GameTooltip:AddLine(" ");
	GameTooltip:AddDoubleLine("인던 내부",tostring(inInstance),nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("인던 종류",tostring(instanceType),nil,nil,nil,1,1,1);

	GameTooltip:AddLine(" ");
	GameTooltip:AddDoubleLine("현 지역 체류시간",InfoPanel_FormatTime(GetTime() - zoneChange),nil,nil,nil,1,1,1);
	if (lastZoneChange) then
		GameTooltip:AddDoubleLine("이전 지역 체류시간",InfoPanel_FormatTime(zoneChange - lastZoneChange),nil,nil,nil,1,1,1);
	end

	GameTooltip:Show();
end

-- Gather Info
local function OnUpdate(self,elapsed)
	nextUpdate = (nextUpdate - elapsed);
	if (nextUpdate <= 0) then
		if (IsInInstance()) then
			InfoPanel_SetText(f,GetZoneText());
		else
--			InfoPanel_SetText(f,GetRealZoneText());
			local x, y = GetPlayerMapPosition("player");
			InfoPanel_SetText(f,"%.1f |cffffff00|||r %.1f",x * 100,y * 100);
		end
		nextUpdate = UPDATE_INTERVAL;
	end
end

-- OnEvent
local function OnEvent(self,event)
	lastZoneChange = zoneChange;
	zoneChange = GetTime();
end

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

f.icon:SetTexture("Interface\\Icons\\Spell_Nature_Web");
f:SetScript("OnEnter",OnEnter);
f:SetScript("OnUpdate",OnUpdate);
f:SetScript("OnClick",function() ToggleWorldMap() end);
f:SetScript("OnEvent",OnEvent);
f:RegisterEvent("PLAYER_ENTERING_WORLD");
--f:RegisterEvent("ZONE_CHANGED_NEW_AREA");