Quantcast
_, BrokerGarbage = ...

-- create drop down menu table for PT sets
local interestingPTSets = {"Consumable", "Misc", "Tradeskill"}

BrokerGarbage.PTSets = {}
<<<<<<< HEAD
for set, _ in pairs( BrokerGarbage.PT and BrokerGarbage.PT.sets or {} ) do
=======
local sets
if not BrokerGarbage.PT then
	sets = {}
else
	sets = BrokerGarbage.PT.sets
end
for set, _ in pairs(sets) do
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
	local interesting = false
	local partials = { strsplit(".", set) }
	local maxParts = #partials

	for i = 1, #interestingPTSets do
		if strfind(partials[1], interestingPTSets[i]) then
			interesting = true
			break
		end
	end

	if interesting then
		local pre = BrokerGarbage.PTSets

		for i = 1, maxParts do
			if i == maxParts then
				-- actual clickable entries
				pre[ partials[i] ] = set
			else
				-- all parts before that
				if not pre[ partials[i] ] or type(pre[ partials[i] ]) == "string" then
					pre[ partials[i] ] = {}
				end
				pre = pre[ partials[i] ]
			end
		end
	end
end

-- options panel / statistics
<<<<<<< HEAD
BrokerGarbage.options = CreateFrame("Frame", "BG_Options", InterfaceOptionsFramePanelContainer)
BrokerGarbage.options.name = "Broker_Garbage"
=======
BrokerGarbage.options = CreateFrame("Frame", "BG_Statistics", InterfaceOptionsFramePanelContainer)
BrokerGarbage.options.name = "Broker_Garbage"
BrokerGarbage.options:Hide()

-- default / main options
BrokerGarbage.basicOptions = CreateFrame("Frame", "BG_BasicOptions", InterfaceOptionsFramePanelContainer)
BrokerGarbage.basicOptions.name = BrokerGarbage.locale.BasicOptionsTitle
BrokerGarbage.basicOptions.parent = "Broker_Garbage"
BrokerGarbage.basicOptions:Hide()
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa

-- list options
BrokerGarbage.listOptions = CreateFrame("Frame", "BG_ListOptions", InterfaceOptionsFramePanelContainer)
BrokerGarbage.listOptions.name = BrokerGarbage.locale.LOTitle
BrokerGarbage.listOptions.parent = "Broker_Garbage"
<<<<<<< HEAD
=======
BrokerGarbage.listOptions:Hide()

-- lists that hold our buttons
BrokerGarbage.listButtons = {}
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa

-- button tooltip infos
local function ShowTooltip(self)
	GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
<<<<<<< HEAD
	if self.tiptext and self:GetParent() == _G["BG_ListOptions_ScrollFrame"] and
		not (self.itemID and string.find(self.tiptext, self.itemID)) then
=======
	if self.tiptext and self:GetParent() == _G["BG_ListOptionsScrollFrameContent"] then
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
		local text = string.gsub(self.tiptext, "%.", " |cffffd200>|r ")

		GameTooltip:ClearLines()
		GameTooltip:AddLine("LibPeriodicTable")
		GameTooltip:AddLine(text, 1, 1, 1, true)
	elseif self.tiptext then
		GameTooltip:SetText(self.tiptext, nil, nil, nil, nil, true)
	elseif self.itemLink then
		GameTooltip:SetHyperlink(self.itemLink)
	end
	GameTooltip:Show()
end
local function HideTooltip() GameTooltip:Hide() end

<<<<<<< HEAD
local function CreateHorizontalRule(parent)
	local line = parent:CreateTexture(nil, "ARTWORK")
	line:SetHeight(8)
	line:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
	line:SetTexCoord(0.81, 0.94, 0.5, 1)

	return line
end

local function CreateFrameBorders(frame)
	local left = frame:CreateTexture(nil, "BACKGROUND")
	left:SetWidth(8) left:SetHeight(20)
	left:SetPoint("LEFT", -5, 0)
	left:SetTexture("Interface\\Common\\Common-Input-Border")
	left:SetTexCoord(0, 0.0625, 0, 0.625)
	local right = frame:CreateTexture(nil, "BACKGROUND")
	right:SetWidth(8) right:SetHeight(20)
	right:SetPoint("RIGHT", 0, 0)
	right:SetTexture("Interface\\Common\\Common-Input-Border")
	right:SetTexCoord(0.9375, 1, 0, 0.625)
	local center = frame:CreateTexture(nil, "BACKGROUND")
	center:SetHeight(20)
	center:SetPoint("RIGHT", right, "LEFT", 0, 0)
	center:SetPoint("LEFT", left, "RIGHT", 0, 0)
	center:SetTexture("Interface\\Common\\Common-Input-Border")
	center:SetTexCoord(0.0625, 0.9375, 0, 0.625)

	return left, center, right
end

local function UpdateOptionsPanel(frame)
	if not BrokerGarbage.options.currentTab then return end
	local panel = BrokerGarbage.tabs[ BrokerGarbage.options.currentTab ].panel
	if panel and panel.Update then
		panel:Update()
	end
end

local function ChangeView(pluginID)
	table.sort(BrokerGarbage.tabs, function(a, b)
		return a.name < b.name
	end)
	for i, plugin in ipairs(BrokerGarbage.tabs) do
		if not plugin.panel then
			if not plugin.init then
				BrokerGarbage:Print("Error! Panel " .. (name or "nil") .. " doesn't have an init script!")
				return
			end
			plugin.init(i)	-- supply the plugin's ID just in case
		end

		if i == pluginID then
			plugin.tab:Activate()
			plugin.panel:Show()

			BrokerGarbage.options.currentTab = pluginID
		else
			plugin.tab:Deactivate()
			plugin.panel:Hide()
		end
	end
	UpdateOptionsPanel()
end

function BrokerGarbage:RegisterPlugin(name, init)
	if not name or not init then
		BrokerGarbage:Print("Error! Cannot register a plugin without a name and initialize function.")
		return
	end

	table.insert(BrokerGarbage.tabs, {
		name = name,
		init = init
	})
	return #BrokerGarbage.tabs
end

local topTab = LibStub("tekKonfig-TopTab")
function BrokerGarbage:CreateOptionsTab(id)
	if not id then BrokerGarbage:Print("Error creating options tab: No id supplied."); return end
	local plugin = BrokerGarbage.tabs[id]

	local tab
	if id == 1 then
		tab = topTab.new(BrokerGarbage.options, plugin.name, "BOTTOMLEFT", BrokerGarbage.options.group, "TOPLEFT", 0, -4)
	else
		tab = topTab.new(BrokerGarbage.options, plugin.name, "BOTTOMLEFT", BrokerGarbage.tabs[ id - 1 ].tab, "BOTTOMRIGHT", -15, 0)
	end

	panel = CreateFrame("Frame", nil, BrokerGarbage.options.group)
	panel:SetAllPoints()
	panel.tab = tab

	tab.panel = panel
	tab:SetID(id)
	tab:SetScript("OnClick", function(self)
		ChangeView(self:GetID())
	end)
	tab:Deactivate()

	plugin.panel = panel
	plugin.tab = tab

	return panel, tab
end

local function Options_BasicOptions(pluginID)
	local panel, tab = BrokerGarbage:CreateOptionsTab(pluginID)

	local behavior = LibStub("tekKonfig-Group").new(panel, BrokerGarbage.locale.GroupBehavior, "TOPLEFT", 21, -16)
	behavior:SetHeight(190); behavior:SetWidth(180)
	behavior:SetBackdropColor(0.1, 0.1, 0.1, 0.4)

	local sell = LibStub("tekKonfig-Checkbox").new(behavior, nil, BrokerGarbage.locale.autoSellTitle, "TOPLEFT", behavior, "TOPLEFT", 4, -2)
	sell.tiptext = BrokerGarbage.locale.autoSellText .. BrokerGarbage.locale.GlobalSetting
	sell:SetChecked(BG_GlobalDB.autoSellToVendor)
	local checksound = sell:GetScript("OnClick")
	sell:SetScript("OnClick", function(sell)
		checksound(sell)
		BG_GlobalDB.autoSellToVendor = not BG_GlobalDB.autoSellToVendor
	end)

	local nothingToSell = LibStub("tekKonfig-Checkbox").new(behavior, nil, BrokerGarbage.locale.showNothingToSellTitle, "TOPLEFT", sell, "BOTTOMLEFT", 14, 4)
	nothingToSell.tiptext = BrokerGarbage.locale.showNothingToSellText .. BrokerGarbage.locale.GlobalSetting
	nothingToSell:SetChecked(BG_GlobalDB.reportNothingToSell)
	local checksound = nothingToSell:GetScript("OnClick")
	nothingToSell:SetScript("OnClick", function(nothingToSell)
		checksound(nothingToSell)
		BG_GlobalDB.reportNothingToSell = not BG_GlobalDB.reportNothingToSell
	end)

	local repair = LibStub("tekKonfig-Checkbox").new(behavior, nil, BrokerGarbage.locale.autoRepairTitle, "TOPLEFT", nothingToSell, "BOTTOMLEFT", -14, 4)
	repair.tiptext = BrokerGarbage.locale.autoRepairText .. BrokerGarbage.locale.GlobalSetting
	repair:SetChecked(BG_GlobalDB.autoRepairAtVendor)
	local checksound = repair:GetScript("OnClick")
	repair:SetScript("OnClick", function(repair)
		checksound(repair)
		BG_GlobalDB.autoRepairAtVendor = not BG_GlobalDB.autoRepairAtVendor
	end)

	local guildrepair = LibStub("tekKonfig-Checkbox").new(behavior, nil, BrokerGarbage.locale.autoRepairGuildTitle, "TOPLEFT", repair, "BOTTOMLEFT", 14, 4)
=======
local function ShowOptions()
	-- ----------------------------------
	-- Statistics / Introductory frame
	-- ----------------------------------
	local title, subtitle = LibStub("tekKonfig-Heading").new(BrokerGarbage.options, "Broker_Garbage", BrokerGarbage.locale.StatisticsHeading)

	local noticetext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	noticetext:SetPoint("TOPLEFT", subtitle, "BOTTOMLEFT", 0, 0)
	noticetext:SetPoint("RIGHT", BrokerGarbage.options, -32, 0)
	noticetext:SetHeight(40)
	noticetext:SetNonSpaceWrap(true)
	noticetext:SetJustifyH("LEFT")
	noticetext:SetJustifyV("TOP")
	noticetext:SetText(BrokerGarbage.PT and "" or BrokerGarbage.locale.LPTNoticeText)

	UpdateAddOnMemoryUsage()
	local memoryusage = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	memoryusage:SetWidth(150)
	memoryusage:SetPoint("TOPLEFT", noticetext, "BOTTOMLEFT", -2, 0)
	memoryusage:SetJustifyH("RIGHT")
	memoryusage:SetText(BrokerGarbage.locale.MemoryUsageTitle)
	local mutext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	mutext:SetWidth(120)
	mutext:SetPoint("LEFT", memoryusage, "RIGHT", 4, 0)
	mutext:SetJustifyH("LEFT")
	mutext:SetText(math.floor(GetAddOnMemoryUsage("Broker_Garbage")))
	local muaction = CreateFrame("Button", nil, BrokerGarbage.options)
	muaction:SetPoint("LEFT", mutext, "RIGHT", 4, 0)
	muaction:SetWidth(16); muaction:SetHeight(16)
	muaction:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-Waiting")
	muaction.tiptext = BrokerGarbage.locale.CollectMemoryUsageTooltip
	muaction:SetScript("OnEnter", ShowTooltip)
	muaction:SetScript("OnLeave", HideTooltip)

	local auctionaddon = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	auctionaddon:SetWidth(150)
	auctionaddon:SetPoint("TOPLEFT", memoryusage, "BOTTOMLEFT", 0, -6)
	auctionaddon:SetJustifyH("RIGHT")
	auctionaddon:SetText(BrokerGarbage.locale.AuctionAddon)
	local aatext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	aatext:SetWidth(120)
	aatext:SetPoint("LEFT", auctionaddon, "RIGHT", 4, 0)
	aatext:SetJustifyH("LEFT")
	aatext:SetText(BrokerGarbage.auctionAddon)

	-- ----------------------------------------------------------------------------
	local globalmoneyinfo = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	globalmoneyinfo:SetPoint("TOPLEFT", auctionaddon, "BOTTOMLEFT", 0, -12)
	globalmoneyinfo:SetPoint("RIGHT", BrokerGarbage.options, -32, 0)
	globalmoneyinfo:SetNonSpaceWrap(true)
	globalmoneyinfo:SetJustifyH("LEFT")
	globalmoneyinfo:SetJustifyV("TOP")
	globalmoneyinfo:SetText(BrokerGarbage.locale.GlobalStatisticsHeading)

	local globalearned = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	globalearned:SetWidth(150)
	globalearned:SetPoint("TOPLEFT", globalmoneyinfo, "BOTTOMLEFT", 0, -15)
	globalearned:SetJustifyH("RIGHT")
	globalearned:SetText(BrokerGarbage.locale.GlobalMoneyEarnedTitle)
	local getext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	getext:SetWidth(120)
	getext:SetPoint("LEFT", globalearned, "RIGHT", 4, 0)
	getext:SetJustifyH("LEFT")
	getext:SetText(BrokerGarbage:FormatMoney(BG_GlobalDB.moneyEarned))
	local geaction = CreateFrame("Button", nil, BrokerGarbage.options)
	geaction:SetPoint("LEFT", getext, "RIGHT", 4, 0)
	geaction:SetWidth(16); geaction:SetHeight(16)
	geaction:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	geaction.tiptext = BrokerGarbage.locale.ResetGlobalMoneyEarnedTooltip
	geaction:SetScript("OnEnter", ShowTooltip)
	geaction:SetScript("OnLeave", HideTooltip)

	local itemssold = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	itemssold:SetWidth(150)
	itemssold:SetPoint("TOPLEFT", globalearned, "BOTTOMLEFT", 0, -6)
	itemssold:SetJustifyH("RIGHT")
	itemssold:SetText(BrokerGarbage.locale.GlobalItemsSoldTitle)
	local istext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	istext:SetWidth(120)
	istext:SetPoint("LEFT", itemssold, "RIGHT", 4, 0)
	istext:SetJustifyH("LEFT")
	istext:SetText(BG_GlobalDB.itemsSold)
	local isaction = CreateFrame("Button", nil, BrokerGarbage.options)
	isaction:SetPoint("LEFT", istext, "RIGHT", 4, 0)
	isaction:SetWidth(16); isaction:SetHeight(16)
	isaction:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	isaction.tiptext = BrokerGarbage.locale.ResetGlobalItemsSoldTooltip
	isaction:SetScript("OnEnter", ShowTooltip)
	isaction:SetScript("OnLeave", HideTooltip)

	local avgsold = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	avgsold:SetWidth(150)
	avgsold:SetPoint("TOPLEFT", itemssold, "BOTTOMLEFT", 0, -6)
	avgsold:SetJustifyH("RIGHT")
	avgsold:SetText(BrokerGarbage.locale.AverageSellValueTitle)
	local astext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	astext:SetWidth(120)
	astext:SetPoint("LEFT", avgsold, "RIGHT", 4, 0)
	astext:SetJustifyH("LEFT")
	astext:SetText(BrokerGarbage:FormatMoney(math.floor(BG_GlobalDB.moneyEarned / (BG_GlobalDB.itemsSold ~= 0 and BG_GlobalDB.itemsSold or 1))))

	-- ----------------------------------------------------------------------------
	local globallost = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	globallost:SetWidth(150)
	globallost:SetPoint("TOPLEFT", avgsold, "BOTTOMLEFT", 0, -15)
	globallost:SetJustifyH("RIGHT")
	globallost:SetText(BrokerGarbage.locale.GlobalMoneyLostTitle)
	local gltext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	gltext:SetWidth(120)
	gltext:SetPoint("LEFT", globallost, "RIGHT", 4, 0)
	gltext:SetJustifyH("LEFT")
	gltext:SetText(BrokerGarbage:FormatMoney(BG_GlobalDB.moneyLostByDeleting))
	local glaction = CreateFrame("Button", nil, BrokerGarbage.options)
	glaction:SetPoint("LEFT", gltext, "RIGHT", 4, 0)
	glaction:SetWidth(16); glaction:SetHeight(16)
	glaction:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	glaction.tiptext = BrokerGarbage.locale.ResetGlobalMoneyLostTooltip
	glaction:SetScript("OnEnter", ShowTooltip)
	glaction:SetScript("OnLeave", HideTooltip)

	local itemsdropped = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	itemsdropped:SetWidth(150)
	itemsdropped:SetPoint("TOPLEFT", globallost, "BOTTOMLEFT", 0, -6)
	itemsdropped:SetJustifyH("RIGHT")
	itemsdropped:SetText(BrokerGarbage.locale.ItemsDroppedTitle)
	local idtext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	idtext:SetWidth(120)
	idtext:SetPoint("LEFT", itemsdropped, "RIGHT", 4, 0)
	idtext:SetJustifyH("LEFT")
	idtext:SetText(BG_GlobalDB.itemsDropped)
	local idaction = CreateFrame("Button", nil, BrokerGarbage.options)
	idaction:SetPoint("LEFT", idtext, "RIGHT", 4, 0)
	idaction:SetWidth(16); idaction:SetHeight(16)
	idaction:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	idaction.tiptext = BrokerGarbage.locale.ResetGlobalItemsDroppedTooltip
	idaction:SetScript("OnEnter", ShowTooltip)
	idaction:SetScript("OnLeave", HideTooltip)

	local avglost = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	avglost:SetWidth(150)
	avglost:SetPoint("TOPLEFT", itemsdropped, "BOTTOMLEFT", 0, -6)
	avglost:SetJustifyH("RIGHT")
	avglost:SetText(BrokerGarbage.locale.AverageDropValueTitle)
	local altext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	altext:SetWidth(120)
	altext:SetPoint("LEFT", avglost, "RIGHT", 4, 0)
	altext:SetJustifyH("LEFT")
	altext:SetText(BrokerGarbage:FormatMoney(math.floor(BG_GlobalDB.moneyLostByDeleting / (BG_GlobalDB.itemsDropped ~= 0 and BG_GlobalDB.itemsDropped or 1))))

	-- ----------------------------------------------------------------------------
	local localmoneyinfo = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	localmoneyinfo:SetPoint("TOPLEFT", avglost, "BOTTOMLEFT", 0, -12)
	localmoneyinfo:SetPoint("RIGHT", BrokerGarbage.options, -32, 0)
	localmoneyinfo:SetNonSpaceWrap(true)
	localmoneyinfo:SetJustifyH("LEFT")
	localmoneyinfo:SetJustifyV("TOP")
	localmoneyinfo:SetText(format(BrokerGarbage.locale.LocalStatisticsHeading, UnitName("player")))

	local localearned = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	localearned:SetWidth(150)
	localearned:SetPoint("TOPLEFT", localmoneyinfo, "BOTTOMLEFT", 0, -15)
	localearned:SetJustifyH("RIGHT")
	localearned:SetText(BrokerGarbage.locale.StatisticsLocalAmountEarned)
	local letext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	letext:SetWidth(120)
	letext:SetPoint("LEFT", localearned, "RIGHT", 4, 0)
	letext:SetJustifyH("LEFT")
	letext:SetText(BrokerGarbage:FormatMoney(BG_LocalDB.moneyEarned))
	local leaction = CreateFrame("Button", nil, BrokerGarbage.options)
	leaction:SetPoint("LEFT", letext, "RIGHT", 4, 0)
	leaction:SetWidth(16); leaction:SetHeight(16)
	leaction:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	leaction.tiptext = BrokerGarbage.locale.ResetLocalMoneyEarnedTooltip
	leaction:SetScript("OnEnter", ShowTooltip)
	leaction:SetScript("OnLeave", HideTooltip)

	local locallost = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	locallost:SetWidth(150)
	locallost:SetPoint("TOPLEFT", localearned, "BOTTOMLEFT", 0, -15)
	locallost:SetJustifyH("RIGHT")
	locallost:SetText(BrokerGarbage.locale.StatisticsLocalAmountLost)
	local lltext = BrokerGarbage.options:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	lltext:SetWidth(120)
	lltext:SetPoint("LEFT", locallost, "RIGHT", 4, 0)
	lltext:SetJustifyH("LEFT")
	lltext:SetText(BrokerGarbage:FormatMoney(BG_LocalDB.moneyLostByDeleting))
	local llaction = CreateFrame("Button", nil, BrokerGarbage.options)
	llaction:SetPoint("LEFT", lltext, "RIGHT", 4, 0)
	llaction:SetWidth(16); llaction:SetHeight(16)
	llaction:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	llaction.tiptext = BrokerGarbage.locale.ResetLocalMoneyLostTooltip
	llaction:SetScript("OnEnter", ShowTooltip)
	llaction:SetScript("OnLeave", HideTooltip)

	-- ----------------------------------------------------------------------------
	-- when panel is shown this will update the statistics data
	local function UpdateStats()
		UpdateAddOnMemoryUsage()
		mutext:SetText(math.floor(GetAddOnMemoryUsage("Broker_Garbage")))

		getext:SetText(BrokerGarbage:FormatMoney(BG_GlobalDB.moneyEarned))
		istext:SetText(BG_GlobalDB.itemsSold)
		gltext:SetText(BrokerGarbage:FormatMoney(BG_GlobalDB.moneyLostByDeleting))
		idtext:SetText(BG_GlobalDB.itemsDropped)

		astext:SetText(BrokerGarbage:FormatMoney(math.floor(BG_GlobalDB.moneyEarned / (BG_GlobalDB.itemsSold ~= 0 and BG_GlobalDB.itemsSold or 1))))
		altext:SetText(BrokerGarbage:FormatMoney(math.floor(BG_GlobalDB.moneyLostByDeleting / (BG_GlobalDB.itemsDropped ~= 0 and BG_GlobalDB.itemsDropped or 1))))

		letext:SetText(BrokerGarbage:FormatMoney(BG_LocalDB.moneyEarned))
		lltext:SetText(BrokerGarbage:FormatMoney(BG_LocalDB.moneyLostByDeleting))
	end

	-- omg-i-reset-everything!!!!!! buttons
	local globalreset = LibStub("tekKonfig-Button").new(BrokerGarbage.options, "TOPLEFT", locallost, "BOTTOMLEFT", 0, -30)
	globalreset:SetText(BrokerGarbage.locale.ResetGlobalDataText)
	globalreset.tiptext = BrokerGarbage.locale.ResetGlobalDataTooltip
	globalreset:SetWidth(150)
	globalreset:SetScript("OnClick", function()
		BrokerGarbage:ResetAll(true)
		UpdateStats()
	end)

	local localreset = LibStub("tekKonfig-Button").new(BrokerGarbage.options, "TOPLEFT", globalreset, "TOPRIGHT", 20, 0)
	localreset:SetText(BrokerGarbage.locale.ResetLocalDataText)
	localreset.tiptext = BrokerGarbage.locale.ResetLocalDataTooltip
	localreset:SetWidth(150)
	localreset:SetScript("OnClick", function()
		BrokerGarbage:ResetAll(false)
		UpdateStats()
	end)

	local function OnClick(self)
		if self == muaction then
			collectgarbage("collect")
		elseif self == geaction then
			BrokerGarbage:ResetMoney("earned", true)
		elseif self == glaction then
			BrokerGarbage:ResetMoney("lost", true)
		elseif self == idaction then
			BG_GlobalDB.itemsDropped = 0
		elseif self == isaction then
			BG_GlobalDB.itemsSold = 0
		elseif self == leaction then
			BG_LocalDB.moneyEarned = 0
		elseif self == llaction then
			BG_LocalDB.moneyLostByDeleting = 0
		end

		UpdateStats()
	end
	muaction:SetScript("OnClick", OnClick)
	geaction:SetScript("OnClick", OnClick)
	isaction:SetScript("OnClick", OnClick)
	glaction:SetScript("OnClick", OnClick)
	idaction:SetScript("OnClick", OnClick)
	leaction:SetScript("OnClick", OnClick)
	llaction:SetScript("OnClick", OnClick)

	BrokerGarbage.options:SetScript("OnShow", UpdateStats)
end

local function ShowBasicOptions()
	-- ----------------------------------
	-- Basic Options
	-- ----------------------------------
	local title0, subtitle0 = LibStub("tekKonfig-Heading").new(BrokerGarbage.basicOptions, "Broker_Garbage - "..BrokerGarbage.locale.BasicOptionsTitle, BrokerGarbage.locale.BasicOptionsText)

	local autosell = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.autoSellTitle, "TOPLEFT", subtitle0, "BOTTOMLEFT", -2, -4)
	autosell.tiptext = BrokerGarbage.locale.autoSellText .. BrokerGarbage.locale.GlobalSetting
	autosell:SetChecked(BG_GlobalDB.autoSellToVendor)
	local checksound = autosell:GetScript("OnClick")
	autosell:SetScript("OnClick", function(autosell)
		checksound(autosell)
		BG_GlobalDB.autoSellToVendor = not BG_GlobalDB.autoSellToVendor
	end)

	local autosellicon = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.showAutoSellIconTitle, "TOPLEFT", autosell, "BOTTOMLEFT", 14, 0)
	autosellicon.tiptext = BrokerGarbage.locale.showAutoSellIconText .. BrokerGarbage.locale.GlobalSetting
	autosellicon:SetChecked(BG_GlobalDB.showAutoSellIcon)
	local checksound = autosellicon:GetScript("OnClick")
	autosellicon:SetScript("OnClick", function(autosellicon)
		checksound(autosellicon)
		BG_GlobalDB.showAutoSellIcon = not BG_GlobalDB.showAutoSellIcon
		BrokerGarbage:UpdateRepairButton()
	end)

	local nothingtext = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.showNothingToSellTitle, "TOPLEFT", autosellicon, "BOTTOMLEFT", 0, 0)
	nothingtext.tiptext = BrokerGarbage.locale.showNothingToSellText .. BrokerGarbage.locale.GlobalSetting
	nothingtext:SetChecked(BG_GlobalDB.reportNothingToSell)
	local checksound = nothingtext:GetScript("OnClick")
	nothingtext:SetScript("OnClick", function(nothingtext)
		checksound(nothingtext)
		BG_GlobalDB.reportNothingToSell = not BG_GlobalDB.reportNothingToSell
	end)

	local autorepair = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.autoRepairTitle, "LEFT", autosell, "LEFT", 200, 0)
	autorepair.tiptext = BrokerGarbage.locale.autoRepairText .. BrokerGarbage.locale.GlobalSetting
	autorepair:SetChecked(BG_GlobalDB.autoRepairAtVendor)
	local checksound = autorepair:GetScript("OnClick")
	autorepair:SetScript("OnClick", function(autorepair)
		checksound(autorepair)
		BG_GlobalDB.autoRepairAtVendor = not BG_GlobalDB.autoRepairAtVendor
	end)

	local guildrepair = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.autoRepairGuildTitle, "TOPLEFT", autorepair, "BOTTOMLEFT", 14, 0)
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
	guildrepair.tiptext = BrokerGarbage.locale.autoRepairGuildText
	guildrepair:SetChecked(BG_LocalDB.neverRepairGuildBank)
	local checksound = guildrepair:GetScript("OnClick")
	guildrepair:SetScript("OnClick", function(guildrepair)
		checksound(guildrepair)
		BG_LocalDB.neverRepairGuildBank = not BG_LocalDB.neverRepairGuildBank
	end)

<<<<<<< HEAD
	local sellGear = LibStub("tekKonfig-Checkbox").new(behavior, nil, BrokerGarbage.locale.sellNotUsableTitle, "TOPLEFT", guildrepair, "BOTTOMLEFT", -14, 4)
	sellGear.tiptext = BrokerGarbage.locale.sellNotUsableText .. BrokerGarbage.locale.GlobalSetting
	sellGear:SetChecked(BG_GlobalDB.sellNotWearable)
	local checksound = sellGear:GetScript("OnClick")
	sellGear:SetScript("OnClick", function(sellGear)
		checksound(sellGear)
		BG_GlobalDB.sellNotWearable = not BG_GlobalDB.sellNotWearable
		BrokerGarbage:ScanInventory()
	end)

	local enchanter = LibStub("tekKonfig-Checkbox").new(behavior, nil, BrokerGarbage.locale.enchanterTitle, "TOPLEFT", sellGear, "BOTTOMLEFT", 0, 4)
	enchanter.tiptext = BrokerGarbage.locale.enchanterTooltip .. BrokerGarbage.locale.GlobalSetting
	enchanter:SetChecked(BG_GlobalDB.hasEnchanter)
	local checksound = enchanter:GetScript("OnClick")
	enchanter:SetScript("OnClick", function(enchanter)
		checksound(enchanter)
		BG_GlobalDB.hasEnchanter = not BG_GlobalDB.hasEnchanter
	end)

	-- -----------------------------------------------------------------
	local line = CreateHorizontalRule(behavior)
	line:SetPoint("TOPLEFT", enchanter, "BOTTOMLEFT", 2, 2)
	line:SetPoint("RIGHT", -6, 2)
	-- -----------------------------------------------------------------

	local disableKey = CreateFrame("Frame", "BG_DisableKeyDropDown", behavior, "UIDropDownMenuTemplate")
	disableKey.tiptext = BrokerGarbage.locale.DKTooltip .. BrokerGarbage.locale.GlobalSetting
	disableKey.displayMode = "MENU"
	disableKey:SetScript("OnEnter", ShowTooltip)
	disableKey:SetScript("OnLeave", HideTooltip)
       disableKey:SetPoint("TOPLEFT", enchanter, "BOTTOMLEFT", -8, -20)
	local disableKeyLabel = disableKey:CreateFontString(nil, "BACKGROUND", "GameFontNormalSmall")
	disableKeyLabel:SetPoint("BOTTOMLEFT", disableKey, "TOPLEFT", 20, 2)
	disableKeyLabel:SetText(BrokerGarbage.locale.DKTitle)
	_G[disableKey:GetName() .. "Button"]:SetPoint("LEFT", _G[disableKey:GetName().."Middle"])
	UIDropDownMenu_SetSelectedValue(disableKey, BG_GlobalDB.disableKey)
	UIDropDownMenu_SetText(disableKey, BrokerGarbage.locale.disableKeys[BG_GlobalDB.disableKey])

	local function DisableKeyOnSelect(self)
		UIDropDownMenu_SetSelectedValue(disableKey, self.value)
=======
	local showsource = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.showSourceTitle, "TOPLEFT", guildrepair, "BOTTOMLEFT", -14, 0)
	showsource.tiptext = BrokerGarbage.locale.showSourceText .. BrokerGarbage.locale.GlobalSetting
	showsource:SetChecked(BG_GlobalDB.showSource)
	local checksound = showsource:GetScript("OnClick")
	showsource:SetScript("OnClick", function(showsource)
		checksound(showsource)
		BG_GlobalDB.showSource = not BG_GlobalDB.showSource
	end)

	local showlost = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.showLostTitle, "TOPLEFT", nothingtext, "BOTTOMLEFT", -14, 0)
	showlost.tiptext = BrokerGarbage.locale.showLostText .. BrokerGarbage.locale.GlobalSetting
	showlost:SetChecked(BG_GlobalDB.showLost)
	local checksound = showlost:GetScript("OnClick")
	showlost:SetScript("OnClick", function(showlost)
		checksound(showlost)
		BG_GlobalDB.showLost = not BG_GlobalDB.showLost
	end)

	local showearned = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.showEarnedTitle, "LEFT", showlost, "LEFT", 200, 0)
	showearned.tiptext = BrokerGarbage.locale.showEarnedText .. BrokerGarbage.locale.GlobalSetting
	showearned:SetChecked(BG_GlobalDB.showEarned)
	local checksound = showearned:GetScript("OnClick")
	showearned:SetScript("OnClick", function(showearned)
		checksound(showearned)
		BG_GlobalDB.showEarned = not BG_GlobalDB.showEarned
	end)

	local quality = LibStub("tekKonfig-Slider").new(BrokerGarbage.basicOptions, BrokerGarbage.locale.dropQualityTitle, 0, 7, "TOPLEFT", showlost, "BOTTOMLEFT", 5, -10)
	quality.tiptext = BrokerGarbage.locale.dropQualityText .. BrokerGarbage.locale.GlobalSetting
	quality:SetWidth(200)
	quality:SetValueStep(1)
	quality:SetValue(BG_GlobalDB.dropQuality)
	quality.text = quality:CreateFontString("$parentCenterText", "ARTWORK", "GameFontHighlightSmall")
	quality.text:SetPoint("TOP", quality, "BOTTOM", 0, 3)
	quality.text:SetText(BrokerGarbage.quality[BG_GlobalDB.dropQuality])
	quality:SetScript("OnValueChanged", function(quality)
		BG_GlobalDB.dropQuality = quality:GetValue()
		quality.text:SetText(BrokerGarbage.quality[quality:GetValue()])
		BrokerGarbage:ScanInventory()
	end)

	local testValue = 130007
	local moneyFormat = LibStub("tekKonfig-Slider").new(BrokerGarbage.basicOptions, BrokerGarbage.locale.moneyFormatTitle, 0, 4, "LEFT", quality, "LEFT", 200, 0)
	moneyFormat.tiptext = BrokerGarbage.locale.moneyFormatText .. BrokerGarbage.locale.GlobalSetting
	moneyFormat:SetWidth(200)
	moneyFormat:SetValueStep(1);
	moneyFormat:SetValue(BG_GlobalDB.showMoney)
	moneyFormat.text = moneyFormat:CreateFontString("$parentCenterText", "ARTWORK", "GameFontHighlightSmall")
	moneyFormat.text:SetPoint("TOP", moneyFormat, "BOTTOM", 0, 3)
	moneyFormat.text:SetText(BrokerGarbage:FormatMoney(testValue))
	moneyFormat:SetScript("OnValueChanged", function(moneyFormat)
		BG_GlobalDB.showMoney = moneyFormat:GetValue()
		moneyFormat.text:SetText(BrokerGarbage:FormatMoney(testValue))
	end)

	local ttMaxItems = LibStub("tekKonfig-Slider").new(BrokerGarbage.basicOptions, BrokerGarbage.locale.maxItemsTitle, 0, 50, "TOPLEFT", quality, "BOTTOMLEFT", 0, -15)
	ttMaxItems.tiptext = BrokerGarbage.locale.maxItemsText .. BrokerGarbage.locale.GlobalSetting
	ttMaxItems:SetWidth(200)
	ttMaxItems:SetValueStep(1);
	ttMaxItems:SetValue(BG_GlobalDB.tooltipNumItems)
	ttMaxItems.text = ttMaxItems:CreateFontString("$parentCenterText", "ARTWORK", "GameFontHighlightSmall")
	ttMaxItems.text:SetPoint("TOP", ttMaxItems, "BOTTOM", 0, 3)
	ttMaxItems.text:SetText(ttMaxItems:GetValue())
	ttMaxItems:SetScript("OnValueChanged", function(ttMaxItems)
		BG_GlobalDB.tooltipNumItems = ttMaxItems:GetValue()
		ttMaxItems.text:SetText(ttMaxItems:GetValue())
	end)

	local ttMaxHeight = LibStub("tekKonfig-Slider").new(BrokerGarbage.basicOptions, BrokerGarbage.locale.maxHeightTitle, 0, 400, "LEFT", ttMaxItems, "LEFT", 200, 0)
	ttMaxHeight.tiptext = BrokerGarbage.locale.maxHeightText .. BrokerGarbage.locale.GlobalSetting
	ttMaxHeight:SetWidth(200)
	ttMaxHeight:SetValueStep(10);
	ttMaxHeight:SetValue(BG_GlobalDB.tooltipMaxHeight)
	ttMaxHeight.text = ttMaxHeight:CreateFontString("$parentCenterText", "ARTWORK", "GameFontHighlightSmall")
	ttMaxHeight.text:SetPoint("TOP", ttMaxHeight, "BOTTOM", 0, 3)
	ttMaxHeight.text:SetText(ttMaxHeight:GetValue())
	ttMaxHeight:SetScript("OnValueChanged", function(ttMaxHeight)
		BG_GlobalDB.tooltipMaxHeight = ttMaxHeight:GetValue()
		ttMaxHeight.text:SetText(ttMaxHeight:GetValue())
	end)

	local sellNotUsable = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.sellNotUsableTitle, "TOPLEFT", ttMaxItems, "BOTTOMLEFT", 0, -10)
	sellNotUsable.tiptext = BrokerGarbage.locale.sellNotUsableText .. BrokerGarbage.locale.GlobalSetting
	sellNotUsable:SetChecked(BG_GlobalDB.sellNotWearable)
	local checksound = sellNotUsable:GetScript("OnClick")
	sellNotUsable:SetScript("OnClick", function(sellNotUsable)
		checksound(sellNotUsable)
		BG_GlobalDB.sellNotWearable = not BG_GlobalDB.sellNotWearable
		BrokerGarbage:ScanInventory()
	end)
	local sellNUQuality = LibStub("tekKonfig-Slider").new(BrokerGarbage.basicOptions, BrokerGarbage.locale.SNUMaxQualityTitle, 0, 6, "TOPLEFT", sellNotUsable, "BOTTOMLEFT", 25, -4)
	sellNUQuality.tiptext = BrokerGarbage.locale.SNUMaxQualityText .. BrokerGarbage.locale.GlobalSetting
	sellNUQuality:SetWidth(200)
	sellNUQuality:SetValueStep(1);
	sellNUQuality:SetValue(BG_GlobalDB.sellNWQualityTreshold)
	sellNUQuality.text = sellNUQuality:CreateFontString("$parentCenterText", "ARTWORK", "GameFontHighlightSmall")
	sellNUQuality.text:SetPoint("TOP", sellNUQuality, "BOTTOM", 0, 3)
	sellNUQuality.text:SetText(BrokerGarbage.quality[sellNUQuality:GetValue()])
	sellNUQuality:SetScript("OnValueChanged", function(sellNUQuality)
		BG_GlobalDB.sellNWQualityTreshold = sellNUQuality:GetValue()
		sellNUQuality.text:SetText(BrokerGarbage.quality[sellNUQuality:GetValue()])
		BrokerGarbage:ScanInventory()
	end)

	local disableKey, disableKeytext, disableKeycontainer = LibStub("tekKonfig-Dropdown").new(BrokerGarbage.basicOptions, BrokerGarbage.locale.DKTitle, "TOPLEFT", sellNUQuality, "BOTTOMLEFT", -25, -16)
	disableKeytext:SetText(BrokerGarbage.locale.disableKeys[BG_GlobalDB.disableKey])
	disableKey.tiptext = BrokerGarbage.locale.DKTooltip .. BrokerGarbage.locale.GlobalSetting

	local function OnClick(self)
		UIDropDownMenu_SetSelectedValue(disableKey, self.value)
		disableKeytext:SetText(BrokerGarbage.locale.disableKeys[self.value])
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
		BG_GlobalDB.disableKey = self.value
	end
	UIDropDownMenu_Initialize(disableKey, function()
		local selected, info = UIDropDownMenu_GetSelectedValue(disableKey), UIDropDownMenu_CreateInfo()
<<<<<<< HEAD
		for name in pairs(BrokerGarbage.disableKey) do
			info.text = BrokerGarbage.locale.disableKeys[name]
			info.value = name
			info.func = DisableKeyOnSelect
=======

		for name in pairs(BrokerGarbage.disableKey) do
			info.text = BrokerGarbage.locale.disableKeys[name]
			info.value = name
			info.func = OnClick
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
			info.checked = name == selected
			UIDropDownMenu_AddButton(info)
		end
	end)

<<<<<<< HEAD
	local treshold = LibStub("tekKonfig-Group").new(panel, BrokerGarbage.locale.GroupTresholds, "TOPLEFT", behavior, "BOTTOMLEFT", 0, -14)
	treshold:SetHeight(100); treshold:SetWidth(180)
	treshold:SetBackdropColor(0.1, 0.1, 0.1, 0.4)

	local qualityTreshold = CreateFrame("Frame", "BG_DropQualityDropDown", treshold, "UIDropDownMenuTemplate")
	qualityTreshold.displayMode = "MENU"
	qualityTreshold:SetPoint("TOPLEFT", treshold, -4, -20)
	_G[qualityTreshold:GetName() .. "Button"]:SetPoint("LEFT", _G[qualityTreshold:GetName().."Middle"])
	_G[qualityTreshold:GetName() .. "Button"].tiptext = BrokerGarbage.locale.dropQualityText .. BrokerGarbage.locale.GlobalSetting
	_G[qualityTreshold:GetName() .. "Button"]:SetScript("OnEnter", ShowTooltip)
	_G[qualityTreshold:GetName() .. "Button"]:SetScript("OnLeave", HideTooltip)

	local qualityTresholdLabel = qualityTreshold:CreateFontString(nil, "BACKGROUND", "GameFontNormalSmall")
	qualityTresholdLabel:SetPoint("BOTTOMLEFT", qualityTreshold, "TOPLEFT", 20, 2)
	qualityTresholdLabel:SetText(BrokerGarbage.locale.dropQualityTitle)
	UIDropDownMenu_SetSelectedValue(qualityTreshold, BG_GlobalDB.dropQuality)
	UIDropDownMenu_SetText(qualityTreshold, BrokerGarbage.quality[BG_GlobalDB.dropQuality])
	local function DropQualityOnSelect(self)
		UIDropDownMenu_SetSelectedValue(qualityTreshold, self.value)
		BG_GlobalDB.dropQuality = self.value
		BrokerGarbage:ScanInventory()
	end
	UIDropDownMenu_Initialize(qualityTreshold, function(self)
		local selected, info = UIDropDownMenu_GetSelectedValue(self), UIDropDownMenu_CreateInfo()
		for i = 0, #BrokerGarbage.quality do
			info.text = BrokerGarbage.quality[i]
			info.value = i
			info.func = DropQualityOnSelect
			info.checked = i == selected
			UIDropDownMenu_AddButton(info)
		end
	end)


	local sellGearTeshold = CreateFrame("Frame", "BG_SellQualityDropDown", treshold, "UIDropDownMenuTemplate")
	sellGearTeshold.displayMode = "MENU"
	sellGearTeshold:SetPoint("TOPLEFT", qualityTreshold, "BOTTOMLEFT", 0, -15)
	_G[sellGearTeshold:GetName() .. "Button"]:SetPoint("LEFT", _G[sellGearTeshold:GetName().."Middle"])
	_G[sellGearTeshold:GetName() .. "Button"].tiptext = BrokerGarbage.locale.SNUMaxQualityText .. BrokerGarbage.locale.GlobalSetting
	_G[sellGearTeshold:GetName() .. "Button"]:SetScript("OnEnter", ShowTooltip)
	_G[sellGearTeshold:GetName() .. "Button"]:SetScript("OnLeave", HideTooltip)

	local sellGearTesholdLabel = sellGearTeshold:CreateFontString(nil, "BACKGROUND", "GameFontNormalSmall")
	sellGearTesholdLabel:SetPoint("BOTTOMLEFT", sellGearTeshold, "TOPLEFT", 20, 2)
	sellGearTesholdLabel:SetText(BrokerGarbage.locale.SNUMaxQualityTitle)
	UIDropDownMenu_SetSelectedValue(sellGearTeshold, BG_GlobalDB.sellNWQualityTreshold)
	UIDropDownMenu_SetText(sellGearTeshold, BrokerGarbage.quality[BG_GlobalDB.sellNWQualityTreshold])
	local function SellQualityOnSelect(self)
		UIDropDownMenu_SetSelectedValue(sellGearTeshold, self.value)
		BG_GlobalDB.sellNWQualityTreshold = self.value
		BrokerGarbage:ScanInventory()
	end
	UIDropDownMenu_Initialize(sellGearTeshold, function(self)
		local selected, info = UIDropDownMenu_GetSelectedValue(self), UIDropDownMenu_CreateInfo()
		for i = 0, #BrokerGarbage.quality do
			info.text = BrokerGarbage.quality[i]
			info.value = i
			info.func = SellQualityOnSelect
			info.checked = i == selected
			UIDropDownMenu_AddButton(info)
		end
	end)

	local display = LibStub("tekKonfig-Group").new(panel, BrokerGarbage.locale.GroupDisplay, "TOPLEFT", behavior, "TOPRIGHT", 10, 0)
	display:SetHeight(150); display:SetWidth(180)
	display:SetBackdropColor(0.1, 0.1, 0.1, 0.4)

	local sellIcon = LibStub("tekKonfig-Checkbox").new(display, nil, BrokerGarbage.locale.showAutoSellIconTitle, "TOPLEFT", display, "TOPLEFT", 4, -2)
	sellIcon.tiptext = BrokerGarbage.locale.showAutoSellIconText .. BrokerGarbage.locale.GlobalSetting
	sellIcon:SetChecked(BG_GlobalDB.showAutoSellIcon)
	local checksound = sellIcon:GetScript("OnClick")
	sellIcon:SetScript("OnClick", function(sellIcon)
		checksound(sellIcon)
		BG_GlobalDB.showAutoSellIcon = not BG_GlobalDB.showAutoSellIcon
		BrokerGarbage:UpdateRepairButton()
	end)

	-- -----------------------------------------------------------------
	local lineDisplay = CreateHorizontalRule(display)
	lineDisplay:SetPoint("TOPLEFT", sellIcon, "BOTTOMLEFT", 2, 2)
	lineDisplay:SetPoint("RIGHT", -6, 2)
	-- -----------------------------------------------------------------

	local function ResetEditBox(self)
		self:SetText(BG_GlobalDB[self.setting])
		self:ClearFocus()
		BrokerGarbage:ScanInventory()
	end
	local function SubmitEditBox(self)
		BG_GlobalDB[self.setting] = self:GetText()
		self:SetText(BG_GlobalDB[self.setting])
		self:ClearFocus()
		BrokerGarbage:ScanInventory()
	end
	local function ResetEditBoxDefault(self)
		BG_GlobalDB[self.setting] = BrokerGarbage.defaultGlobalSettings[self.setting]
		self:SetText(BG_GlobalDB[self.setting])
		self:ClearFocus()
		BrokerGarbage:ScanInventory()
	end

	local LDBtitle = display:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	LDBtitle:SetPoint("TOPLEFT", sellIcon, "BOTTOMLEFT", 8, -10)
	LDBtitle:SetText(BrokerGarbage.locale.LDBDisplayTextTitle)

	local editHelp = CreateFrame("Button", nil, display)
	editHelp:SetPoint("LEFT", LDBtitle, "RIGHT", 2, 0)
	editHelp:SetWidth(12); editHelp:SetHeight(12)
	editHelp:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-Waiting")
	editHelp.tiptext = BrokerGarbage.locale.LDBDisplayTextHelpTooltip
	editHelp:SetScript("OnEnter", ShowTooltip)
	editHelp:SetScript("OnLeave", HideTooltip)

	-- LDB format string for "Junk"
	local junkText = CreateFrame("EditBox", nil, display)
	CreateFrameBorders(junkText)
	junkText:SetPoint("TOPLEFT", LDBtitle, "BOTTOMLEFT", 2, 2)
	junkText:SetWidth(140); junkText:SetHeight(32)
	junkText:SetFontObject("GameFontHighlightSmall")
	junkText:SetAutoFocus(false)
	junkText:SetText(BG_GlobalDB.LDBformat)
	junkText.tiptext = BrokerGarbage.locale.LDBDisplayTextTooltip .. BrokerGarbage.locale.GlobalSetting
	junkText.setting = "LDBformat"

	junkText:SetScript("OnEscapePressed", ResetEditBox)
	junkText:SetScript("OnEnterPressed", SubmitEditBox)
	junkText:SetScript("OnEnter", ShowTooltip)
	junkText:SetScript("OnLeave", HideTooltip)

	local editReset = CreateFrame("Button", nil, display)
	editReset:SetPoint("LEFT", junkText, "RIGHT", 4, 0)
	editReset:SetWidth(16); editReset:SetHeight(16)
	editReset:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	editReset.tiptext = BrokerGarbage.locale.ResetToDefault
	editReset:SetScript("OnEnter", ShowTooltip)
	editReset:SetScript("OnLeave", HideTooltip)
	editReset:SetScript("OnClick", ResetEditBoxDefault)

	-- LDB format string for "No Junk"
	local noJunkText = CreateFrame("EditBox", nil, display)
	CreateFrameBorders(noJunkText)
	noJunkText:SetPoint("TOPLEFT", junkText, "BOTTOMLEFT", 0, 12)
	noJunkText:SetAutoFocus(false)
	noJunkText:SetWidth(140); noJunkText:SetHeight(32)
	noJunkText:SetFontObject("GameFontHighlightSmall")
	noJunkText:SetText(BG_GlobalDB.LDBNoJunk)
	noJunkText.tiptext = BrokerGarbage.locale.LDBNoJunkTextTooltip .. BrokerGarbage.locale.GlobalSetting
	noJunkText.setting = "LDBNoJunk"

	noJunkText:SetScript("OnEscapePressed", ResetEditBox)
	noJunkText:SetScript("OnEnterPressed", SubmitEditBox)
	noJunkText:SetScript("OnEnter", ShowTooltip)
	noJunkText:SetScript("OnLeave", HideTooltip)

	local editReset2 = CreateFrame("Button", nil, display)
	editReset2:SetPoint("LEFT", noJunkText, "RIGHT", 4, 0)
	editReset2:SetWidth(16); editReset2:SetHeight(16)
	editReset2:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	editReset2.tiptext = BrokerGarbage.locale.ResetToDefault
=======
	local enchanter = LibStub("tekKonfig-Checkbox").new(BrokerGarbage.basicOptions, nil, BrokerGarbage.locale.enchanterTitle, "LEFT", sellNotUsable, "LEFT", 200, 0)
	enchanter.tiptext = BrokerGarbage.locale.enchanterTooltip .. BrokerGarbage.locale.GlobalSetting
	enchanter:SetChecked(BG_GlobalDB.hasEnchanter)
	local checksound = enchanter:GetScript("OnClick")
	enchanter:SetScript("OnClick", function(enchanter)
		checksound(enchanter)
		BG_GlobalDB.hasEnchanter = not BG_GlobalDB.hasEnchanter
	end)

	-- LDB format string for "Junk"
	local editbox = CreateFrame("EditBox", nil, BrokerGarbage.basicOptions)
	editbox:SetAutoFocus(false)
	editbox:SetWidth(150); editbox:SetHeight(32)
	editbox:SetFontObject("GameFontHighlightSmall")
	editbox:SetText(BG_GlobalDB.LDBformat)
	editbox.tiptext = BrokerGarbage.locale.LDBDisplayTextTooltip .. BrokerGarbage.locale.GlobalSetting

	local left = editbox:CreateTexture(nil, "BACKGROUND")
	left:SetWidth(8) left:SetHeight(20)
	left:SetPoint("LEFT", -5, 0)
	left:SetTexture("Interface\\Common\\Common-Input-Border")
	left:SetTexCoord(0, 0.0625, 0, 0.625)
	local right = editbox:CreateTexture(nil, "BACKGROUND")
	right:SetWidth(8) right:SetHeight(20)
	right:SetPoint("RIGHT", 0, 0)
	right:SetTexture("Interface\\Common\\Common-Input-Border")
	right:SetTexCoord(0.9375, 1, 0, 0.625)
	local center = editbox:CreateTexture(nil, "BACKGROUND")
	center:SetHeight(20)
	center:SetPoint("RIGHT", right, "LEFT", 0, 0)
	center:SetPoint("LEFT", left, "RIGHT", 0, 0)
	center:SetTexture("Interface\\Common\\Common-Input-Border")
	center:SetTexCoord(0.0625, 0.9375, 0, 0.625)

	local LDBtitle = editbox:CreateFontString(nil, "ARTWORK", "GameFontNormal")
	LDBtitle:SetPoint("TOPLEFT", enchanter, "BOTTOMLEFT", 0, -10)
	LDBtitle:SetText(BrokerGarbage.locale.LDBDisplayTextTitle)

	editbox:SetPoint("TOPLEFT", LDBtitle, "BOTTOMLEFT", 14, 0)
	local function ResetEditBox(self)
		self:SetText(BG_GlobalDB.LDBformat)
		self:ClearFocus()
		BrokerGarbage:ScanInventory()
	end
	local function SubmitEditBox()
		BG_GlobalDB.LDBformat = editbox:GetText()
		editbox:SetText(BG_GlobalDB.LDBformat)
		editbox:ClearFocus()
		BrokerGarbage:ScanInventory()
	end
	local function ResetEditBoxDefault()
		BG_GlobalDB.LDBformat = BrokerGarbage.defaultGlobalSettings.LDBformat
		editbox:SetText(BG_GlobalDB.LDBformat)
		editbox:ClearFocus()
		BrokerGarbage:ScanInventory()
	end
	editbox:SetScript("OnEscapePressed", ResetEditBox)
	editbox:SetScript("OnEnterPressed", SubmitEditBox)
	editbox:SetScript("OnEnter", ShowTooltip)

	local editReset = CreateFrame("Button", nil, BrokerGarbage.basicOptions)
	editReset:SetPoint("LEFT", editbox, "RIGHT", 4, 0)
	editReset:SetWidth(16); editReset:SetHeight(16)
	editReset:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	editReset.tiptext = BrokerGarbage.locale.LDBDisplayTextResetTooltip
	editReset:SetScript("OnEnter", ShowTooltip)
	editReset:SetScript("OnLeave", HideTooltip)
	editReset:SetScript("OnClick", ResetEditBoxDefault)
	local editHelp = CreateFrame("Button", nil, BrokerGarbage.basicOptions)
	editHelp:SetPoint("LEFT", LDBtitle, "RIGHT", 2, 0)
	editHelp:SetWidth(16); editHelp:SetHeight(16)
	editHelp:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-Waiting")
	editHelp.tiptext = BrokerGarbage.locale.LDBDisplayTextHelpTooltip
	editHelp:SetScript("OnEnter", ShowTooltip)
	editHelp:SetScript("OnLeave", HideTooltip)

	-- LDB format string for "No Junk"
	local editbox2 = CreateFrame("EditBox", nil, BrokerGarbage.basicOptions)
	editbox2:SetAutoFocus(false)
	editbox2:SetWidth(150); editbox2:SetHeight(32)
	editbox2:SetFontObject("GameFontHighlightSmall")
	editbox2:SetText(BG_GlobalDB.LDBNoJunk)
	editbox2.tiptext = BrokerGarbage.locale.LDBNoJunkTextTooltip .. BrokerGarbage.locale.GlobalSetting

	local left2 = editbox2:CreateTexture(nil, "BACKGROUND")
	left2:SetWidth(8) left2:SetHeight(20)
	left2:SetPoint("LEFT", -5, 0)
	left2:SetTexture("Interface\\Common\\Common-Input-Border")
	left2:SetTexCoord(0, 0.0625, 0, 0.625)
	local right2 = editbox2:CreateTexture(nil, "BACKGROUND")
	right2:SetWidth(8) right2:SetHeight(20)
	right2:SetPoint("RIGHT", 0, 0)
	right2:SetTexture("Interface\\Common\\Common-Input-Border")
	right2:SetTexCoord(0.9375, 1, 0, 0.625)
	local center2 = editbox2:CreateTexture(nil, "BACKGROUND")
	center2:SetHeight(20)
	center2:SetPoint("RIGHT", right2, "LEFT", 0, 0)
	center2:SetPoint("LEFT", left2, "RIGHT", 0, 0)
	center2:SetTexture("Interface\\Common\\Common-Input-Border")
	center2:SetTexCoord(0.0625, 0.9375, 0, 0.625)

	editbox2:SetPoint("TOPLEFT", editbox, "BOTTOMLEFT", 0, 12)
	local function ResetEditBox(self)
		self:SetText(BG_GlobalDB.LDBNoJunk)
		self:ClearFocus()
		BrokerGarbage:ScanInventory()
	end
	local function SubmitEditBox()
		BG_GlobalDB.LDBNoJunk = editbox2:GetText()
		editbox2:SetText(BG_GlobalDB.LDBNoJunk)
		editbox2:ClearFocus()
		BrokerGarbage:ScanInventory()
	end
	local function ResetEditBoxDefault()
		BG_GlobalDB.LDBNoJunk = BrokerGarbage.locale.label
		editbox2:SetText(BG_GlobalDB.LDBNoJunk)
		editbox2:ClearFocus()
		BrokerGarbage:ScanInventory()
	end
	editbox2:SetScript("OnEscapePressed", ResetEditBox)
	editbox2:SetScript("OnEnterPressed", SubmitEditBox)
	editbox2:SetScript("OnEnter", ShowTooltip)
	editbox2:SetScript("OnLeave", HideTooltip)

	local editReset2 = CreateFrame("Button", nil, BrokerGarbage.basicOptions)
	editReset2:SetPoint("LEFT", editbox2, "RIGHT", 4, 0)
	editReset2:SetWidth(16); editReset2:SetHeight(16)
	editReset2:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
	editReset2.tiptext = BrokerGarbage.locale.LDBNoJunkTextResetTooltip
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
	editReset2:SetScript("OnEnter", ShowTooltip)
	editReset2:SetScript("OnLeave", HideTooltip)
	editReset2:SetScript("OnClick", ResetEditBoxDefault)

<<<<<<< HEAD
	-- -----------------------------------------------------------------
	local lineDisplay2 = CreateHorizontalRule(display)
	lineDisplay2:SetPoint("TOPLEFT", noJunkText, "BOTTOMLEFT", -10, 2)
	lineDisplay2:SetPoint("RIGHT", -6, 2)
	-- -----------------------------------------------------------------

	local testValue = 130007
	local moneyFormat = CreateFrame("Frame", "BG_MoneyFormatDropDown", display, "UIDropDownMenuTemplate")
	moneyFormat.displayMode = "MENU"
	moneyFormat:SetPoint("TOPLEFT", noJunkText, "BOTTOMLEFT", -20, -20)
	_G[moneyFormat:GetName() .. "Button"]:SetPoint("LEFT", _G[moneyFormat:GetName().."Middle"])
	_G[moneyFormat:GetName() .. "Button"].tiptext = BrokerGarbage.locale.moneyFormatText .. BrokerGarbage.locale.GlobalSetting
	_G[moneyFormat:GetName() .. "Button"]:SetScript("OnEnter", ShowTooltip)
	_G[moneyFormat:GetName() .. "Button"]:SetScript("OnLeave", HideTooltip)

	local moneyFormatLabel = moneyFormat:CreateFontString(nil, "BACKGROUND", "GameFontNormalSmall")
	moneyFormatLabel:SetPoint("BOTTOMLEFT", moneyFormat, "TOPLEFT", 20, 2)
	moneyFormatLabel:SetText(BrokerGarbage.locale.moneyFormatTitle)
	UIDropDownMenu_SetSelectedValue(moneyFormat, BG_GlobalDB.showMoney)
	UIDropDownMenu_SetText(moneyFormat, BrokerGarbage:FormatMoney(testValue))
	local function MoneyFormatOnSelect(self)
		UIDropDownMenu_SetSelectedValue(moneyFormat, self.value)
		BG_GlobalDB.showMoney = self.value
		BrokerGarbage:ScanInventory()
	end
	UIDropDownMenu_Initialize(moneyFormat, function(self)
		local selected, info = UIDropDownMenu_GetSelectedValue(self), UIDropDownMenu_CreateInfo()
		for i = 0, 4 do	-- currently 4 formats are supported
			info.text = BrokerGarbage:FormatMoney(testValue, i)
			info.value = i
			info.func = MoneyFormatOnSelect
			info.checked = i == selected
			UIDropDownMenu_AddButton(info)
		end
	end)

	local tooltip = LibStub("tekKonfig-Group").new(panel, BrokerGarbage.locale.GroupTooltip, "TOPLEFT", display, "BOTTOMLEFT", 0, -14)
	tooltip:SetHeight(140); tooltip:SetWidth(180)
	tooltip:SetBackdropColor(0.1, 0.1, 0.1, 0.4)

	local showSource = LibStub("tekKonfig-Checkbox").new(tooltip, nil, BrokerGarbage.locale.showSourceTitle, "TOPLEFT", tooltip, "TOPLEFT", 4, -2)
	showSource.tiptext = BrokerGarbage.locale.showSourceText .. BrokerGarbage.locale.GlobalSetting
	showSource:SetChecked(BG_GlobalDB.showSource)
	local checksound = showSource:GetScript("OnClick")
	showSource:SetScript("OnClick", function(showSource)
		checksound(showSource)
		BG_GlobalDB.showSource = not BG_GlobalDB.showSource
	end)

	local showEarned = LibStub("tekKonfig-Checkbox").new(tooltip, nil, BrokerGarbage.locale.showEarnedTitle, "TOPLEFT", showSource, "BOTTOMLEFT", 0, 4)
	showEarned.tiptext = BrokerGarbage.locale.showEarnedText .. BrokerGarbage.locale.GlobalSetting
	showEarned:SetChecked(BG_GlobalDB.showEarned)
	local checksound = showEarned:GetScript("OnClick")
	showEarned:SetScript("OnClick", function(showEarned)
		checksound(showEarned)
		BG_GlobalDB.showEarned = not BG_GlobalDB.showEarned
	end)

	local showLost = LibStub("tekKonfig-Checkbox").new(tooltip, nil, BrokerGarbage.locale.showLostTitle, "TOPLEFT", showEarned, "BOTTOMLEFT", 0, 4)
	showLost.tiptext = BrokerGarbage.locale.showLostText .. BrokerGarbage.locale.GlobalSetting
	showLost:SetChecked(BG_GlobalDB.showLost)
	local checksound = showLost:GetScript("OnClick")
	showLost:SetScript("OnClick", function(showLost)
		checksound(showLost)
		BG_GlobalDB.showLost = not BG_GlobalDB.showLost
	end)

	-- -----------------------------------------------------------------
	local lineTooltip = CreateHorizontalRule(tooltip)
	lineTooltip:SetPoint("TOPLEFT", showLost, "BOTTOMLEFT", 2, 2)
	lineTooltip:SetPoint("RIGHT", -6, 2)
	-- -----------------------------------------------------------------

	local numItems, numItemsText, _, low, high = LibStub("tekKonfig-Slider").new(tooltip,
		BrokerGarbage.locale.maxItemsTitle .. ": " .. BG_GlobalDB.tooltipNumItems,
		0, 50, "TOPLEFT", showLost, "BOTTOMLEFT", 12, -5)
	numItems.tiptext = BrokerGarbage.locale.maxItemsText .. BrokerGarbage.locale.GlobalSetting
	numItems:SetWidth(165)
	numItems:SetValueStep(1);
	numItems:SetValue(BG_GlobalDB.tooltipNumItems)
	numItems:SetScript("OnValueChanged", function(numItems)
		BG_GlobalDB.tooltipNumItems = numItems:GetValue()
		numItemsText:SetText(BrokerGarbage.locale.maxItemsTitle .. ": " .. numItems:GetValue())
	end)
	low:Hide(); high:Hide()

	local tooltipHeight, tooltipHeightText, _, low, high = LibStub("tekKonfig-Slider").new(tooltip,
		BrokerGarbage.locale.maxHeightTitle .. ": " .. BG_GlobalDB.tooltipMaxHeight,
		0, 500, "TOPLEFT", numItems, "BOTTOMLEFT", 0, -2)
	tooltipHeight.tiptext = BrokerGarbage.locale.maxHeightText .. BrokerGarbage.locale.GlobalSetting
	tooltipHeight:SetWidth(160)
	tooltipHeight:SetValueStep(10);
	tooltipHeight:SetValue(BG_GlobalDB.tooltipMaxHeight)
	tooltipHeight:SetScript("OnValueChanged", function(tooltipHeight)
		BG_GlobalDB.tooltipMaxHeight = tooltipHeight:GetValue()
		tooltipHeightText:SetText(BrokerGarbage.locale.maxHeightTitle .. ": " .. tooltipHeight:GetValue())
	end)
	low:Hide(); high:Hide()
end
local defaultTab = BrokerGarbage:RegisterPlugin(BrokerGarbage.locale.BasicOptionsTitle, Options_BasicOptions)

local function Options_Statistics(pluginID)
	local panel, tab = BrokerGarbage:CreateOptionsTab(pluginID)

	local function ResetStatistics(self)
		if not self or not self.stat then return end
		if self.isGlobal then
			variable = BG_GlobalDB[self.stat]
		else
			variable = BG_LocalDB[self.stat]
		end

		if variable then
			variable = 0
		end
	end

	local function AddStatistic(stat, label, value, tooltip, ...)
		if not (label and value) then return end
		local textLeft = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
		textLeft:SetWidth(150)
		textLeft:SetJustifyH("RIGHT")
		textLeft:SetText(label)

		local textRight = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
		textRight:SetPoint("LEFT", textLeft, "RIGHT", 4, 0)
		textRight:SetWidth(120)
		textRight:SetJustifyH("LEFT")
		textRight:SetText(value)

		if tooltip then
			local action = CreateFrame("Button", nil, panel)
			action:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-Waiting")
			action:SetPoint("LEFT", textRight, "RIGHT",4, 0)
			action:SetWidth(16); action:SetHeight(16)
			action.tiptext = tooltip

			action:SetScript("OnEnter", ShowTooltip)
			action:SetScript("OnLeave", HideTooltip)

			if stat then
				action.isGlobal = string.match(stat, "^_.*") and true or nil
				action.stat = string.match(stat, "^_?(.*)")
				if stat == "collectgarbage" then
					action:SetScript("OnClick", function() collectgarbage("collect"); UpdateOptionsPanel() end)
				else
					action:SetNormalTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
					action:SetScript("OnClick", ResetStatistics)
				end
			else

			end
		end
		if select('#',...) > 0 then	textLeft:SetPoint(...) end

		return textLeft, textRight
	end

	UpdateAddOnMemoryUsage()
	local memoryUsage, memoryUsageText = AddStatistic("collectgarbage", BrokerGarbage.locale.MemoryUsageTitle, math.floor(GetAddOnMemoryUsage("Broker_Garbage")), BrokerGarbage.locale.CollectMemoryUsageTooltip, "TOPRIGHT", panel, "TOP", -2, -40)

	local auctionAddon, auctionAddonText = AddStatistic(nil, BrokerGarbage.locale.AuctionAddon, BrokerGarbage.auctionAddon, BrokerGarbage.locale.AuctionAddonTooltip, "TOPLEFT", memoryUsage, "BOTTOMLEFT", 0, -6)

	local globalStatistics = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	globalStatistics:SetPoint("TOPLEFT", auctionAddon, "BOTTOMLEFT", 0, -12)
	globalStatistics:SetPoint("RIGHT", panel, -32, 0)
	globalStatistics:SetNonSpaceWrap(true)
	globalStatistics:SetJustifyH("LEFT")
	globalStatistics:SetJustifyV("TOP")
	globalStatistics:SetText(BrokerGarbage.locale.GlobalStatisticsHeading)

	local globalEarned, globalEarnedText = AddStatistic("_moneyEarned", BrokerGarbage.locale.GlobalMoneyEarnedTitle, BrokerGarbage:FormatMoney(BG_GlobalDB.moneyEarned), BrokerGarbage.locale.ResetStatistic, "TOPLEFT", globalStatistics, "BOTTOMLEFT", 0, -15)

	local itemsSold, itemsSoldText = AddStatistic("_itemsSold", BrokerGarbage.locale.GlobalItemsSoldTitle, BG_GlobalDB.itemsSold, BrokerGarbage.locale.ResetStatistic, "TOPLEFT", globalEarned, "BOTTOMLEFT", 0, -6)

	local averageSellValue, averageSellValueText = AddStatistic(nil, BrokerGarbage.locale.AverageSellValueTitle, BrokerGarbage:FormatMoney(math.floor(BG_GlobalDB.moneyEarned / (BG_GlobalDB.itemsSold ~= 0 and BG_GlobalDB.itemsSold or 1))), BrokerGarbage.locale.AverageSellValueTooltip, "TOPLEFT", itemsSold, "BOTTOMLEFT", 0, -6)

	local globalLost, globalLostText = AddStatistic("_moneyLostByDeleting", BrokerGarbage.locale.GlobalMoneyLostTitle, BrokerGarbage:FormatMoney(BG_GlobalDB.moneyLostByDeleting), BrokerGarbage.locale.ResetStatistic, "TOPLEFT", averageSellValue, "BOTTOMLEFT", 0, -15)

	local itemsDropped, itemsDroppedText = AddStatistic("_itemsDropped", BrokerGarbage.locale.ItemsDroppedTitle, BG_GlobalDB.itemsDropped, BrokerGarbage.locale.ResetStatistic, "TOPLEFT", globalLost, "BOTTOMLEFT", 0, -6)

	local averageValueLost, averageValueLostText = AddStatistic(nil, BrokerGarbage.locale.AverageDropValueTitle, BrokerGarbage:FormatMoney(math.floor(BG_GlobalDB.moneyLostByDeleting / (BG_GlobalDB.itemsDropped ~= 0 and BG_GlobalDB.itemsDropped or 1))), BrokerGarbage.locale.AverageDropValueTooltip, "TOPLEFT", itemsDropped, "BOTTOMLEFT", 0, -6)

	local localStatistics = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	localStatistics:SetPoint("TOPLEFT", averageValueLost, "BOTTOMLEFT", 0, -12)
	localStatistics:SetPoint("RIGHT", panel, -32, 0)
	localStatistics:SetNonSpaceWrap(true)
	localStatistics:SetJustifyH("LEFT")
	localStatistics:SetJustifyV("TOP")
	localStatistics:SetText(format(BrokerGarbage.locale.LocalStatisticsHeading, BrokerGarbage:Colorize(RAID_CLASS_COLORS[BrokerGarbage.playerClass]) .. UnitName("player") .. "|r"))

	local localEarned, localEarnedText = AddStatistic("moneyEarned", BrokerGarbage.locale.StatisticsLocalAmountEarned, BrokerGarbage:FormatMoney(BG_LocalDB.moneyEarned), BrokerGarbage.locale.ResetStatistic, "TOPLEFT", localStatistics, "BOTTOMLEFT", 0, -15)

	local localLost, localLostText = AddStatistic("moneyLostByDeleting", BrokerGarbage.locale.StatisticsLocalAmountLost, BrokerGarbage:FormatMoney(BG_LocalDB.moneyLostByDeleting), BrokerGarbage.locale.ResetStatistic, "TOPLEFT", localEarned, "BOTTOMLEFT", 0, -6)

	local resetAll = LibStub("tekKonfig-Button").new(panel, "TOPLEFT", localLostText, "BOTTOMLEFT", 0, -24)
	resetAll:SetText(BrokerGarbage.locale.ResetAllText)
	resetAll.tiptext = BrokerGarbage.locale.ResetAllTooltip
	resetAll:SetWidth(150)
	resetAll:SetScript("OnClick", function()
		BrokerGarbage:ResetAll( IsShiftKeyDown() )
		UpdateStats()
	end)

	function panel:Update()
		UpdateAddOnMemoryUsage()
		memoryUsageText:SetText(math.floor(GetAddOnMemoryUsage("Broker_Garbage")))

		globalEarnedText:SetText(BrokerGarbage:FormatMoney(BG_GlobalDB.moneyEarned))
		itemsSoldText:SetText(BG_GlobalDB.itemsSold)
		globalLostText:SetText(BrokerGarbage:FormatMoney(BG_GlobalDB.moneyLostByDeleting))
		itemsDroppedText:SetText(BG_GlobalDB.itemsDropped)

		averageSellValueText:SetText(BrokerGarbage:FormatMoney(math.floor(BG_GlobalDB.moneyEarned / (BG_GlobalDB.itemsSold ~= 0 and BG_GlobalDB.itemsSold or 1))))
		averageValueLostText:SetText(BrokerGarbage:FormatMoney(math.floor(BG_GlobalDB.moneyLostByDeleting / (BG_GlobalDB.itemsDropped ~= 0 and BG_GlobalDB.itemsDropped or 1))))

		localEarnedText:SetText(BrokerGarbage:FormatMoney(BG_LocalDB.moneyEarned))
		localLostText:SetText(BrokerGarbage:FormatMoney(BG_LocalDB.moneyLostByDeleting))
	end
end
local _ = BrokerGarbage:RegisterPlugin(BrokerGarbage.locale.StatisticsHeading, Options_Statistics)

function BrokerGarbage.CreateOptionsPanel(frame)
	local title, subtitle = LibStub("tekKonfig-Heading").new(frame, "Broker_Garbage", BrokerGarbage.locale.BasicOptionsText)

	local group = LibStub("tekKonfig-Group").new(frame, nil, "TOP", subtitle, "BOTTOM", 0, -24)
	group:SetPoint("LEFT")
	group:SetPoint("BOTTOMRIGHT")
	group:SetBackdropColor(0.1, 0.1, 0.1, 0.3)
	frame.group = group

	ChangeView(defaultTab)
	frame:SetScript("OnShow", UpdateOptionsPanel)
end

-- creates child options frame for setting up one's lists
local function ShowListOptions(frame)
=======
	local rescan = LibStub("tekKonfig-Button").new(BrokerGarbage.basicOptions, "TOP", editbox2, "BOTTOM", 0, -4)
	rescan:SetText(BrokerGarbage.locale.rescanInventory)
	rescan.tiptext = BrokerGarbage.locale.rescanInventoryText
	rescan:SetWidth(150)
	rescan:SetScript("OnClick", function()
		BrokerGarbage:ScanInventory()
	end)

	BrokerGarbage.basicOptions:SetScript("OnShow", nil)
end

local function ShowListOptions(frame)
	-- ----------------------------------
	-- List Options
	-- ----------------------------------
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
	local title = LibStub("tekKonfig-Heading").new(frame, "Broker_Garbage - " .. BrokerGarbage.locale.LOTitle)

	local explanation = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	explanation:SetHeight(70)
	explanation:SetPoint("TOPLEFT", title, "TOPLEFT", 0, -20)
	explanation:SetPoint("RIGHT", frame, -4, 0)
	explanation:SetNonSpaceWrap(true)
	explanation:SetJustifyH("LEFT")
	explanation:SetJustifyV("TOP")
	explanation:SetText(BrokerGarbage.locale.LOSubTitle)

	local default = LibStub("tekKonfig-Button").new(frame, "TOPLEFT", explanation, "BOTTOMLEFT", 0, -4)
	default:SetText(BrokerGarbage.locale.defaultListsText)
	default.tiptext = BrokerGarbage.locale.defaultListsTooltip
	default:SetWidth(150)
	default:RegisterForClicks("RightButtonUp", "LeftButtonUp")
	default:SetScript("OnClick", function(self, button)
<<<<<<< HEAD
		BrokerGarbage:CreateDefaultLists(IsShiftKeyDown())
=======
		BrokerGarbage:CreateDefaultLists(button == "RightButton")
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
	end)

	local autoSellIncludeItems = LibStub("tekKonfig-Checkbox").new(frame, nil, BrokerGarbage.locale.LOIncludeAutoSellText, "LEFT", default, "RIGHT", 10, 0)
	autoSellIncludeItems.tiptext = BrokerGarbage.locale.LOIncludeAutoSellTooltip .. BrokerGarbage.locale.GlobalSetting
	autoSellIncludeItems:SetChecked(BG_GlobalDB.autoSellIncludeItems)
	local checksound = autoSellIncludeItems:GetScript("OnClick")
	autoSellIncludeItems:SetScript("OnClick", function(autoSellIncludeItems)
		checksound(autoSellIncludeItems)
		BG_GlobalDB.autoSellIncludeItems = not BG_GlobalDB.autoSellIncludeItems
		BrokerGarbage.itemsCache = {}
		BrokerGarbage:ScanInventory()
	end)

<<<<<<< HEAD
=======
	local topTab = LibStub("tekKonfig-TopTab")
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
	local panel = LibStub("tekKonfig-Group").new(frame, nil, "TOP", default, "BOTTOM", 0, -24)
	panel:SetPoint("LEFT", 8 + 3, 0)
	panel:SetPoint("BOTTOMRIGHT", -8 -4, 34)

	local include = topTab.new(frame, BrokerGarbage.locale.LOTabTitleInclude, "BOTTOMLEFT", panel, "TOPLEFT", 0, -4)
	frame.current = "include"
	local exclude = topTab.new(frame, BrokerGarbage.locale.LOTabTitleExclude, "LEFT", include, "RIGHT", -15, 0)
	exclude:Deactivate()
	local vendorPrice = topTab.new(frame, BrokerGarbage.locale.LOTabTitleVendorPrice, "LEFT", exclude, "RIGHT", -15, 0)
	vendorPrice:Deactivate()
	local autoSell = topTab.new(frame, BrokerGarbage.locale.LOTabTitleAutoSell, "LEFT", vendorPrice, "RIGHT", -15, 0)
	autoSell:Deactivate()
	local help = topTab.new(frame, "?", "LEFT", autoSell, "RIGHT", -15, 0)
	help:Deactivate()

<<<<<<< HEAD
	local scrollFrame = CreateFrame("ScrollFrame", frame:GetName().."_Scroll", panel, "UIPanelScrollFrameTemplate")
	scrollFrame:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, -4)
	scrollFrame:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", -26, 3)
	local scrollContent = CreateFrame("Frame", scrollFrame:GetName().."Frame", scrollFrame)
=======
	local scrollFrame = CreateFrame("ScrollFrame", frame:GetName().."ScrollFrame", panel, "UIPanelScrollFrameTemplate")
	scrollFrame:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, -4)
	scrollFrame:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", -26, 3)
	local scrollContent = CreateFrame("Frame", scrollFrame:GetName().."Content", scrollFrame)
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
	scrollFrame:SetScrollChild(scrollContent)
	scrollContent:SetHeight(300); scrollContent:SetWidth(400)	-- will be replaced when used
	scrollContent:SetAllPoints()

	-- action buttons
	local plus = CreateFrame("Button", "BrokerGarbage_AddButton", frame)
	plus:SetPoint("TOPLEFT", panel, "BOTTOMLEFT", 4, -2)
	plus:SetWidth(25); plus:SetHeight(25)
	plus:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
	plus:SetNormalTexture("Interface\\Icons\\Spell_chargepositive")
	plus.tiptext = BrokerGarbage.locale.LOPlus
	plus:RegisterForClicks("LeftButtonUp", "RightButtonUp")
	local minus = CreateFrame("Button", "BrokerGarbage_RemoveButton", frame)
	minus:SetPoint("LEFT", plus, "RIGHT", 4, 0)
	minus:SetWidth(25);	minus:SetHeight(25)
	minus:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
	minus:SetNormalTexture("Interface\\Icons\\Spell_chargenegative")
	minus.tiptext = BrokerGarbage.locale.LOMinus
	local demote = CreateFrame("Button", "BrokerGarbage_DemoteButton", frame)
	demote:SetPoint("LEFT", minus, "RIGHT", 14, 0)
	demote:SetWidth(25) demote:SetHeight(25)
	demote:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
	demote:SetNormalTexture("Interface\\Icons\\INV_Misc_GroupLooking")
	demote.tiptext = BrokerGarbage.locale.LODemote
	local promote = CreateFrame("Button", "BrokerGarbage_PromoteButton", frame)
	promote:SetPoint("LEFT", demote, "RIGHT", 4, 0)
	promote:SetWidth(25) promote:SetHeight(25)
	promote:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
	promote:SetNormalTexture("Interface\\Icons\\INV_Misc_GroupNeedMore")
	promote.tiptext = BrokerGarbage.locale.LOPromote
	local emptyList = CreateFrame("Button", "BrokerGarbage_EmptyListButton", frame)
	emptyList:SetPoint("LEFT", promote, "RIGHT", 14, 0)
	emptyList:SetWidth(25); emptyList:SetHeight(25)
	emptyList:SetNormalTexture("Interface\\Buttons\\UI-GroupLoot-Pass-UP")
	emptyList.tiptext = BrokerGarbage.locale.LOEmptyList

	-- editbox curtesy of Tekkub
	local searchbox = CreateFrame("EditBox", frame:GetName().."SearchBox", frame)
	searchbox:SetAutoFocus(false)
	searchbox:SetPoint("TOPRIGHT", panel, "BOTTOMRIGHT", -4, 2)
	searchbox:SetWidth(160)
	searchbox:SetHeight(32)
	searchbox:SetFontObject("GameFontHighlightSmall")
<<<<<<< HEAD
	CreateFrameBorders(searchbox)
=======

	local left = searchbox:CreateTexture(nil, "BACKGROUND")
	left:SetWidth(8) left:SetHeight(20)
	left:SetPoint("LEFT", -5, 0)
	left:SetTexture("Interface\\Common\\Common-Input-Border")
	left:SetTexCoord(0, 0.0625, 0, 0.625)
	local right = searchbox:CreateTexture(nil, "BACKGROUND")
	right:SetWidth(8) right:SetHeight(20)
	right:SetPoint("RIGHT", 0, 0)
	right:SetTexture("Interface\\Common\\Common-Input-Border")
	right:SetTexCoord(0.9375, 1, 0, 0.625)
	local center = searchbox:CreateTexture(nil, "BACKGROUND")
	center:SetHeight(20)
	center:SetPoint("RIGHT", right, "LEFT", 0, 0)
	center:SetPoint("LEFT", left, "RIGHT", 0, 0)
	center:SetTexture("Interface\\Common\\Common-Input-Border")
	center:SetTexCoord(0.0625, 0.9375, 0, 0.625)
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa

	searchbox:SetScript("OnEscapePressed", searchbox.ClearFocus)
	searchbox:SetScript("OnEnterPressed", searchbox.ClearFocus)
	searchbox:SetScript("OnEditFocusGained", function(self)
		if not self.searchString then
			self:SetText("")
			self:SetTextColor(1,1,1,1)
		end
	end)
	searchbox:SetScript("OnEditFocusLost", function(self)
		if self:GetText() == "" then
			self:SetText(BrokerGarbage.locale.search)
			self:SetTextColor(0.75, 0.75, 0.75, 1)
		end
	end)
	searchbox:SetScript("OnTextChanged", function(self)
		local t = self:GetText()
		self.searchString = t ~= "" and t ~= BrokerGarbage.locale.search and t:lower() or nil
		BrokerGarbage:UpdateSearch(self.searchString)
	end)
	searchbox:SetText(BrokerGarbage.locale.search)
	searchbox:SetTextColor(0.75, 0.75, 0.75, 1)

	-- tab changing actions
	include:SetScript("OnClick", function(self)
		self:Activate()
		exclude:Deactivate()
		vendorPrice:Deactivate()
		autoSell:Deactivate()
		help:Deactivate()
		promote:Enable(); promote:GetNormalTexture():SetDesaturated(false)
		demote:Enable(); demote:GetNormalTexture():SetDesaturated(false)
		frame.current = "include"
		scrollFrame:SetVerticalScroll(0)
		BrokerGarbage:ListOptionsUpdate()
	end)
	exclude:SetScript("OnClick", function(self)
		self:Activate()
		include:Deactivate()
		vendorPrice:Deactivate()
		autoSell:Deactivate()
		help:Deactivate()
		promote:Enable(); promote:GetNormalTexture():SetDesaturated(false)
		demote:Enable(); demote:GetNormalTexture():SetDesaturated(false)
		frame.current = "exclude"
		scrollFrame:SetVerticalScroll(0)
		BrokerGarbage:ListOptionsUpdate()
	end)
	vendorPrice:SetScript("OnClick", function(self)
		self:Activate()
		include:Deactivate()
		exclude:Deactivate()
		autoSell:Deactivate()
		help:Deactivate()
		promote:Disable(); promote:GetNormalTexture():SetDesaturated(true)
		demote:Disable(); demote:GetNormalTexture():SetDesaturated(true)
		frame.current = "forceVendorPrice"
		scrollFrame:SetVerticalScroll(0)
		BrokerGarbage:ListOptionsUpdate()
	end)
	autoSell:SetScript("OnClick", function(self)
		self:Activate()
		include:Deactivate()
		exclude:Deactivate()
		vendorPrice:Deactivate()
		help:Deactivate()
		promote:Enable(); promote:GetNormalTexture():SetDesaturated(false)
		demote:Enable(); demote:GetNormalTexture():SetDesaturated(false)
		frame.current = "autoSellList"
		scrollFrame:SetVerticalScroll(0)
		BrokerGarbage:ListOptionsUpdate()
	end)
	help:SetScript("OnClick", function(self)
		self:Activate()
		include:Deactivate()
		exclude:Deactivate()
		autoSell:Deactivate()
		vendorPrice:Deactivate()
		promote:Enable(); promote:GetNormalTexture():SetDesaturated(false)
		demote:Enable(); demote:GetNormalTexture():SetDesaturated(false)
		frame.current = nil
		scrollFrame:SetVerticalScroll(0)
<<<<<<< HEAD
		BrokerGarbage:ListOptionsUpdate()
=======
		BrokerGarbage:ShowHelp()
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
	end)

	-- function to set the drop treshold (limit) via the mousewheel
	local function OnMouseWheel(self, dir)
		if type(self.itemID) ~= "number" then return end
		BrokerGarbage.itemsCache[self.itemID] = nil		-- clear item from cache

		local text, limit = self.limit:GetText()
		if self.isGlobal then
			list = BG_GlobalDB[frame.current]
		else
			list = BG_LocalDB[frame.current]
		end

<<<<<<< HEAD
		local change = IsShiftKeyDown() and 10 or 1
		if dir == 1 then	-- up
			if list[self.itemID] == true then
				list[self.itemID] = change
			else
				list[self.itemID] = list[self.itemID] + change
			end
			text = list[self.itemID]
		else				-- down
			if list[self.itemID] == true then	-- no change
				text = ""
			else
				list[self.itemID] = list[self.itemID] - change
				text = list[self.itemID]
			end

			if type(list[self.itemID]) == "number" and list[self.itemID] <= 0 then
				list[self.itemID] = true
				text = ""
=======
		if dir == 1 then	-- up
			if list[self.itemID] == true then
				list[self.itemID] = 1
			else
				list[self.itemID] = list[self.itemID] + 1
			end
			text = list[self.itemID]
		else				-- down
			if list[self.itemID] == true then
				text = ""
			elseif list[self.itemID] == 1 then
				list[self.itemID] = true
				text = ""
			else
				list[self.itemID] = list[self.itemID] - 1
				text = list[self.itemID]
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
			end
		end
		self.limit:SetText(text)
	end

	-- function that updates & shows items from various lists
	local numCols
	function BrokerGarbage:ListOptionsUpdate()
<<<<<<< HEAD
		scrollContent:SetWidth(scrollFrame:GetWidth())	-- update scrollframe content to full width
		if frame.current == nil then
			local index = 1
			while _G["BG_ListOptions_ScrollFrame_Item"..index] do
				_G["BG_ListOptions_ScrollFrame_Item"..index]:Hide()
				index = index + 1
			end
			BrokerGarbage:ShowHelp()
			return
		elseif _G["BG_HelpFrame"] then
			_G["BG_HelpFrame"]:Hide()
		end

=======
		-- update scrollframe content to full width
		scrollContent:SetWidth(scrollFrame:GetWidth())
		if frame.current == nil then
			BrokerGarbage:ShowHelp()
		elseif _G["BrokerGarbageHelpFrame"] then
			_G["BrokerGarbageHelpFrame"]:Hide()
		end
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
		local globalList = BG_GlobalDB[frame.current]
		local localList = BG_LocalDB[frame.current] or {}
		local dataList = BrokerGarbage:JoinTables(globalList, localList)

		-- make this table sortable
		data = {}
		for key, value in pairs(dataList) do
			table.insert(data, key)
		end
		table.sort(data, function(a,b)
			if type(a) == "string" and type(b) == "string" then
				return a < b
			elseif type(a) == "number" and type(b) == "number" then
				return (GetItemInfo(a) or "z") < (GetItemInfo(b) or "z")
			else
				return type(a) == "string"
			end
		end)

<<<<<<< HEAD
		for index, itemID in ipairs(data) do
			local button = _G[scrollContent:GetName().."_Item"..index]
			if not button then	-- create another button
				button = CreateFrame("CheckButton", scrollContent:GetName().."_Item"..index, scrollContent)
				button:SetWidth(36)
				button:SetHeight(36)

				button.limit = button:CreateFontString(nil, "ARTWORK", "NumberFontNormal")
				button.limit:SetPoint("BOTTOMLEFT", button, "BOTTOMLEFT", 2, 2)
				button.limit:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -2, 2)
				button.limit:SetHeight(20)
				button.limit:SetJustifyH("RIGHT")
				button.limit:SetJustifyV("BOTTOM")
				button.limit:SetText("")

				button.global = button:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
				button.global:SetPoint("TOPLEFT", button, "TOPLEFT", 2, -2)
				button.global:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -3, 1)
				button.global:SetJustifyH("LEFT")
				button.global:SetJustifyV("TOP")
				button.global:SetText("")

=======
		if not BrokerGarbage.listButtons then BrokerGarbage.listButtons = {} end
		for index, itemID in ipairs(data) do
			if BrokerGarbage.listButtons[index] then
				-- use available button
				local button = BrokerGarbage.listButtons[index]
				local itemLink, texture
				if type(itemID) ~= "number" then	-- this is an item category
					itemLink = nil
					button.tiptext = itemID			-- category description string
					button.itemID = nil
					texture = "Interface\\Icons\\Trade_engineering"
				else	-- this is an explicit item
					_, itemLink, _, _, _, _, _, _, _, texture, _ = GetItemInfo(itemID)
					button.itemID = itemID
					button.tiptext = nil
				end

				if texture then	-- everything's fine
					button.itemLink = itemLink
					button:SetNormalTexture(texture)

					if globalList[itemID] then
						button.global:SetText("G")
						button.isGlobal = true
					else
						button.global:SetText("")
						button.isGlobal = false
					end
					if button.isGlobal and globalList[itemID] ~= true then
						button.limit:SetText(globalList[itemID])
					elseif localList[itemID] ~= true then
						button.limit:SetText(localList[itemID])
					else
						button.limit:SetText("")
					end

					if not itemLink and not BrokerGarbage.PT then
						button:SetAlpha(0.2)
						button.tiptext = button.tiptext .. "\n|cffff0000"..BrokerGarbage.locale.LPTNotLoaded
					end
				else	-- an item the server has not seen
					button.tiptext = "ID: "..itemID
					button:SetNormalTexture("Interface\\Icons\\Inv_misc_questionmark")
				end
				if BrokerGarbage.listOptions.current == "include" then
					button:EnableMouseWheel(true)
					button:SetScript("OnMouseWheel", OnMouseWheel)
				else
					button:EnableMouseWheel(false)
				end
				button:SetChecked(false)
				button:Show()
			else
				-- create another button
				local button = CreateFrame("CheckButton", scrollContent:GetName().."Item"..index, scrollContent)
				button:Hide()
				button:SetWidth(36)
				button:SetHeight(36)

				local limit = button:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
				limit:SetPoint("BOTTOMLEFT", button, "BOTTOMLEFT", 2, 1)
				limit:SetPoint("BOTTOMLEFT", button, "BOTTOMLEFT", 2, 1)
				limit:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -3, 1)
				limit:SetHeight(20)
				limit:SetJustifyH("RIGHT")
				limit:SetJustifyV("BOTTOM")
				limit:SetText("")
				button.limit = limit

				local global = button:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
				global:SetPoint("TOPLEFT", button, "TOPLEFT", 2, -2)
				global:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -3, 1)
				global:SetJustifyH("LEFT")
				global:SetJustifyV("TOP")
				global:SetText("")
				button.global = global

				button:SetNormalTexture("Interface\\Icons\\Inv_misc_questionmark")
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
				button:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
				button:SetCheckedTexture("Interface\\Buttons\\UI-Button-Outline")
				button:SetChecked(false)
				local tex = button:GetCheckedTexture()
				tex:ClearAllPoints()
				tex:SetPoint("CENTER")
				tex:SetWidth(36/37*66) tex:SetHeight(36/37*66)

				button:SetScript("OnClick", function(self)
					local check = self:GetChecked()
<<<<<<< HEAD
					if IsModifiedClick() then	-- this handles chat linking as well as dress-up
=======
					BrokerGarbage:Debug("OnClick", check)

					if IsModifiedClick() then
						-- this handles chat linking as well as dress-up
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
						local linkText = type(self.itemID) == "string" and self.itemID or BrokerGarbage.locale.AuctionAddonUnknown
						HandleModifiedItemClick(self.itemLink or linkText)
						self:SetChecked(not check)
					elseif not IsModifierKeyDown() then
						self:SetChecked(check)
					else
						self:SetChecked(not check)
					end
				end)
				button:SetScript("OnEnter", ShowTooltip)
				button:SetScript("OnLeave", HideTooltip)

<<<<<<< HEAD
				-- TODO: make even more generic
				if not numCols and panel:GetWidth() - (index+1)*(button:GetWidth() + 2) < 2 then
=======
				if not numCols and panel:GetWidth() - (index+1)*button:GetWidth() < 2 then
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
					-- we found the width limit, set the column count
					numCols = index - 1
				end
				if index == 1 then		-- place first icon
					button:SetPoint("TOPLEFT", scrollContent, "TOPLEFT", 6, -6)
				elseif numCols and mod(index, numCols) == 1 then	-- new row
<<<<<<< HEAD
					button:SetPoint("TOPLEFT", _G[scrollContent:GetName().."_Item" .. index - numCols], "BOTTOMLEFT", 0, -6)
				else					-- new button next to the old one
					button:SetPoint("LEFT", _G[scrollContent:GetName().."_Item" .. index - 1], "RIGHT", 4, 0)
				end
			end

			-- update this button with data
			local itemLink, texture
			if type(itemID) ~= "number" then	-- this is an item category
				itemLink = nil
				button.tiptext = itemID			-- category description string
				button.itemID = nil
				texture = "Interface\\Icons\\Trade_engineering"
			else	-- this is an explicit item
				_, itemLink, _, _, _, _, _, _, _, texture, _ = GetItemInfo(itemID)
				button.itemID = itemID
				button.tiptext = nil
			end

			if texture then	-- everything's fine
				button.itemLink = itemLink

				if globalList[itemID] then
					button.global:SetText("G")
					button.isGlobal = true
				else
					button.global:SetText("")
					button.isGlobal = false
				end
				if button.isGlobal and globalList[itemID] ~= true then
					button.limit:SetText(globalList[itemID])
				elseif localList[itemID] ~= true then
					button.limit:SetText(localList[itemID])
				else
					button.limit:SetText("")
				end

				if not itemLink and not BrokerGarbage.PT then
					button:SetAlpha(0.2)
					button.tiptext = button.tiptext .. "\n|cffff0000"..BrokerGarbage.locale.LPTNotLoaded
				end
			else	-- an item the server has not seen
				button.tiptext = "ID: "..itemID
			end
			button:SetNormalTexture(texture or "Interface\\Icons\\Inv_misc_questionmark")

			if BrokerGarbage.listOptions.current == "include" then
				button:EnableMouseWheel(true)
				button:SetScript("OnMouseWheel", OnMouseWheel)
			else
				button:EnableMouseWheel(false)
			end
			button:SetChecked(false)
			button:Show()
		end
		-- hide unnessessary buttons
		local index = #data + 1
		while _G[scrollContent:GetName().."_Item"..index] do
			_G[scrollContent:GetName().."_Item"..index]:Hide()
=======
					button:SetPoint("TOPLEFT", BrokerGarbage.listButtons[index-numCols], "BOTTOMLEFT", 0, -6)
				else					-- new button next to the old one
					button:SetPoint("LEFT", BrokerGarbage.listButtons[index-1], "RIGHT", 4, 0)
				end

				BrokerGarbage.listButtons[index] = button
				BrokerGarbage:ListOptionsUpdate(listName)	-- update, so we get item data & texture
			end
		end
		-- hide unnessessary buttons
		local index = #data + 1
		while BrokerGarbage.listButtons[index] do
			BrokerGarbage.listButtons[index]:Hide()
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
			index = index + 1
		end
	end

	-- shows some help strings for setting up the lists
	function BrokerGarbage:ShowHelp()
<<<<<<< HEAD
		if not _G["BG_HelpFrame"] then
			local helpFrame = CreateFrame("Frame", "BG_HelpFrame", scrollContent)
=======
		for i, button in ipairs(BrokerGarbage.listButtons) do
			button:Hide()
		end
		if not _G["BrokerGarbageHelpFrame"] then
			local helpFrame = CreateFrame("Frame", "BrokerGarbageHelpFrame", scrollContent)
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
			helpFrame:SetAllPoints()

			local bestUse = helpFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
			bestUse:SetHeight(190)
			bestUse:SetPoint("TOPLEFT", helpFrame, "TOPLEFT", 8, -4)
			bestUse:SetPoint("RIGHT", helpFrame, -4, 0)
			bestUse:SetNonSpaceWrap(true)
			bestUse:SetJustifyH("LEFT"); bestUse:SetJustifyV("TOP")
			bestUse:SetText(BrokerGarbage.locale.listsBestUse)

			local iconButtons = helpFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
			iconButtons:SetHeight(124)
			iconButtons:SetPoint("TOPLEFT", bestUse, "BOTTOMLEFT", 0, -10)
			iconButtons:SetPoint("RIGHT", helpFrame, -4, 0)
			iconButtons:SetNonSpaceWrap(true)
			iconButtons:SetJustifyH("LEFT"); iconButtons:SetJustifyV("TOP")
			iconButtons:SetText(BrokerGarbage.locale.iconButtonsUse)

			local actionButtons = helpFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
			actionButtons:SetHeight(180)
			actionButtons:SetPoint("TOPLEFT", iconButtons, "BOTTOMLEFT", 0, -10)
			actionButtons:SetPoint("RIGHT", helpFrame, -4, 0)
			actionButtons:SetNonSpaceWrap(true)
			actionButtons:SetJustifyH("LEFT"); actionButtons:SetJustifyV("TOP")
			actionButtons:SetText(BrokerGarbage.locale.actionButtonsUse)
		else
<<<<<<< HEAD
			_G["BG_HelpFrame"]:Show()
=======
			_G["BrokerGarbageHelpFrame"]:Show()
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
		end
	end

	-- when a search string is passed, suitable items will be shown while the rest is grayed out
	function BrokerGarbage:UpdateSearch(searchString)
<<<<<<< HEAD
		local index = 1
		local button = _G[scrollContent:GetName().."_Item"..index]
		while button and button:IsVisible() do
			local name = button.itemID and GetItemInfo(button.itemID) or button.tiptext
			name = (button.itemID or "") .. " " .. (name or "")
			name = name:lower()

			if not searchString or string.match(name, searchString) then
				button:SetAlpha(1)
			else
				button:SetAlpha(0.3)
			end
			index = index + 1
			button = _G[scrollContent:GetName().."_Item"..index]
=======
		for i, button in ipairs(BrokerGarbage.listButtons) do
			if button:IsVisible() then
				local itemName = button.itemID and GetItemInfo(button.itemID) or button.tiptext
				local name = (button.itemID or "") .. " " .. (itemName or "")
				name = name:lower()

				if not searchString or string.match(name, searchString) then
					button:SetAlpha(1)
				else
					button:SetAlpha(0.3)
				end
			end
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
		end
	end

	local function AddItem(item)
		BrokerGarbage:Debug("Add Item", item)
		local cursorType, itemID, link = GetCursorInfo()
		if not item and not (cursorType and itemID and link) then
			return
		end

		-- find the item we want to add
		if itemID then	-- real items
			itemID = itemID
			BrokerGarbage.itemsCache[itemID] = nil
		else			-- category strings
			itemID = item
			BrokerGarbage.itemsCache = {}
		end

		-- create "link" for output
		if type(itemID) == "number" then
			link = select(2, GetItemInfo(itemID))
		else
			link = itemID
		end

		if BG_LocalDB[frame.current] and BG_LocalDB[frame.current][itemID] == nil then
			BG_LocalDB[frame.current][itemID] = true
			BrokerGarbage:Print(format(BrokerGarbage.locale["addedTo_" .. frame.current], link))
			BrokerGarbage:ListOptionsUpdate()
			ClearCursor()
		elseif BG_LocalDB[frame.current] == nil and
			BG_GlobalDB[frame.current] and BG_GlobalDB[frame.current][itemID] == nil then
			BG_GlobalDB[frame.current][itemID] = true
			BrokerGarbage:Print(format(BrokerGarbage.locale["addedTo_" .. frame.current], link))
			BrokerGarbage:ListOptionsUpdate()
			ClearCursor()
		else
			BrokerGarbage:Print(string.format(BrokerGarbage.locale.itemAlreadyOnList, link))
		end

		BrokerGarbage:ScanInventory()
		BrokerGarbage:UpdateRepairButton()
	end

<<<<<<< HEAD
	if not _G["BG_LPTMenuFrame"] then
		--initialize dropdown menu for adding setstrings
		BrokerGarbage.menuFrame = CreateFrame("Frame", "BG_LPTMenuFrame", UIParent, "UIDropDownMenuTemplate")

		UIDropDownMenu_Initialize(BrokerGarbage.menuFrame, function(self, level)
			local dataTable = BrokerGarbage.PTSets or {}
			if UIDROPDOWNMENU_MENU_VALUE and string.find(UIDROPDOWNMENU_MENU_VALUE, ".") then
				local parts = { strsplit(".", UIDROPDOWNMENU_MENU_VALUE) } or {}
				for k = 1, #parts do
					dataTable = dataTable[ parts[k] ]
				end
			elseif UIDROPDOWNMENU_MENU_VALUE then
				dataTable = dataTable[ UIDROPDOWNMENU_MENU_VALUE ] or {}
			end

			-- display a heading
			if (level == 1) then
				local info = UIDropDownMenu_CreateInfo()
				info.isTitle = true
				info.notCheckable = true
				info.text = BrokerGarbage.locale.categoriesHeading
				UIDropDownMenu_AddButton(info, level)

				-- and some warning text, in case LPT is not available
				if not BrokerGarbage.PT then
					local info = UIDropDownMenu_CreateInfo()
					info.isTitle = true
					info.notCheckable = true
					info.text = BrokerGarbage.locale.LPTNotLoaded
					UIDropDownMenu_AddButton(info, level)
				end
			end

			for key, value in pairs(dataTable) do
				local info = UIDropDownMenu_CreateInfo()
				local prefix = ""
				if UIDROPDOWNMENU_MENU_VALUE then
					prefix = UIDROPDOWNMENU_MENU_VALUE .. "."
				end

				info.text = key
				info.value = prefix .. key
				info.hasArrow = type(value) == "table" and true or false
				info.func = function(...)
					AddItem(value)
					BrokerGarbage:ListOptionsUpdate()
				end

				UIDropDownMenu_AddButton(info, level);
			end
		end, "MENU")
=======
	if not _G["BrokerGarbagePTMenuFrame"] then
		--initialize dropdown menu for adding setstrings
		BrokerGarbage.menuFrame = CreateFrame("Frame", "BrokerGarbagePTMenuFrame", UIParent, "UIDropDownMenuTemplate")

		-- menu create function
		function DropDown_Initialize(self,level)
			level = level or 1
			if (level == 1) then
				local info = UIDropDownMenu_CreateInfo()
				info.hasArrow = false -- no submenu
				info.notCheckable = true
				info.text = BrokerGarbage.locale.categoriesHeading
				info.isTitle = true
				UIDropDownMenu_AddButton(info, level)

				if not BrokerGarbage.PT then
					local info = UIDropDownMenu_CreateInfo()
					info.hasArrow = false
					info.notCheckable = true
					info.text = BrokerGarbage.locale.LPTNotLoaded
					info.isTitle = true
					UIDropDownMenu_AddButton(info, level)
				end
				for key, subarray in pairs(BrokerGarbage.PTSets) do
					-- submenus
					local info = UIDropDownMenu_CreateInfo()
					info.hasArrow = true
					info.notCheckable = true
					info.text = key
					info.value = {
						[1] = key
					}
					info.func = function(...)
						AddItem(key)
						BrokerGarbage:ListOptionsUpdate()
					end
					UIDropDownMenu_AddButton(info, level)
				end
			end

			if (level > 1) then
				-- getting values of first menu
				local parentValue = UIDROPDOWNMENU_MENU_VALUE
				local PTSets = BrokerGarbage.PTSets
				for i = 1, level - 1 do
					PTSets = PTSets[ parentValue[i] ]
				end

				for key, value in pairs(PTSets) do
					local newValue = {}
					for i = 1, level - 1 do
						newValue[i] = parentValue[i]
					end
					newValue[level] = key

					local info = UIDropDownMenu_CreateInfo();
					if type(value) == "table" then
						-- submenu
						local valueString = newValue[1]
						for i = 2, level do
							valueString = valueString.."."..newValue[i]
						end

						info.hasArrow = true;
						info.notCheckable = true;
						info.text = key
						info.value = newValue
						info.func = function(...)
							AddItem(valueString)
							BrokerGarbage:ListOptionsUpdate()
						end
					else
						-- end node
						info.hasArrow = false; -- no submenues this time
						info.notCheckable = true;
						info.text = key
						info.func = function(...)
							AddItem(value)
							BrokerGarbage:ListOptionsUpdate()
						end
					end
					UIDropDownMenu_AddButton(info, level);
				end
			end
		end
		UIDropDownMenu_Initialize(BrokerGarbage.menuFrame, DropDown_Initialize, "MENU")
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
	end

	local function OnClick(self, button)
		if frame.current == nil then return end
		if button == "RightButton" then
			-- toggle LibPeriodicTable menu
			BrokerGarbage.menuFrame.clickTarget = self
			ToggleDropDownMenu(1, nil, BrokerGarbage.menuFrame, self, -20, 0)
<<<<<<< HEAD
=======
			BrokerGarbage:Debug("LPT menu opened", self, button)
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
			return
		end

		-- add action
		if self == plus then
			AddItem()
		-- remove action
		elseif self == minus then
<<<<<<< HEAD
			BrokerGarbage:Debug("Clicked on Minus: Remove items")
			local index = 1
			while _G["BG_ListOptions_ScrollFrame_Item"..index] do
				local button = _G["BG_ListOptions_ScrollFrame_Item"..index]
				if button:IsVisible() and button:GetChecked() then
					BrokerGarbage:Debug("Button visible & checked. removing")
					local item = button.itemID or button.tiptext
					if BG_LocalDB[frame.current] then
						BrokerGarbage:Debug("is local")
						BG_LocalDB[frame.current][item] = nil
					end
					if BG_GlobalDB[frame.current] then
						BrokerGarbage:Debug("is global")
=======
			for i, button in ipairs(BrokerGarbage.listButtons) do
				if button:IsVisible() and button:GetChecked() then
					local item = button.itemID or button.tiptext
					if BG_LocalDB[frame.current] then
						BG_LocalDB[frame.current][item] = nil
					end
					if BG_GlobalDB[frame.current] then
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
						BG_GlobalDB[frame.current][item] = nil
					end

					if type(item) == "number" then	-- regular item
						BrokerGarbage.itemsCache[item] = nil
					else							-- category string
						BrokerGarbage.itemsCache = {}
					end
				end
<<<<<<< HEAD
				index = index + 1
			end
		-- demote action
		elseif self == demote then
			local index = 1
			while _G["BG_ListOptions_ScrollFrame_Item"..index] do
				local button = _G["BG_ListOptions_ScrollFrame_Item"..index]
=======
			end
		-- demote action
		elseif self == demote then
			for i, button in ipairs(BrokerGarbage.listButtons) do
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
				if button:IsVisible() and button:GetChecked() then
					local item = button.itemID or button.tiptext
					if BG_GlobalDB[frame.current][item] and BG_LocalDB[frame.current] then
						BG_LocalDB[frame.current][item] = BG_GlobalDB[frame.current][item]
						BG_GlobalDB[frame.current][item] = nil
					end
				end
<<<<<<< HEAD
				index = index + 1
			end
		-- promote action
		elseif self == promote then
			local index = 1
			while _G["BG_ListOptions_ScrollFrame_Item"..index] do
				local button = _G["BG_ListOptions_ScrollFrame_Item"..index]
=======
			end
		-- promote action
		elseif self == promote then
			for i, button in ipairs(BrokerGarbage.listButtons) do
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
				if button:IsVisible() and button:GetChecked() then
					local item = button.itemID or button.tiptext
					if not BG_GlobalDB[frame.current][item] then
						BG_GlobalDB[frame.current][item] = BG_LocalDB[frame.current][item]
						BG_LocalDB[frame.current][item] = nil
					end
				end
<<<<<<< HEAD
				index = index + 1
=======
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa
			end
		-- empty action
		elseif self == emptyList then
			BrokerGarbage.itemsCache = {}
			if IsShiftKeyDown() then
				BG_GlobalDB[frame.current] = {}
			elseif BG_LocalDB[frame.current] then
				BG_LocalDB[frame.current] = {}
			end
		end

		BrokerGarbage:ScanInventory()
		BrokerGarbage:ListOptionsUpdate()
		BrokerGarbage:UpdateRepairButton()
	end

	plus:SetScript("OnClick", OnClick)
	plus:SetScript("OnEnter", ShowTooltip)
	plus:SetScript("OnLeave", HideTooltip)
	minus:SetScript("OnClick", OnClick)
	minus:SetScript("OnEnter", ShowTooltip)
	minus:SetScript("OnLeave", HideTooltip)
	demote:SetScript("OnClick", OnClick)
	demote:SetScript("OnEnter", ShowTooltip)
	demote:SetScript("OnLeave", HideTooltip)
	promote:SetScript("OnClick", OnClick)
	promote:SetScript("OnEnter", ShowTooltip)
	promote:SetScript("OnLeave", HideTooltip)
	emptyList:SetScript("OnClick", OnClick)
	emptyList:SetScript("OnEnter", ShowTooltip)
	emptyList:SetScript("OnLeave", HideTooltip)

	-- support for add-mechanism
	plus:RegisterForDrag("LeftButton")
	plus:SetScript("OnReceiveDrag", ItemDrop)
	plus:SetScript("OnMouseDown", ItemDrop)

	BrokerGarbage:ListOptionsUpdate()
	BrokerGarbage.listOptions:SetScript("OnShow", BrokerGarbage.ListOptionsUpdate)
end

<<<<<<< HEAD
BrokerGarbage.options:SetScript("OnShow", BrokerGarbage.CreateOptionsPanel)
InterfaceOptions_AddCategory(BrokerGarbage.options)

BrokerGarbage.listOptions:SetScript("OnShow", ShowListOptions)
InterfaceOptions_AddCategory(BrokerGarbage.listOptions)

LibStub("tekKonfig-AboutPanel").new("Broker_Garbage", "Broker_Garbage")
=======
local index = #BrokerGarbage.optionsModules
table.insert(BrokerGarbage.optionsModules, BrokerGarbage.options)
BrokerGarbage.optionsModules[index+1].OnShow = ShowOptions
table.insert(BrokerGarbage.optionsModules, BrokerGarbage.basicOptions)
BrokerGarbage.optionsModules[index+2].OnShow = ShowBasicOptions
table.insert(BrokerGarbage.optionsModules, BrokerGarbage.listOptions)
BrokerGarbage.optionsModules[index+3].OnShow = ShowListOptions

local firstLoad = true
function BrokerGarbage:OptionsFirstLoad()
	if not firstLoad then return end

	for i, options in ipairs(BrokerGarbage.optionsModules) do
		BrokerGarbage:Debug("Loading options: ", options.name)
		InterfaceOptions_AddCategory(options)
		options:SetScript("OnShow", options.OnShow)
	end
	LibStub("tekKonfig-AboutPanel").new("Broker_Garbage", "Broker_Garbage")

	collectgarbage()
	firstLoad = false
end

-- show me!
InterfaceOptionsFrame:HookScript("OnShow", BrokerGarbage.OptionsFirstLoad)
>>>>>>> 5718466e0636150e9aca329ad638bf22e4e21cfa

-- register slash commands
SLASH_BROKERGARBAGE1 = "/garbage"
SLASH_BROKERGARBAGE2 = "/garb"
function SlashCmdList.BROKERGARBAGE(msg, editbox)
	local command, rest = msg:match("^(%S*)%s*(.-)$")
	local command = strlower(command)
	local LootManager = IsAddOnLoaded("Broker_Garbage-LootManager")

	if command == "format" then
		if strlower(rest) ~= "reset" then
			BG_GlobalDB.LDBformat = rest
		else
			BG_GlobalDB.LDBformat = BrokerGarbage.defaultGlobalSettings.LDBformat
		end
		BrokerGarbage:ScanInventory()

	elseif command == "options" or command == "config" or command == "option" or command == "menu" then
		BrokerGarbage:OptionsFirstLoad()
		InterfaceOptionsFrame_OpenToCategory(BrokerGarbage.options)

	elseif command == "limit" or command == "glimit" or command == "globallimit" then
		local itemID, count = rest:match("^[^0-9]-([0-9]+).-([0-9]+)$")
		itemID = tonumber(itemID)
		count = tonumber(count)

		BrokerGarbage.itemsCache[itemID] = nil

		if string.find(command, "g") then
			BG_GlobalDB.include[itemID] = count
		else
			BG_LocalDB.include[itemID] = count
		end
		local itemLink = select(2,GetItemInfo(itemID)) or BrokerGarbage.locale.unknown
		BrokerGarbage:Print(format(BrokerGarbage.locale.limitSet, itemLink, count))
		BrokerGarbage:ListOptionsUpdate("include")

	elseif command == "value" or command == "minvalue" and LootManager then
		rest = tonumber(rest)
		if not rest then return end

		BrokerGarbage_LootManager:SetMinValue(rest)
		BrokerGarbage:Print(format(BrokerGarbage.locale.minValueSet, BrokerGarbage:FormatMoney(BG_LocalDB.itemMinValue)))

	else
		BrokerGarbage:Print(BrokerGarbage.locale.slashCommandHelp)
	end
end