local _,ns = ...
ns.ADDUIEVENT("PLAYER_LOGIN", function()
if AddUIDB.mh ==  true  then
--自动卖灰
local f = CreateFrame("Frame") 
f:SetScript("OnEvent", function(...) 

	local p,N,c,n=0
		for b=0,4 do
		    for s=1,C_Container.GetContainerNumSlots (b) do
			    n=C_Container.GetContainerItemLink(b,s) 
                    if n and string.find(n,"|cnIQ0") then--9d9d9d--Q0灰色123456---https://warcraft.wiki.gg/wiki/UI_escape_sequences
					    N={C_Item.GetItemInfo(n)} 
                        c=C_Item.GetItemCount(n)
						p= p+(N[11]*c)
						C_Container.UseContainerItem(b,s)
					end
			end
		end 
		--C_MerchantFrame.SellAllJunkItems()
    if p ~= 0 then
	    print("|cff44CCFF售卖垃圾: |r"..C_CurrencyInfo.GetCoinText(p))
	end
end)
f:RegisterEvent("MERCHANT_SHOW")
end

--NPC一键售卖按钮装备
StaticPopupDialogs.MerchantFrame_Sell = {
    text = "即将自动售卖\n售卖低于多少装等的装备?",  -- 提示文本
    button1 = "确认",          -- 确认按钮
    button2 = "取消",          -- 取消按钮
    timeout = 0,               -- 不自动关闭
    whileDead = true,          -- 死亡时可用
    hideOnEscape = true,       -- 按ESC关闭
    hasEditBox = true,         -- 包含输入框
	OnShow = function(self)
		self.editBox:SetScript("OnEscapePressed", function(editBox)
            self:Hide()  -- 直接关闭窗口
        end)
    end,
    OnAccept = function(self)  -- 点击确认后的回调
        local BoxLevel = tonumber(self.editBox:GetText())
		local N,c,n
		for b=0,4 do
			for s = 1,C_Container.GetContainerNumSlots(b) do
				n = C_Container.GetContainerItemLink(b,s) 
				if n then
					local level = GetDetailedItemLevelInfo(n)
					N={C_Item.GetItemInfo(n)}
					c=C_Item.GetItemCount(n)
					if BoxLevel and level and BoxLevel > level and level > 1 and (N[6] == ARMOR or N[6] == WEAPON) then
						c=C_Item.GetItemCount(n)
						C_Container.UseContainerItem(b,s)
					end
				end
			end
		end
    end,
}
local Sell = CreateFrame("Button", "AddUISell", MerchantFrame.NineSlice, "UIPanelButtonTemplate")
Sell:SetText("售卖")
Sell:SetWidth(55)
Sell:SetHeight(22)
Sell:SetPoint("TOPLEFT", 57, 0)
Sell:SetScript("OnClick", function()
	StaticPopup_Show("MerchantFrame_Sell")
end)

-- 快速拾取
if AddUIDB.sq ==  true  then
local faster = CreateFrame("Frame")
faster:RegisterEvent("LOOT_READY")
faster:SetScript("OnEvent", function(self, event, ...)
-- Time delay
local tDelay = 0
	if GetTime() - tDelay >= 0.1 then
		tDelay = GetTime()
		if GetCVarBool("autoLootDefault") ~= IsModifiedClick("AUTOLOOTTOGGLE") then
			for i = GetNumLootItems(), 1, -1 do
				LootSlot(i)
			end
			tDelay = GetTime()
		end
	end
end)
end

end)