----------------------------------------------------------------------------------------
--	Auto repair
----------------------------------------------------------------------------------------
local T, C, L, _ = unpack(select(2, ...))
if C.Module.Automation.auto_sell ~= true then return end

local Event = CreateFrame("Frame")
Event:RegisterEvent("MERCHANT_SHOW")
Event:SetScript("OnEvent", function(self)
	local Cost = 0
	for BagID = 0, 4 do
		for SlotID = 1, GetContainerNumSlots(BagID) do
			local Link = GetContainerItemLink(BagID, SlotID)
			if Link and GetItemInfo(Link) ~= nil then
				local p = select(11, GetItemInfo(Link)) * select(2, GetContainerItemInfo(BagID, SlotID))
				if select(3, GetItemInfo(Link)) == 0 and p > 0 then
					UseContainerItem(BagID, SlotID)
					PickupMerchantItem()
					Cost = Cost + p
				end
			end
		end
	end
	if Cost > 0 then
		local g, s, c = math.floor(Cost/10000) or 0, math.floor((Cost%10000)/100) or 0, Cost%100
		DEFAULT_CHAT_FRAME:AddMessage("|cffffff00"..L.AUTO_SELL_INFO.."|r"..format(GOLD_AMOUNT_TEXTURE, g, 0, 0).." "..format(SILVER_AMOUNT_TEXTURE, s, 0, 0).." "..format(COPPER_AMOUNT_TEXTURE, c, 0, 0),255,255,255)
	end
end)