local _,ns = ...
ns.tips("按alt一次买一组")
local savedMerchantItemButton_OnModifiedClick = MerchantItemButton_OnModifiedClick 
function MerchantItemButton_OnModifiedClick(self, ...) 
   if ( IsAltKeyDown() ) then 
      local itemLink = GetMerchantItemLink(self:GetID()) 
      if not itemLink then return end 
      local maxStack = select(8, C_Item.GetItemInfo(itemLink)) 
      if ( maxStack and maxStack > 1 ) then 
         BuyMerchantItem(self:GetID(), GetMerchantItemMaxStack(self:GetID())) 
      end 
   end 
   savedMerchantItemButton_OnModifiedClick(self, ...) 
end

--拍卖行保存过滤AHFilterRestoreDB
local AHDB = CreateFrame("frame")
AHDB:RegisterEvent('AUCTION_HOUSE_SHOW')
AHDB:SetScript("OnEvent", function(self, event)
	AddUIDB.AHFilterRestoreDB = AddUIDB.AHFilterRestoreDB or {}
	--设置拍卖行
	AuctionHouseFrame.SearchBar.FilterButton.filters = next(AddUIDB.AHFilterRestoreDB) and AddUIDB.AHFilterRestoreDB or
	CopyTable(AUCTION_HOUSE_DEFAULT_FILTERS)
	AuctionHouseFrame.SearchBar:UpdateClearFiltersButton()
	--设置hook
	if self.hooked then return end
	hooksecurefunc(AuctionHouseFrame.SearchBar, "OnFilterToggled", function()
		local newFilter = AuctionHouseFrame.SearchBar.FilterButton:GetFilters()
		AddUIDB.AHFilterRestoreDB = newFilter
	end)
	
	AuctionHouseFrame.SearchBar.FilterButton.ClearFiltersButton:SetScript("OnClick", function()
		AuctionHouseFrame.SearchBar.FilterButton.filters = CopyTable(AUCTION_HOUSE_DEFAULT_FILTERS)
		AuctionHouseFrame.SearchBar.FilterButton.minLevel = 0
		AuctionHouseFrame.SearchBar.FilterButton.maxLevel = 0
		AuctionHouseFrame.SearchBar.FilterButton.ClearFiltersButton:Hide()
		wipe(AddUIDB.AHFilterRestoreDB)
	end)
	
	self.hooked = true
end)


--BlizzardInterfaceCode\Interface\FrameXML\UIParent
ns.tips("让拍卖行和专业界面可以同时打开")
function CanShowRightUIPanel(frame)
	local width = frame and GetUIPanelWidth(frame) or UIParent:GetAttribute("DEFAULT_FRAME_WIDTH");
	local rightSide = UIParent:GetAttribute("RIGHT_OFFSET") + width;
	if frame == AuctionHouseFrame or frame == ProfessionsFrame then
		return true
	else
		return rightSide <= GetMaxUIPanelsWidth();
	end
end