searchKeyword = ''

function TRaid_ReportChannel_OnClick(self)--{{{
	UIDropDownMenu_SetSelectedValue(TradeListReportChannel, self.value);
	TradeLogDB.briefChannel = self.value
end--}}}

function TRaid_ReportChannel_OnLoad()--{{{
	local info

	info = {}
	info.text = TRADE_LOG_CHANNELS.raid
	info.func = TRaid_ReportChannel_OnClick
	info.value = "RAID"
	if info.value == TradeLogDB.briefChannel then
		info.checked = true
	else
		info.checked = false
	end
	UIDropDownMenu_AddButton(info)

	info = {}
	info.text = TRADE_LOG_CHANNELS.party
	info.func = TRaid_ReportChannel_OnClick
	info.value = "PARTY"
	if info.value == TradeLogDB.briefChannel then
		info.checked = true
	else
		info.checked = false
	end
	UIDropDownMenu_AddButton(info)

end--}}}

function TradeLogFrame_OnLoad(self)--{{{
	table.insert(UISpecialFrames, self:GetName()); --for esc close frame

	TradeLog_SetHyperlink_Origin = ItemRefTooltip.SetHyperlink
	ItemRefTooltip.SetHyperlink = function(self,link)
	   if(strsub(link, 1, 8)=="tradelog") then
		HideUIPanel(self)
	        return
	   end
	   return TradeLog_SetHyperlink_Origin(self,link)
	end
end--}}}

function TradeLogFrame_FillDetailLog(trade)--{{{
	--DEFAULT_CHAT_FRAME:AddMessage("|CFF00B4FF|Htradelog:"..TEXT(trade.id).."|h[TradeLog]|h|r")
end--}}}

function TradeLogFrame_UpdateItemDetail(frame, name, texture, numItems, isUsable, enchantment, itemLink)--{{{
	local frameName = frame:GetName()
	local id = frame:GetID()
	local buttonText = getglobal(frameName.."Name")

	if(itemLink) then
		local found, _, itemString = string.find(itemLink, "^|%x+|H(.+)|h%[.+%]")
		frame.itemLink = itemString
	end

	--ChatFrame1:AddMessage(itemLink, "\124", "\124\124"))
	-- See if its the enchant slot
	if ( id == 7 ) then
		if ( name ) then
			if ( enchantment ) then
				buttonText:SetText(GREEN_FONT_COLOR_CODE..enchantment..FONT_COLOR_CODE_CLOSE);		
			else
				buttonText:SetText(HIGHLIGHT_FONT_COLOR_CODE..TRADEFRAME_NOT_MODIFIED_TEXT..FONT_COLOR_CODE_CLOSE)
			end
		else
			buttonText:SetText("")
		end
		
	else
		buttonText:SetText(name)

	end
	buttonText:SetTextHeight(12)
	TradeLogRecipientMoneyFrame:SetScale(0.9)
	TradeLogPlayerMoneyFrame:SetScale(0.9)
	local tradeItemButton = getglobal(frameName.."ItemButton")
	local tradeItem = frame
	SetItemButtonTexture(tradeItemButton, texture)
	SetItemButtonCount(tradeItemButton, numItems)
	if ( isUsable or not name ) then
		SetItemButtonTextureVertexColor(tradeItemButton, 1.0, 1.0, 1.0)
		SetItemButtonNameFrameVertexColor(tradeItem, 1.0, 1.0, 1.0)
		SetItemButtonSlotVertexColor(tradeItem, 1.0, 1.0, 1.0)
	else
		SetItemButtonTextureVertexColor(tradeItemButton, 0.9, 0, 0)
		SetItemButtonNameFrameVertexColor(tradeItem, 0.9, 0, 0)
		SetItemButtonSlotVertexColor(tradeItem, 1.0, 0, 0)
	end
end--}}}

function TRaid_ShowTooltip(self)--{{{
	GameTooltip:SetOwner(self, "ANCHOR_LEFT")

	local filteredTradesHistory = TRaid_GetFilteredTradesHistory()
	local idx = string.gsub(self:GetName(), "TradeListFrameButton", "")
	local trade = filteredTradesHistory[#filteredTradesHistory-FauxScrollFrame_GetOffset(TradeListScrollFrame)-idx+1]

	local msg = {}

	-- 받은 것 요약
	local receiveItemsSummary = {}
	if trade.targetMoney >= 1 then
		local goldStr = {}
		if math.floor(trade.targetMoney/10000) > 0 then
			table.insert(goldStr, math.floor(trade.targetMoney/10000).."골드")
		end
		if math.floor(trade.targetMoney/100) % 100 > 0 then
			table.insert(goldStr, (math.floor(trade.targetMoney/100) % 100).."실버")
		end
		if trade.targetMoney % 100 > 0 then
			table.insert(goldStr, (math.floor(trade.targetMoney/100) % 100).."쿠퍼")
		end
		table.insert(receiveItemsSummary, table.concat(goldStr, " "))
	end

	local k, item
	for k, item in pairs(trade.targetItems) do
		if k <= 6 then
			if item.numItems > 1 then
				table.insert(receiveItemsSummary, item.itemLink.."x"..item.numItems)
			else
				table.insert(receiveItemsSummary, item.itemLink)
			end
		end
	end
	if trade.playerItems[7] and trade.playerItems[7].enchantment then
		table.insert(receiveItemsSummary, trade.playerItems[7].enchantment)
	end
	if #receiveItemsSummary > 0 then
		table.insert(msg, "받은 것:\n     "..table.concat(receiveItemsSummary, "\n     "))
	end

	-- 준 것 요약
	local sendItemsSummary = {}
	if trade.playerMoney >= 1 then
		local goldStr = {}
		if math.floor(trade.playerMoney/10000) > 0 then
			table.insert(goldStr, math.floor(trade.playerMoney/10000).."골드")
		end
		if math.floor(trade.playerMoney/100) % 100 > 0 then
			table.insert(goldStr, (math.floor(trade.playerMoney/100) % 100).."실버")
		end
		if trade.playerMoney % 100 > 0 then
			table.insert(goldStr, (math.floor(trade.playerMoney/100) % 100).."쿠퍼")
		end
		table.insert(sendItemsSummary, table.concat(goldStr, " "))
	end

	local k, item
	for k, item in pairs(trade.playerItems) do
		if k <= 6 then
			if item.numItems > 1 then
				table.insert(sendItemsSummary, item.itemLink.."x"..item.numItems)
			else
				table.insert(sendItemsSummary, item.itemLink)
			end
		end
	end
	if trade.targetItems[7] and trade.targetItems[7].enchantment then
		table.insert(sendItemsSummary, trade.targetItems[7].enchantment)
	end
	if #sendItemsSummary > 0 then
		table.insert(msg, "준 것:\n     "..table.concat(sendItemsSummary, "\n     "))
	end

	GameTooltip:SetText(table.concat(msg, "\n\n"), 1, 1, 1, 1)
end--}}}

local function trim(str)--{{{
  -- from PiL2 20.4
  return (str:gsub("^%s*(.-)%s*$", "%1"))
end--}}}

function TRaid_GetFilteredTradesHistory()--{{{
	local filteredTradesHistory = {}

	local trade
	for _, trade in pairs(TradeLog_TradesHistory) do
		if searchKeyword == '' or
		   string.find(strlower(trade.who), strlower(searchKeyword)) or
		   string.find(strlower(trade.where), strlower(searchKeyword)) then
			table.insert(filteredTradesHistory, trade)
		end
	end

	return filteredTradesHistory
end--}}}

function TradeListScrollFrame_Update(self)--{{{
	local offset, count
	local filteredTradesHistory = TRaid_GetFilteredTradesHistory()
	
	count = #filteredTradesHistory

	FauxScrollFrame_Update(TradeListScrollFrame,count, 25, 16)

	if(not FauxScrollFrame_GetOffset(TradeListScrollFrame)) then
		offset = 1
	else
		offset = FauxScrollFrame_GetOffset(TradeListScrollFrame)+1
	end

	local line = 1
	while line <= 25 do
		if offset <= #filteredTradesHistory then
			local trade

			if TradeLogDB.listOrder == "desc" then
				trade = filteredTradesHistory[#filteredTradesHistory-offset+1]
			else
				trade = filteredTradesHistory[offset]
			end

			local _,_,month,day,hour,min = string.find(trade.when, "(%d+)-(%d+) (%d+):(%d+)")
			getglobal("TradeListFrameButton"..line).offset = offset

			getglobal("TradeListFrameButton"..line.."Time"):SetText(month..TRADE_LIST_MONTH_SUFFIX..day..TRADE_LIST_DAY_SUFFIX.." "..hour..":"..min)
			getglobal("TradeListFrameButton"..line.."Target"):SetText(trade.who)
			getglobal("TradeListFrameButton"..line.."Zone"):SetText(trade.where)
			getglobal("TradeListFrameButton"..line.."Result"):SetText(TRADE_LIST_RESULT_TEXT_SHORT[trade.result])
			getglobal("TradeListFrameButton"..line):Show()

			getglobal("TradeListFrameButton"..line.."SendMoneyIcon"):Show()
			getglobal("TradeListFrameButton"..line.."ReceiveMoneyIcon"):Show()

			if(trade.result=="complete")then
				-- 받은 것 요약
				local itemCnt = 0
				local k, item
				for k, item in pairs(trade.targetItems) do
					if k <= 6 then
						itemCnt = itemCnt + 1
					end
				end

				local receiveItemsSummary = {}
				if trade.targetMoney >= 10000 then
					table.insert(receiveItemsSummary, math.floor(trade.targetMoney/10000))
				end
				if itemCnt >= 1 then
					table.insert(receiveItemsSummary, "아이템x"..itemCnt)
				end
				if trade.playerItems[7] and trade.playerItems[7].enchantment then
					table.insert(receiveItemsSummary, "마부")
				end

				-- 받은 것 레이어
				if trade.targetMoney >= 10000 then 
					getglobal("TradeListFrameButton"..line.."ReceiveMoneyIcon"):Show()
					--getglobal("TradeListFrameButton"..line.."Receive"):SetText(math.floor( trade.targetMoney / 10000 ))
					getglobal("TradeListFrameButton"..line.."Receive"):SetText(table.concat(receiveItemsSummary, ", "))
					getglobal("TradeListFrameButton"..line.."Receive"):Show()
					getglobal("TradeListFrameButton"..line.."Receive"):SetTextColor(1.0, 1.0, 1.0)
					getglobal("TradeListFrameButton"..line.."ReceiveItem"):Hide()
				else
					getglobal("TradeListFrameButton"..line.."ReceiveMoneyIcon"):Hide()
					getglobal("TradeListFrameButton"..line.."Receive"):Hide(); 
					getglobal("TradeListFrameButton"..line.."ReceiveItem"):SetText(table.concat(receiveItemsSummary, ", "))
					getglobal("TradeListFrameButton"..line.."ReceiveItem"):Show()
				end 

				-- 준 것 요약
				local itemCnt = 0
				local k, item
				for k, item in pairs(trade.playerItems) do
					if k <= 6 then
						itemCnt = itemCnt + 1
					end
				end

				local sendItemsSummary = {}
				if trade.playerMoney >= 10000 then
					table.insert(sendItemsSummary, math.floor(trade.playerMoney/10000))
				end
				if itemCnt >= 1 then
					table.insert(sendItemsSummary, "아이템x"..itemCnt)
				end
				if trade.targetItems[7] and trade.targetItems[7].enchantment then
					table.insert(sendItemsSummary, "마부")
				end

				-- 준 것 레이어
				if(math.floor( trade.playerMoney / 10000 )>=1)then 
					getglobal("TradeListFrameButton"..line.."SendMoneyIcon"):Show()
					--getglobal("TradeListFrameButton"..line.."Send"):SetText(math.floor( trade.playerMoney / 10000 ))
					getglobal("TradeListFrameButton"..line.."Send"):SetText(table.concat(sendItemsSummary, ", "))
					getglobal("TradeListFrameButton"..line.."Send"):Show()
					getglobal("TradeListFrameButton"..line.."Send"):SetTextColor(1.0, 1.0, 1.0)
					getglobal("TradeListFrameButton"..line.."SendItem"   ):Hide()
				else
					getglobal("TradeListFrameButton"..line.."SendMoneyIcon"):Hide()
					getglobal("TradeListFrameButton"..line.."Send"):Hide(); 
					getglobal("TradeListFrameButton"..line.."SendItem"):SetText(table.concat(sendItemsSummary, ", "))
					getglobal("TradeListFrameButton"..line.."SendItem"   ):Show()
				end

				getglobal("TradeListFrameButton"..line.."Time"   ):SetTextColor(1.0, .82, 0.0)
				getglobal("TradeListFrameButton"..line.."Target" ):SetTextColor(1.0, 1.0, 1.0)
				getglobal("TradeListFrameButton"..line.."Zone"   ):SetTextColor(1.0, 1.0, 1.0)
				getglobal("TradeListFrameButton"..line.."Result" ):SetTextColor(1.0, 1.0, 1.0)
			elseif(trade.result=="cancelled")then
				getglobal("TradeListFrameButton"..line.."Time"   ):SetTextColor(0.5, 0.3, 0.3)
				getglobal("TradeListFrameButton"..line.."Target" ):SetTextColor(0.5, 0.3, 0.3)
				getglobal("TradeListFrameButton"..line.."Zone"   ):SetTextColor(0.5, 0.3, 0.3)
				getglobal("TradeListFrameButton"..line.."Receive"):Hide()
				getglobal("TradeListFrameButton"..line.."ReceiveItem"):Hide()
				getglobal("TradeListFrameButton"..line.."ReceiveMoneyIcon"):Hide()
				getglobal("TradeListFrameButton"..line.."Send"   ):Hide()
				getglobal("TradeListFrameButton"..line.."SendItem"   ):Hide()
				getglobal("TradeListFrameButton"..line.."SendMoneyIcon"):Hide()
				getglobal("TradeListFrameButton"..line.."Result" ):SetTextColor(0.5, 0.3, 0.3)
			else
				getglobal("TradeListFrameButton"..line.."Time"   ):SetTextColor(0.8, 0.2, 0.2)
				getglobal("TradeListFrameButton"..line.."Target" ):SetTextColor(0.8, 0.2, 0.2)
				getglobal("TradeListFrameButton"..line.."Zone"   ):SetTextColor(0.8, 0.2, 0.2)
				getglobal("TradeListFrameButton"..line.."Receive"):SetTextColor(0.8, 0.2, 0.2)
				getglobal("TradeListFrameButton"..line.."ReceiveItem"):SetTextColor(0.8, 0.2, 0.2)
				getglobal("TradeListFrameButton"..line.."Send"   ):SetTextColor(0.8, 0.2, 0.2)
				getglobal("TradeListFrameButton"..line.."SendItem"   ):SetTextColor(0.8, 0.2, 0.2)
				getglobal("TradeListFrameButton"..line.."Result" ):SetTextColor(0.8, 0.2, 0.2)
			end

			line=line+1
		else
			getglobal("TradeListFrameButton"..line):Hide()
			line=line+1
		end
		offset=offset+1
	end

	-- 총 받은 금액과 보낸 금액 업데이트
	local totalReceivedGold = 0
	local totalSendGold = 0
	local totalProfit = 0

	local k, trade
	for k, trade in pairs(filteredTradesHistory) do
		if trade.result == 'complete' then
			totalReceivedGold = totalReceivedGold + math.floor(trade.targetMoney / 10000)
			totalSendGold = totalSendGold + math.floor(trade.playerMoney / 10000)
		end
	end
	totalProfit = totalReceivedGold - totalSendGold

	getglobal("TradeListTotalGold"):SetText(totalReceivedGold)
	getglobal("TradeListTotalSendGold"):SetText(totalSendGold)
	getglobal("TradeListTotalPlusGold"):SetText(totalProfit)
end--}}}

StaticPopupDialogs["TRADE_LOG_CLEAR_HISTORY"] = {
	text = TEXT("CLEAR TRADE HISTORY"),
	button1 = TEXT(ACCEPT),
	button2 = TEXT(CANCEL),
	whileDead = 1,
	OnShow = function(self)
		getglobal(self:GetName().."Text"):SetText(TRADE_LIST_CLEAR_CONFIRM)
	end,
	OnAccept = function(self)
		TradeLog_KeepOnlyToday()
	end,
	timeout = 0,
	hideOnEscape = 1
}

function TradeLog_KeepOnlyToday()--{{{
	local today = {
		month = date("%m"), 
		day = date("%d"),
	}
	for k, v in pairs(TradeLog_TradesHistory) do
		local _,_,month,day,hour,min = string.find(v.when, "(%d+)-(%d+) (%d+):(%d+)")
		if(month==today.month and day==today.day+1)then
			local tmp = {}
			for i=k, #TradeLog_TradesHistory do
				table.insert(tmp, TradeLog_TradesHistory[i])
			end
			TradeLog_TradesHistory = nil
			TradeLog_TradesHistory = tmp
			TradeListScrollFrame_Update()
			return
		end
	end
	
	TradeLog_TradesHistory = nil
	TradeLog_TradesHistory = {}
	TradeListScrollFrame_Update()
end--}}}

function TradeListFrame_TradeTooltip(self, trade)--{{{
	GameTooltip_SetDefaultAnchor(GameTooltip, self)
	if(trade.result=="complete")then
		GameTooltip:SetText(TRADE_LIST_RESULT_TEXT.complete, 1, 1, 1)
		GameTooltip:AddLine(TRADE_LIST_COMPLETE_TOOLTIP, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1)
	elseif(trade.result=="cancelled")then
		GameTooltip:SetText(TRADE_LIST_RESULT_TEXT.cancelled, 1, 0.5, 0.5)
		GameTooltip:AddLine(CANCEL_REASON_TEXT[trade.reason], NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1)
	else
		GameTooltip:SetText(TRADE_LIST_RESULT_TEXT.error, 1, 0.1, 0.1)
		GameTooltip:AddLine(trade.reason, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1)
	end	
	GameTooltip:Show()
end--}}}

function TradeListFrame_ShowDetail(trade)--{{{
	TradeLogFrame:Hide()
	if(trade.result=="complete")then
		TradeLogFrame_FillDetailLog(trade)
		TradeLogFrame:Show()
		TradeLogFrame:SetFrameStrata("HIGH")
	end
end--}}}

function InitialMovableMinimapButton(ButtonName, PosVariableName, UseSquareMap)--{{{
	local button = getglobal(ButtonName)
	if(not button) then return nil; end

	button["POS"] = PosVariableName
	button["square"] = UseSquareMap
	button.updateTimer = 0
	button:RegisterEvent("VARIABLES_LOADED")
	button:RegisterForDrag("LeftButton")

	button:SetScript("OnDragStart", function(self) 
		self:LockHighlight()
		self:StartTimer()
	end)

	button:SetScript("OnDragStop", function(self)
		self:StopTimer()
		self:UnlockHighlight()
	end)

	button.MovingPos = function(self)
		local xpos,ypos
		local IconPos = getglobal(self["POS"])

		if self["square"] then
			xpos = 110 * cos(IconPos or 0)
			ypos = 110 * sin(IconPos or 0)
			xpos = math.max(-82,math.min(xpos,84))
			ypos = math.max(-86,math.min(ypos,82))
		else
			xpos = 82*cos(IconPos or 0)
			ypos = 82*sin(IconPos or 0)
		end

		button:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-xpos,ypos-52)
	end
	
	button.Dragging = function(self)
		local xpos,ypos = GetCursorPosition()
		local xmin,ymin = Minimap:GetLeft() or 400, Minimap:GetBottom() or 400
		xpos = xmin-xpos/Minimap:GetEffectiveScale()+70
		ypos = ypos/Minimap:GetEffectiveScale()-ymin-70
		setglobal( self["POS"], math.deg(math.atan2(ypos,xpos)) )
		self:MovingPos()
	end

	button.StartTimer = function(self)
		self:SetScript("OnUpdate", function (self, elapsed) 
			self.updateTimer = self.updateTimer + elapsed
			if(self.updateTimer >= 0) then
				self:Dragging()
				self.updateTimer = 0
			end
		end )
	end

	button.StopTimer = function(self)
		self:SetScript("OnUpdate", nil)
	end

end--}}}

function TRaid_Search(keyword)--{{{
	searchKeyword = trim(keyword)
	TradeListScrollFrame_Update()
end--}}}

function TradeLog_GetMoneyColorText(money)--{{{
	local GSC_GOLD="ffd100"
	local GSC_SILVER="e6e6e6"
	local GSC_COPPER="c8602c"

	local g = math.floor( money / 10000 );
	local s = math.floor( money / 100 ) - g*100 ;
	local c = money - ( g * 100 + s ) * 100;

	local text = ""
	if(g>0) then text = text.."|cffffff00"..g.."|r".."|cff"..GSC_GOLD..TRADE_LOG_MONEY_NAME.gold.."|r"; end
	if(s>0) then text = text.."|cffffff00"..s.."|r".."|cff"..GSC_SILVER..TRADE_LOG_MONEY_NAME.silver.."|r"; end
	if(c>0) then text = text.."|cffffff00"..c.."|r".."|cff"..GSC_COPPER..TRADE_LOG_MONEY_NAME.copper.."|r"; end

	return text;
end--}}}

function TRaid_ReportMsg(msg)--{{{
	SendChatMessage(msg, TradeLog_FindAnnounceChannel(TradeLogDB.briefChannel))
end--}}}

function TRaid_ReportTrade(trade)--{{{
	local enPlayer, enTarget, msg

	if trade.playerItems[7] and trade.playerItems[7].name and trade.playerItems[7].enchantment then 
		enPlayer = trade.playerItems[7].enchantment 
	end
	if trade.targetItems[7] and trade.targetItems[7].name and trade.targetItems[7].enchantment then
		enTarget = trade.targetItems[7].enchantment 
	end

	if trade.result ~= "complete" then
		return
	end

	-- 보낸 내용 정리
	local hasSendAny, strSend
	hasSendAny = false 
	strSend = ''
	-- 보낸 골드
	if trade.playerMoney > 0 then
		hasSendAny = true
		strSend = strSend..TradeLog_GetMoneyPlainText(trade.playerMoney);
	end
	-- 보낸 아이템
	for i = 1, 6 do
		if trade.playerItems[i] then
			if hasSendAny then
				strSend = strSend..", "
			end
			hasSendAny = true;
			strSend = strSend..trade.playerItems[i].itemLink;
			if trade.playerItems[i].numItems > 1 then
				strSend = strSend.."x"..trade.playerItems[i].numItems;
			end
		end
	end
	-- 해준 마부
	if enTarget then
		if hasSendAny then
			strSend = strSend..", "
		end
		hasSendAny = true;
		strSend = strSend..TRADE_LOG_ENCHANT..":"..enTarget
	end

	-- 받은 내용 정리
	local hasReceiveAny, strReceive
	hasReceiveAny = false 
	strReceive = ''
	-- 받은 골드
	if trade.targetMoney > 0 then
		hasReceiveAny = true
		strReceive = strReceive..TradeLog_GetMoneyPlainText(trade.targetMoney);
	end
	-- 받은 아이템
	for i = 1, 6 do
		if trade.targetItems[i] then
			if hasReceiveAny then
				strReceive = strReceive..", "
			end
			hasReceiveAny = true
			strReceive = strReceive..trade.targetItems[i].itemLink
			if trade.targetItems[i].numItems > 1 then
				strReceive = strReceive.."x"..trade.targetItems[i].numItems
			end
		end
	end
	-- 받은 마부
	if enPlayer then
		if hasReceiveAny then
			strReceive = strReceive..", "
		end
		hasReceiveAny = true
		strReceive = strReceive..TRADE_LOG_ENCHANT..":"..enPlayer
	end

	if not hasSendAny and not hasReceiveAny then
		return
	end

	local _, _,  month, day, hour, min = string.find(trade.when, "(%d+)-(%d+) (%d+):(%d+)")
	if hasReceiveAny then
		msg = ''
		msg = msg..'['..hour..':'..min..'] '
		msg = msg..'【 '..trade.who..' 】님께 '
		msg = msg..strReceive..' 받음'
		TRaid_ReportMsg(msg)
	end
	if hasSendAny then 
		msg = ''
		msg = msg..'['..hour..':'..min..'] '
		msg = msg..'【 '..trade.who..' 】님께 '
		msg = msg..strSend..' 드림'
		TRaid_ReportMsg(msg)
	end
end--}}}

function TRaid_Report()--{{{
	local filteredTradesHistory = TRaid_GetFilteredTradesHistory()

	TRaid_ReportMsg('《======= 거래 내역 확인 =======》');

	for _, trade in pairs(filteredTradesHistory) do
		TRaid_ReportTrade(trade)
	end
	TRaid_ReportMsg('《========= TOTAL =========》');
	local totalReceivedGold, totalSendGold = 0, 0
	for _, trade in pairs(filteredTradesHistory) do
		if trade.result == 'complete' then
			totalReceivedGold = totalReceivedGold + math.floor(trade.targetMoney / 10000)
			totalSendGold = totalSendGold + math.floor(trade.playerMoney / 10000)
		end
	end
	TRaid_ReportMsg('【받은 골드】: '..totalReceivedGold..'골드');
	TRaid_ReportMsg('【지급 골드】: '..totalSendGold..'골드');
	TRaid_ReportMsg('【최종 골드】: '..(totalReceivedGold-totalSendGold)..'골드');
	TRaid_ReportMsg('《========= 분 배 금 =========》');
        TRaid_ReportMsg('【파티 분배】: '..((totalReceivedGold-totalSendGold)/5)..'골드');
        TRaid_ReportMsg('【개인 분배】: '..((totalReceivedGold-totalSendGold)/25)..'골드');
        TRaid_ReportMsg('《=======T-raid Addon=======》');
end--}}}
