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)


----改名
StaticPopupDialogs.SC_NAME = { 
        text = "输入你要改的名字,不输入为恢复原名", 
        button1 = "确定并重载界面", 
        button2 = CANCEL, 
		--功能调用
        --OnAccept =  function() end, 
		OnAccept = function (self, data, data2)
		AddUIDB.Gname = self.editBox:GetText()
		ReloadUI()
		end,
        timeout = 0, 
        whileDead = 1, 
        hideOnEscape = true, 
		hasEditBox = true,
        preferredIndex = 5, 
}
SLASH_SCNAME1 = "/gn" 
SLASH_SCNAME2 = "/name" 
SLASH_SCNAME3 = "/改名" 
SlashCmdList["SCNAME"] = function() 
        StaticPopup_Show("SC_NAME") 
end


local Gname = CreateFrame("Frame")
Gname:RegisterEvent("ADDON_LOADED")
Gname:SetScript("OnEvent", function(self, event)
if AddUIDB.Gname == nil then return end
if AddUIDB.Gname == ""  then return end
local changedName = AddUIDB.Gname


local playerName = UnitName("player")
local UnitNameStore = UnitName
local function GetUnitName(unit)
	local realname = UnitNameStore(unit)
	if realname == playerName then
		return changedName
	else
		return realname
	end
end
UnitName = GetUnitName

local playercnClass, playerusClass ,playerClassid = UnitClass("player")
local UnitClassStore = UnitClass
local function GetUnitClass(unit)
	local cnclass,usclass,classid= UnitClassStore(unit)
	if usclass == nil then
		return playercnClass, playerusClass ,playerClassid
	else
		return cnclass,usclass,classid
	end
end
UnitClass = GetUnitClass

CharacterFrame:HookScript("OnShow", function(self)
	CharacterFrameTitleText:SetText(changedName)
	if C_AddOns.IsAddOnLoaded("TinyInspect") then
	PaperDollFrame.inspectFrame.title:SetText(changedName)
	end
end)

local function mynamechange()
	local _, unit = GameTooltip:GetUnit()
	if UnitIsPlayer(unit) then
		local text = GameTooltipTextLeft1:GetText()
		if UnitName(unit) == UnitName("player") then text = changedName end
		GameTooltipTextLeft1:SetText(text)
	end
end
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Unit, mynamechange)

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