local GlobalAddonName, LTS = ...

local ADDON_VERSION = "3.8 (20.02.2026)"

local clientLocale = GetLocale()
local isNotENClient = not clientLocale:find("^en")
local wowheadPrefixTable = {
	deDE = "de/",
	esES = "es/",
	esMX = "es/",
	frFR = "fr/",
	itIT = "it/",
	koKR = "ko/",
	ptBR = "pt/",
	ruRU = "ru/",
	zhCN = "cn/",
	zhTW = "cn/",
}
local wowheadPrefix = wowheadPrefixTable[clientLocale] or ""

local InputFrame = nil
local function ShowInputFrame(title,inputText)
	if not InputFrame then
		InputFrame = CreateFrame("Frame",nil,UIParent,"UIPanelDialogTemplate")
		InputFrame:SetSize(500,100)
		InputFrame:SetPoint("CENTER")
		InputFrame:SetFrameStrata("FULLSCREEN")
		InputFrame:SetClampedToScreen(true)
		InputFrame:EnableMouse(true)
		InputFrame:SetMovable(true)
		InputFrame:RegisterForDrag("LeftButton")
		InputFrame:SetScript("OnDragStart", function(self) 
			self:StartMoving() 
		end)
		InputFrame:SetScript("OnDragStop", function(self) 
			self:StopMovingOrSizing() 
		end)
		InputFrame:SetScript("OnShow",function (self)
			self.EditBox:HighlightText()
			self.EditBox:SetFocus()
		end)
		InputFrame:Hide()
	
		InputFrame.EditBox = CreateFrame("EditBox",nil,InputFrame,"InputBoxTemplate")
		InputFrame.EditBox:SetSize(470,20)
		InputFrame.EditBox:SetPoint("TOP",5,-35)
		InputFrame.EditBox:SetCursorPosition(0)
		InputFrame.EditBox:SetAutoFocus( false )
		InputFrame.EditBox:SetScript("OnEscapePressed",function(self) 
			self:ClearFocus() 
			self:GetParent().OK:Click("LeftButton")
		end)
		InputFrame.EditBox:SetScript("OnEnterPressed",function (self)
			self:GetParent().OK:Click("LeftButton")
		end)
		
		InputFrame.OK = CreateFrame("Button",nil,InputFrame,"UIPanelButtonTemplate")
		InputFrame.OK:SetPoint("TOP",0,-60)
		InputFrame.OK:SetSize(130,22)
		InputFrame.OK:SetText(CLOSE)
		InputFrame.OK:SetScript("OnClick",function (self)
			InputFrame:Hide()
			local input = InputFrame.EditBox:GetText()
		end)
	end
	if InputFrame:IsShown() then
		InputFrame:Hide()
	end
	InputFrame.Title:SetText(title or "")
	InputFrame.EditBox:SetText(inputText or "")
	InputFrame:Show()
end


local function GetCursorPos(obj)
	local x_f,y_f = GetCursorPosition()
	local s = obj:GetEffectiveScale()
	x_f, y_f = x_f/s, y_f/s
	local x,y = obj:GetLeft(),obj:GetTop()
	x = x_f-x
	y = (y_f-y)*(-1)
	return x,y
end

local function ButtonOnEnter(self)
	if not self.tooltip then return end
	GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
	GameTooltip:AddLine(self.tooltip)
	GameTooltip:Show()
end
local function ButtonOnLeave(self)
	GameTooltip_Hide()
end

local dataLoaded = false
local function LoadData()
	if dataLoaded then
		return
	end
	C_AddOns.LoadAddOn("LegionWardrobeData")

	for k,v in pairs(LTSData) do
		LTS[k] = v
	end
	
	dataLoaded = true
end

local function rgb2lab(r,g,b)
	r = r / 255;
	g = g / 255;
	b = b / 255;
	local x, y, z;
	
	r = (r > 0.04045) and math.pow((r + 0.055) / 1.055, 2.4) or r / 12.92;
	g = (g > 0.04045) and math.pow((g + 0.055) / 1.055, 2.4) or g / 12.92;
	b = (b > 0.04045) and math.pow((b + 0.055) / 1.055, 2.4) or b / 12.92;
	
	x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
	y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;
	z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
	
	x = (x > 0.008856) and math.pow(x, 1/3) or (7.787 * x) + 16/116;
	y = (y > 0.008856) and math.pow(y, 1/3) or (7.787 * y) + 16/116;
	z = (z > 0.008856) and math.pow(z, 1/3) or (7.787 * z) + 16/116;
	
	return (116 * y) - 16, 500 * (x - y), 200 * (y - z)
end

local function labDiff(Ar,Ag,Ab,Br,Bg,Bb)
	local deltaL = Ar - Br;
	local deltaA = Ag - Bg;
	local deltaB = Ab - Bb;
	local c1 = math.sqrt(Ag * Ag + Ab * Ab);
	local c2 = math.sqrt(Bg * Bg + Bb * Bb);
	local deltaC = c1 - c2;
	local deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
	deltaH = deltaH < 0 and 0 or math.sqrt(deltaH);
	local sc = 1.0 + 0.045 * c1;
	local sh = 1.0 + 0.015 * c1;
	local deltaLKlsl = deltaL / (1.0);
	local deltaCkcsc = deltaC / (sc);
	local deltaHkhsh = deltaH / (sh);
	local i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
	return i < 0 and 0 or math.sqrt(i);
end

local eventsFrame = CreateFrame("Frame")
eventsFrame:RegisterEvent("ADDON_LOADED")
eventsFrame:SetScript("OnEvent",function(self,event,arg1)
	if event == "ADDON_LOADED" then
		if arg1 == GlobalAddonName then				
			if C_AddOns.IsAddOnLoaded("Blizzard_Collections") then
				self:GetScript("OnEvent")(self,"ADDON_LOADED","Blizzard_Collections")
			elseif C_AddOns.IsAddOnLoaded("Blizzard_Transmog") then
				self:GetScript("OnEvent")(self,"ADDON_LOADED","Blizzard_Transmog")
			end
		elseif arg1 == "Blizzard_Collections" then
	
			
			local function SortVisuals(self)
				local comparison = function(source1, source2)
					if ( source1.colorDiff ~= source2.colorDiff ) then
						return source1.colorDiff > source2.colorDiff;
					end
					if ( source1.isCollected ~= source2.isCollected ) then
						return source1.isCollected;
					end
					if ( source1.isUsable ~= source2.isUsable ) then
						return source1.isUsable;
					end
					if ( source1.isFavorite ~= source2.isFavorite ) then
						return source1.isFavorite;
					end
					if ( source1.canDisplayOnPlayer ~= source2.canDisplayOnPlayer ) then
						return source1.canDisplayOnPlayer;
					end
					if ( source1.isHideVisual ~= source2.isHideVisual ) then
						return source1.isHideVisual;
					end
					if ( source1.hasActiveRequiredHoliday ~= source2.hasActiveRequiredHoliday ) then
						return source1.hasActiveRequiredHoliday;
					end
					if ( source1.uiOrder and source2.uiOrder ) then
						return source1.uiOrder > source2.uiOrder;
					end
					return source1.sourceID > source2.sourceID;
				end
			
				table.sort(self.filteredVisualsList, comparison);
			end
	
			local prevR, prevG, prevB, prevCat
			local function colorPick()
				LoadData()

				local info = {}
				info.r, info.g, info.b = prevR or .7,prevG or .7,prevB or .7
				info.hasOpacity = false
				info.swatchFunc = function()
					local newR, newG, newB = ColorPickerFrame:GetColorRGB()
					local newA = ColorPickerFrame:GetColorAlpha()

					if prevR == newR and prevG == newG and prevB == newB then
						return
					end
	
					prevR, prevG, prevB = newR, newG, newB
					
					local visualsList = WardrobeCollectionFrame.ItemsCollectionFrame.visualsList
	
					newR, newG, newB = newR * 255, newG * 255, newB * 255
	
					local labA, labB, labC = rgb2lab(newR, newG, newB)
	
					local filtered = {}
	
					for i=1,#visualsList do
						if not visualsList[i].isHideVisual then
							local colors = LTS.VisualColors[ visualsList[i].visualID ]
							local colorDiff
							local isValid
							if colors then
								for c=1,#colors,4 do
									local cR = colors:byte(c+0)
									local cG = colors:byte(c+1)
									local cB = colors:byte(c+2)
									local cP = colors:byte(c+3)
									if cR and cG and cB and cP then
										local diff = labDiff(labA, labB, labC, rgb2lab(cR, cG, cB))
		
										if diff <= 10 then
											isValid = true
											if diff == 0 then diff = 0.00001 end
											colorDiff = max(colorDiff or 0, (1 / diff) * cP)
										end
									end
								end
							end
							if isValid then
								filtered[#filtered+1] = visualsList[i]
								visualsList[i].colorDiff = colorDiff
							end
						end
					end
	
					WardrobeCollectionFrame.ItemsCollectionFrame.filteredVisualsList = filtered
					SortVisuals(WardrobeCollectionFrame.ItemsCollectionFrame)
					WardrobeCollectionFrame.ItemsCollectionFrame.PagingFrame:SetMaxPages(ceil(#WardrobeCollectionFrame.ItemsCollectionFrame.filteredVisualsList / WardrobeCollectionFrame.ItemsCollectionFrame.PAGE_SIZE))
					WardrobeCollectionFrame.ItemsCollectionFrame:ResetPage()
		
				end
				info.cancelFunc = function()
					if not ColorPickerFrame:IsMouseOver() then
						return
					end
					local newR, newG, newB, newA = ColorPickerFrame:GetPreviousValues()
	
					WardrobeCollectionFrame.ItemsCollectionFrame:FilterVisuals()
					WardrobeCollectionFrame.ItemsCollectionFrame:SortVisuals()
					WardrobeCollectionFrame.ItemsCollectionFrame.PagingFrame:SetMaxPages(ceil(#WardrobeCollectionFrame.ItemsCollectionFrame.filteredVisualsList / WardrobeCollectionFrame.ItemsCollectionFrame.PAGE_SIZE))
					WardrobeCollectionFrame.ItemsCollectionFrame:ResetPage()	
				end
				ColorPickerFrame:SetupColorPickerAndShow(info)
			end
		
			local colorSelectButton = CreateFrame("Button",nil,WardrobeCollectionFrame.ItemsCollectionFrame)
			colorSelectButton:SetPoint("TOPRIGHT", WardrobeCollectionFrame.ItemsCollectionFrame.SlotsFrame.Buttons[16], -5, -75)
			colorSelectButton:SetSize(34,34)
			colorSelectButton:SetScript("OnClick",function(self)
				colorPick()
			end)
			colorSelectButton:SetScript("OnEnter",ButtonOnEnter)
			colorSelectButton:SetScript("OnLeave",ButtonOnLeave)
			colorSelectButton.tooltip = "Wardrobe Enhanced: "..(COLOR_PICKER or "Select color")
			
			colorSelectButton.Texture = colorSelectButton:CreateTexture(nil,"ARTWORK")
			colorSelectButton.Texture:SetPoint("CENTER")
			colorSelectButton.Texture:SetSize(26,26)
			colorSelectButton.Texture:SetTexture([[Interface\AddOns\LegionWardrobe\wheeltexture]])

			for i=1,3 do
				for j=1,6 do
					--hooksecurefunc(WardrobeCollectionFrame.ItemsCollectionFrame["ModelR"..i.."C"..j],"OnMouseDown", function (self,button)
					WardrobeCollectionFrame.ItemsCollectionFrame["ModelR"..i.."C"..j]:HookScript("OnMouseDown",function(self,button)
						if button == "RightButton" and self.visualInfo and (not self.visualInfo.isCollected or IsShiftKeyDown()) then
							local app = C_TransmogCollection.GetAppearanceSources(self.visualInfo.visualID, WardrobeCollectionFrame.ItemsCollectionFrame.activeCategory, WardrobeCollectionFrame.ItemsCollectionFrame.transmogLocation)

							if app and app[1] and app[1].itemID then
								ShowInputFrame("url","https://wowhead.com/"..wowheadPrefix.."item="..app[1].itemID)
							end
						end
					end)
				end
			end

			do
				local IsEnableUndress = true
				local IsSavePosition = false
				local IsUseBigModelPosition = false

				local model = CreateFrame("DressUpModel",nil,WardrobeCollectionFrame.ItemsCollectionFrame,"BackdropTemplate")
				model:SetPoint("TOPLEFT",WardrobeCollectionFrame,"TOPRIGHT",5,0)
							
				local MOD = 6
				model:SetSize(78*MOD,104*MOD)
				model:SetBackdrop({bgFile = "Interface\\Buttons\\WHITE8X8",edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",tile = true,tileSize = 1,edgeSize = 8,insets = {left = 2,right = 2,top = 2,bottom = 2}})
				model:SetBackdropColor(0.07, 0.07, 0.07, 1) 
				model:SetBackdropBorderColor(0.4, 0.4, 0.4, 1) 
				
				model:MakeCurrentCameraCustom()
				model.cameraID = 1
				
				model:Hide()
				
				model.previewModelsList = {}
				for i=1,3 do
					for j=1,6 do
						tinsert(model.previewModelsList,WardrobeCollectionFrame.ItemsCollectionFrame["ModelR"..i.."C"..j])
					end
				end
				
				model:EnableMouse(true)
				model:SetScript("OnMouseDown",function (self,button)
					local x,y = GetCursorPos(self)
					self.x = x
					self.y = y
					local cx,cy,cz = self:GetPosition()
					self.cx = cx
					self.cy = cy
					self.cz = cz
					self.cf = self:GetFacing()
					self.mov = true
					self.isRotation = button ~= "RightButton"
				end)
				model:SetScript("OnMouseUp",function (self)
					self.mov = nil
				end)
				model:SetScript("OnUpdate",function (self)
					if not self.mov then
						return
					end
					local x,y = GetCursorPos(self)
					local diff_x = x - self.x
					local diff_y = y - self.y
					if self.isRotation then
						self:SetFacing(self.cf + diff_x / 65)
						
						if IsUseBigModelPosition then
							for i=1,#self.previewModelsList do
								self.previewModelsList[i]:SetFacing(self.cf + diff_x / 65)
							end
						end
					else
						self:SetPosition(self.cx,self.cy + diff_x / 200,self.cz - diff_y / 200)
						
						if IsUseBigModelPosition then
							for i=1,#self.previewModelsList do
								self.previewModelsList[i]:SetPosition(self.cx,self.cy + diff_x / 200,self.cz - diff_y / 200)
							end
						end
					end
				end)
				model:SetScript("OnMouseWheel",function (self,delta)
					local cx,cy,cz = self:GetPosition()
					self:SetPosition(cx + delta / 7,cy,cz)
					
					if IsUseBigModelPosition then
						for i=1,#self.previewModelsList do
							self.previewModelsList[i]:SetPosition(cx + delta / 7,cy,cz)
						end
					end
				end)
				model:SetScript("OnModelLoaded",function (self)

				end)
				
				function model:Reload(undress)
					self:SetUnit("player")
					if undress then
						self:Undress()
					end
					--self:TryOn(self.itemID or "item:94984")
				end
				
				local lastCamera = 152
				model:SetScript("OnShow",function (self)
					self:Reload(IsEnableUndress)
					Model_ApplyUICamera(model, lastCamera)
				end)
				
				local disableUndress = CreateFrame("CheckButton",nil,model,"UICheckButtonTemplate")  
				disableUndress.text:SetText("Undress")
				disableUndress:SetPoint("BOTTOMLEFT",5,0)
				disableUndress:SetScript("OnClick",function (self)
					IsEnableUndress = self:GetChecked()
					model:Reload(IsEnableUndress)
					Model_ApplyUICamera(model, lastCamera)
				end)
				disableUndress:SetChecked(true)
				disableUndress:SetScale(.8)
			
				local savePosition = CreateFrame("CheckButton",nil,model,"UICheckButtonTemplate")  
				savePosition.text:SetText("Save position")
				savePosition:SetPoint("BOTTOMLEFT",105,0)
				savePosition:SetScript("OnClick",function (self)
					IsSavePosition = self:GetChecked()
				end)
				savePosition:SetScale(.8)
				
				local useBigModelPos = CreateFrame("CheckButton",nil,model,"UICheckButtonTemplate")  
				useBigModelPos.text:SetText("Use this position in preview")
				useBigModelPos:SetPoint("BOTTOMLEFT",205,0)
				useBigModelPos:SetScript("OnClick",function (self)
					IsUseBigModelPosition = self:GetChecked()
				end)
				useBigModelPos:SetScale(.8)
				
				local slotToCamera = {
					["HEADSLOT"] 		= {531},
					["SHOULDERSLOT"]	= {532},
					["BACKSLOT"]		= {533},
					["CHESTSLOT"]		= {535},
					["TABARDSLOT"]		= {535},
					["SHIRTSLOT"]		= {536},
					["WRISTSLOT"]		= {537},
					["HANDSSLOT"]		= {538},
					["WAISTSLOT"]		= {539},
					["LEGSSLOT"]		= {540},
					["FEETSLOT"]		= {541},
					["SECONDARYHANDSLOT"]	= {151,151},
				}
				
				hooksecurefunc(WardrobeCollectionFrame.ItemsCollectionFrame,"ChangeModelsSlot", function (oldSlot, newSlot)
					if IsSavePosition then
						if IsEnableUndress then
							model:Undress()
						end
						return
					end
					model:Reload(IsEnableUndress)
					if slotToCamera[newSlot] and not slotToCamera[newSlot][2] then
						C_Timer.NewTimer(0.1,function ()
							local m = WardrobeCollectionFrame.ItemsCollectionFrame.ModelR1C1
							if not m.visualInfo or not WardrobeCollectionFrame.ItemsCollectionFrame.activeCategory then
								return
							end
							local cameraID = C_TransmogCollection.GetAppearanceCameraID(m.visualInfo.visualID)
							slotToCamera[newSlot][2] = cameraID
							lastCamera = cameraID
							Model_ApplyUICamera(model, cameraID)
						end)
					end 
					lastCamera = (slotToCamera[newSlot] and slotToCamera[newSlot][2]) or (slotToCamera[newSlot] and slotToCamera[newSlot][1]) or 152
					Model_ApplyUICamera(model, lastCamera)
				end)
				
				for i=1,3 do
					for j=1,6 do
						WardrobeCollectionFrame.ItemsCollectionFrame["ModelR"..i.."C"..j]:HookScript("OnEnter",function(self,button)
							if not self.visualInfo or not WardrobeCollectionFrame.ItemsCollectionFrame.activeCategory or not model:IsShown() then
								return
							end
							
							local sourceID = WardrobeCollectionFrame.ItemsCollectionFrame:GetAnAppearanceSourceFromVisual(self.visualInfo.visualID)
							model:TryOn(sourceID)
						end)
					end
				end
				
				
				local bigModelButton = CreateFrame("Button",nil,WardrobeCollectionFrame.ItemsCollectionFrame)
				bigModelButton:SetPoint("TOP", colorSelectButton, "BOTTOM", 0, 0)
				bigModelButton:SetSize(31,31)
				bigModelButton:SetScript("OnClick",function(self)
					if model:IsShown() then
						model:Hide()
						self.Texture:SetDesaturated(true)
					else
						model:Show()
						self.Texture:SetDesaturated(false)
					end
				end)
				bigModelButton:SetScript("OnEnter",ButtonOnEnter)
				bigModelButton:SetScript("OnLeave",ButtonOnLeave)
				bigModelButton.tooltip = "Open Big Model"
				
				bigModelButton.Texture = bigModelButton:CreateTexture(nil,"ARTWORK")
				bigModelButton.Texture:SetAllPoints()
				bigModelButton.Texture:SetTexture([[Interface\AddOns\LegionWardrobe\Transmogrify]])
				bigModelButton.Texture:SetTexCoord(450/512,482/512,88/512,120/512)
				bigModelButton.Texture:SetDesaturated(true)

				bigModelButton:Click()

			end	
		elseif arg1 == "Blizzard_Transmog" then
	
			local function SetCollectionEntries(self, entries, retainCurrentPage)
				local compareEntries = function(element1, element2)
					local source1 = element1.appearanceInfo;
					local source2 = element2.appearanceInfo;
			
					if ( source1.colorDiff ~= source2.colorDiff ) then
						return source1.colorDiff > source2.colorDiff;
					end
					if source1.isCollected ~= source2.isCollected then
						return source1.isCollected;
					end
			
					if source1.isUsable ~= source2.isUsable then
						return source1.isUsable;
					end
			
					if source1.isFavorite ~= source2.isFavorite then
						return source1.isFavorite;
					end
			
					if source1.canDisplayOnPlayer ~= source2.canDisplayOnPlayer then
						return source1.canDisplayOnPlayer;
					end
			
					if source1.isHideVisual ~= source2.isHideVisual then
						return source1.isHideVisual;
					end
			
					if source1.hasActiveRequiredHoliday ~= source2.hasActiveRequiredHoliday then
						return source1.hasActiveRequiredHoliday;
					end
			
					if source1.uiOrder and source2.uiOrder then
						return source1.uiOrder > source2.uiOrder;
					end
			
					return source1.sourceID > source2.sourceID;
				end
			
				local collectionElements = {};
				for _index, itemEntry in ipairs(entries) do
					if (itemEntry.isUsable and itemEntry.isCollected) or itemEntry.alwaysShowItem then
						local element = {
							templateKey = "COLLECTION_ITEM",
							appearanceInfo = itemEntry,
							collectionFrame = self
						};
						table.insert(collectionElements, element);
					end
				end
			
				table.sort(collectionElements, compareEntries);
			
				local collectionData = {{elements = collectionElements}};
				local dataProvider = CreateDataProvider(collectionData);
				self.PagedContent:SetDataProvider(dataProvider, retainCurrentPage);
			end
	
			local prevR, prevG, prevB
			local function colorPick()
				LoadData()

				local info = {}
				info.r, info.g, info.b = prevR or .7,prevG or .7,prevB or .7
				info.hasOpacity = false
				info.swatchFunc = function()
					local newR, newG, newB = ColorPickerFrame:GetColorRGB()
					local newA = ColorPickerFrame:GetColorAlpha()
	
					if prevR == newR and prevG == newG and prevB == newB then
						return
					end
	
					prevR, prevG, prevB = newR, newG, newB
					
					TransmogFrame.WardrobeCollection.TabContent.ItemsFrame:RefreshCollectionEntries()
					local visualsList = TransmogFrame.WardrobeCollection.TabContent.ItemsFrame.itemCollectionEntries
	
					newR, newG, newB = newR * 255, newG * 255, newB * 255
	
					local labA, labB, labC = rgb2lab(newR, newG, newB)
	
					local filtered = {}
	
					for i=1,#visualsList do
						if not visualsList[i].isHideVisual then
							local colors = LTS.VisualColors[ visualsList[i].visualID ]
							local colorDiff
							local isValid
							if colors then
								for c=1,#colors,4 do
									local cR = colors:byte(c+0)
									local cG = colors:byte(c+1)
									local cB = colors:byte(c+2)
									local cP = colors:byte(c+3)
									if cR and cG and cB and cP then
										local diff = labDiff(labA, labB, labC, rgb2lab(cR, cG, cB))
		
										if diff <= 10 then
											isValid = true
											if diff == 0 then diff = 0.00001 end
											colorDiff = max(colorDiff or 0, (1 / diff) * cP)
										end
									end
								end
							end
							if isValid then
								filtered[#filtered+1] = visualsList[i]
								visualsList[i].colorDiff = colorDiff
							end
						end
					end
	
					TransmogFrame.WardrobeCollection.TabContent.ItemsFrame.itemCollectionEntries = filtered
					SetCollectionEntries(TransmogFrame.WardrobeCollection.TabContent.ItemsFrame, TransmogFrame.WardrobeCollection.TabContent.ItemsFrame.itemCollectionEntries, false);
				end
				info.cancelFunc = function()
					if not ColorPickerFrame:IsMouseOver() then
						return
					end
					local newR, newG, newB, newA = ColorPickerFrame:GetPreviousValues()
					prevR, prevG, prevB = nil
	
					TransmogFrame.WardrobeCollection.TabContent.ItemsFrame:RefreshCollectionEntries()
				end
				ColorPickerFrame:SetupColorPickerAndShow(info)

				prevR, prevG, prevB = nil
				info.swatchFunc()
			end

		
			local colorSelectButton = CreateFrame("Button",nil,TransmogFrame.WardrobeCollection.TabContent.ItemsFrame)
			colorSelectButton:SetPoint("TOPRIGHT", TransmogFrame.WardrobeCollection.TabContent.ItemsFrame, "TOPRIGHT", -30, -50)
			colorSelectButton:SetSize(40,40)
			colorSelectButton:SetScript("OnClick",function(self)
				colorPick()
			end)
			colorSelectButton:SetScript("OnEnter",ButtonOnEnter)
			colorSelectButton:SetScript("OnLeave",ButtonOnLeave)
			colorSelectButton.tooltip = "Wardrobe Enhanced: "..(COLOR_PICKER or "Select color")
			
			colorSelectButton.Texture = colorSelectButton:CreateTexture(nil,"ARTWORK")
			colorSelectButton.Texture:SetPoint("CENTER")
			colorSelectButton.Texture:SetSize(32,32)
			colorSelectButton.Texture:SetTexture([[Interface\AddOns\LegionWardrobe\wheeltexture]])
	
		end
	end
end)