local _, class = UnitClass('player')
if(class ~= 'ROGUE') then return end

TradeFrameUnlockButton = CreateFrame('Button', 'TradeFrameUnlockButton', TradeFrame, 'SecureActionButtonTemplate, UIPanelButtonTemplate')
TradeFrameUnlockButton:SetHeight(22)
TradeFrameUnlockButton:SetWidth(56)
TradeFrameUnlockButton:RegisterForClicks('AnyUp')
TradeFrameUnlockButton:SetAttribute('type', 'spell')
TradeFrameUnlockButton:SetAttribute('spell', GetSpellInfo(1804))
TradeFrameUnlockButton:SetPoint('BOTTOMRIGHT', TradeFrameCancelButton, 'BOTTOMRIGHT', 0, 68)
TradeFrameUnlockButton:SetText('开锁')

-- if (class == "ROGUE") then
--    TradeFrameTradeButton:SetWidth(56)
--    TradeFrameCancelButton:SetWidth(56)
--    TradeFrameTradeButton:SetPoint("BOTTOMRIGHT","TradeFrame","BOTTOMRIGHT",-141,55)
--    TradeFrameCancelButton:SetPoint("TOPLEFT","TradeFrameUnlockButton","TOPRIGHT",-3,0)
-- end

----===================================完美的分割线=====================================----

local frame = CreateFrame("Button", "oApplication", UIParent, "SecureActionButtonTemplate AutoCastShineTemplate")
local macro = "/stopcasting\n/use %s\n/use [button:2] 17; 16"
local tip = GameTooltip
local orig = tip:GetScript"OnTooltipSetItem"

for _, v in ipairs(frame.sparkles) do
	v:SetWidth(v:GetWidth() * 3)
	v:SetHeight(v:GetHeight() * 3)
end

local GetID = function(item)
	if type(item) == "number" then return item
	elseif type(item) == "string" then
		local _, _, id = string.find(item, "item:(%d+):")
		if id then return tonumber(id) end
	end
end
local S = function() return IsControlKeyDown() and not IsAltKeyDown() and not IsShiftKeyDown() end
local W = '3824 34538 40773 23122 41170 41174 20844 3829 41194 43230 43234 23529 36900 12404 20745 20747 20749 8984 8985 6811 41171 22053 22055 41191 41195 43231 43235 34861 3775 28421 7964 6949 6950 21835 10920 10921 10922 3239 23123 41172 3241 2892 41192 41196 43232 10918 7965 23528 22522 22521 31535 2863 20744 20746 20748 20750 2893 2862 34539 6530 5237 36899 3240 7307 12643 8926 8927 41169 41173 6529 22054 41193 21927 6532 43237 6533 8928 28420 18262 43233 2871 6947 '
local OnShow = function(self, ...)
	if(self and orig) then orig(self, ...) end
	local name, id = self:GetItem()
	if(name and id) then
		id = GetID(id)
		if(id and W:match(id.."%s") and S()) then
			name = GetItemInfo(id)
			frame:ClearAllPoints()
			frame:SetAttribute("macrotext", macro:format(name))
			frame:SetAllPoints(GetMouseFocus())
			AutoCastShine_AutoCastStart(frame, 0, 1, 0)
			frame:Show()
		end
	end
end
frame:SetFrameStrata"DIALOG"
frame:RegisterForClicks("LeftButtonUp", "RightButtonUp")
frame:SetScript("OnLeave", function(self) self:Hide() end)
frame:SetAttribute("*type*", "macro")
frame:SetScript("OnEvent", function(self, event)
              	self:ClearAllPoints()
		self:Hide()
		AutoCastShine_AutoCastStop(frame)
end)
frame:RegisterEvent"MODIFIER_STATE_CHANGED"
frame:RegisterEvent"PLAYER_REGEN_DISABLED"
tip:SetScript("OnTooltipSetItem", OnShow)