-- REQUIRED Combuctor
local CombuctorSet = Combuctor:GetModule("Sets")

-- Profession Icon Name
local IconPathName="Interface/Icons/Trade_Tailoring"

-- AucItemClasses
local Class_Armor						=select(2, GetAuctionItemClasses())
local Class_Bags						=select(3, GetAuctionItemClasses())
local Class_Recipe						=select(7, GetAuctionItemClasses())

-- AucItemSubClasses
local SubClass_Cloth					=select(2, GetAuctionItemSubClasses(6))
local SubClass_Reagents					=select(2, GetAuctionItemSubClasses(9))
local SubClass_Other					=select(5, GetAuctionItemSubClasses(9))
local SubClass_Recipe_Tailoring			=select(3, GetAuctionItemSubClasses(7))

-- Tab Names
local TN={}
TN.Tailoring=SubClass_Recipe_Tailoring
TN.All=ALL 								-- Источник==Портняжное ИЛИ Используется==Портняжное или Рецепт
-- Материалы
TN.Cloth=SubClass_Cloth				 	-- Ткань
TN.Reagents=SubClass_Reagents			-- Использется==Портнядное И НЕ Ткань
-- Продукты
TN.Armor=Class_Armor					-- Изготовленная броня
TN.Bags=Class_Bags						-- Изготовленная броня
TN.Products=SubClass_Other				-- Источник==Портняжное И НЕ Броня
-- Рецепты
TN.Recipes=Class_Recipe					-- Рецепты для Портняжного
-----------------------------------------------------------------------------------------------------------------------------------------
local function GetItemIDFromLink(itemLink)
	if not itemLink or itemLink=="" then return nil end

	local itemString = string.match(itemLink, "item[%-?%d:]+")
	local linkType, itemId, enchantId,jewelId1, jewelId2, jewelId3, jewelId4,suffixId, uniqueId = strsplit(":", itemString)
	if (linkType == 'item') then
		return itemId
	end

end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isTailoring(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not link then return false end
	if not subType then return false end

	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end

	return (ReagentsForTailoring[tonumber(ItemID)] or CraftedByTailoring[tonumber(ItemID)] or subType==SubClass_Recipe_Tailoring or type==Class_Bags)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isCloth(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end
	return (subType==SubClass_Cloth)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isReagent(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not link then return false end

	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end

	return (ReagentsForTailoring[tonumber(ItemID)] and subType~=SubClass_Cloth)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isArmor(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not type then return false end
	if not link then return false end
	
	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end
	
	return (CraftedByTailoring[tonumber(ItemID)] and type==Class_Armor)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isBag(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not type then return false end
	return (type==Class_Bags)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isProduct(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not link then return false end
	if not type then return false end

	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end

	return (CraftedByTailoring[tonumber(ItemID)] and type~=Class_Armor and type~=Class_Bags and subType~=SubClass_Cloth)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isRecipe(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not type then return false end
	if not subType then return false end
	return (type==Class_Recipe and subType==SubClass_Recipe_Tailoring)
end
-----------------------------------------------------------------------------------------------------------------------------------------
CombuctorSet:Register(TN.Tailoring, IconPathName, isTailoring)

CombuctorSet:RegisterSubSet(TN.All,			TN.Tailoring,nil,isTailoring)
CombuctorSet:RegisterSubSet(TN.Cloth,		TN.Tailoring,nil,isCloth)
CombuctorSet:RegisterSubSet(TN.Reagents,	TN.Tailoring,nil,isReagent)
CombuctorSet:RegisterSubSet(TN.Armor,		TN.Tailoring,nil,isArmor)
CombuctorSet:RegisterSubSet(TN.Bags,		TN.Tailoring,nil,isBag)
CombuctorSet:RegisterSubSet(TN.Products,	TN.Tailoring,nil,isProduct)
CombuctorSet:RegisterSubSet(TN.Recipes,		TN.Tailoring,nil,isRecipe)
