
--------------------------------------------------------------------------------------------------------
--                                           Event Handling                                           --
--------------------------------------------------------------------------------------------------------
function WDButton_OnEvent(self, event, ...)
	if( event == "PLAYER_TARGET_CHANGED" ) then
		if ( UnitIsVisible("target")) then
			WDButtonFrame:Show();
		else
			WDButtonFrame:Hide();
		end
	end
end

function WDButton_OnDragStart(self, button)
	WDButtonFrame:StartMoving()
end

function WDButton_OnDragStop(self)
	WDButtonFrame:StopMovingOrSizing()
end

--------------------------------------------------------------------------------------------------------
--                                               OnLoad                                               --
--------------------------------------------------------------------------------------------------------
local InspectFrame = nil;
local Examiner = nil;

function WDButton_OnLoad(self)
	WDButtonFrame:RegisterEvent("PLAYER_TARGET_CHANGED");
	WDButtonFrame:RegisterForDrag("RightButton");

	if (IsAddOnLoaded("Examiner")) then
		Examiner = _G["Examiner"];
	end
end

--------------------------------------------------------------------------------------------------------
--                                               Onclick                                              --
--------------------------------------------------------------------------------------------------------
function WDButton_OnClick(self, button, down)
 local arg1 = button;
	if arg1 == "LeftButton" then
		local frame = InspectFrame
		if (IsAltKeyDown()) then
			InviteUnit(UnitName("target"))
		elseif (IsShiftKeyDown()) then
			InitiateTrade("target")
		else
			-- Examiner 이면
			if (Examiner) then
				if (Examiner:IsShown()) then
					HideUIPanel(Examiner);
				else
					Examiner:DoInspect("target");
				end
			else
				if (frame == nil) then
					InspectUnit("target")
					InspectFrame =_G["InspectFrame"];
				elseif (frame ~= nil and frame:IsShown()) then
					HideUIPanel(frame);
				else
					InspectUnit("target")
				end
			end
		end
	end
end

---------------------------------------------------------------------------------------------------------
--                                           OnEnter, OnLeave                                          --
---------------------------------------------------------------------------------------------------------
function WDButtonFrame_OnEnter(self, motion)
--  GameTooltip_SetDefaultAnchor( GameTooltip, self );
  GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT", 10, -10);
  GameTooltip:SetText( ">> |cFF00FFFF마우스 좌클릭 |r: 대상 살펴보기 \n\n>> |cFF00FFFF마우스 우클릭 + 끌기(드래그) |r: 버튼(WDButton) 이동\n\n>> |cFF00FFFFALT + 마우스 좌클릭 |r: 대상 파티 초대\n\n>> |cFF00FFFFSHIFT + 마우스 좌클릭 |r: 대상과 거래\n\n|cFFC0FF3E## 이 버튼은 기본 유닛프레임 또는 기본유닛프레임 기반의 유닛프레임 애드온에서만 동작합니다.");
  GameTooltip:Show();
end

function WDButtonFrame_OnLeave(self, motion)
  GameTooltip:Hide();
end
