local f = InfoPanel_AddPlugin("right");
local UPDATE_INTERVAL = 1;
local nextUpdate = 0;
local startTime = GetTime();
local gameTimeOffset = mod(time(),60);
local gameTimeMin = select(2,GetGameTime());
local hrs, min;
local playerName=UnitName("player");

--[[if (not InfoPanel_Config[playerName]["Clock"]) then
	InfoPanel_Config[playerName]["Clock"] = { showRealTime = true };
end
local cfg = InfoPanel_Config[playerName]["Clock"];]]

-- Az: temp until I setup the settings properly
local cfg = { showRealTime = true };

--------------------------------------------------------------------------------------------------------
--                                             Clock Bar                                              --
--------------------------------------------------------------------------------------------------------

-- OnEnter - http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
local function OnEnter(self)
	InfoPanel_MakeTip(f,"시간 정보");

	hrs, min = GetGameTime();
	GameTooltip:AddDoubleLine("서버 시간",format("%.2d:%.2d:%.2d",hrs,min,mod(time() - gameTimeOffset,60)),nil,nil,nil,1,1,1);
	GameTooltip:AddLine(" ");
	GameTooltip:AddDoubleLine("현재 시간",date("%H:%M:%S"),nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("요일",date("%A, %B %d, %Y"),nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("누적 날짜",tonumber(date("%j")),nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("누적 주",(tonumber(date("%W")) + 1),nil,nil,nil,1,1,1);
	GameTooltip:AddLine(" ");
	GameTooltip:AddDoubleLine("현 접속 시간",InfoPanel_FormatTime(GetTime() - startTime),nil,nil,nil,1,1,1);
	GameTooltip:AddDoubleLine("총 접속 시간",InfoPanel_FormatTime(GetTime()),nil,nil,nil,1,1,1);

	GameTooltip:Show();
end

-- OnUpdate
local function OnUpdate(self,elapsed)
	nextUpdate = (nextUpdate - elapsed);
	if (nextUpdate <= 0) then
		-- Sync GameTime Seconds
		if (gameTimeMin) and (select(2,GetGameTime()) ~= gameTimeMin) then
			gameTimeOffset = mod(time(),60);
			gameTimeMin = nil;
		end
		-- Show Time
		if (cfg.showRealTime) then
			InfoPanel_SetText(f,date("%H:%M:%S"));
		else
			hrs, min = GetGameTime();
			InfoPanel_SetText(f,"%.2d:%.2d:%.2d",hrs,min,mod(time() - gameTimeOffset,60));
		end
		nextUpdate = UPDATE_INTERVAL;
	end
end

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

f.icon:SetTexture("Interface\\Icons\\Ability_Hunter_Readiness");
f:SetScript("OnEnter",OnEnter);
f:SetScript("OnUpdate",OnUpdate);