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

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

-- AucItemClasses
local Class_Recipe					=select(7, GetAuctionItemClasses())

-- AucItemSubClasses
local SubClass_Potions				=select(2, GetAuctionItemSubClasses(4))
local SubClass_Elixirs				=select(3, GetAuctionItemSubClasses(4))
local SubClass_Flasks				=select(4, GetAuctionItemSubClasses(4))
local SubClass_Herbs				=select(6, GetAuctionItemSubClasses(6))
local SubClass_Recipe_Alchemy		=select(7, GetAuctionItemSubClasses(7))
local SubClass_Reagents				=select(2, GetAuctionItemSubClasses(9))
local SubClass_Other				=select(5, GetAuctionItemSubClasses(9))

-- Tab Names
local TN={}
TN.Alchemy=SubClass_Recipe_Alchemy

TN.All=ALL 						-- Источник==Алхимия ИЛИ Используется==Алхимия
TN.Herbs=SubClass_Herbs 		-- Травы
TN.Reagents=SubClass_Reagents	-- Используется==Алхимия И НЕ Травы

TN.Potions=SubClass_Potions
TN.Elixirs=SubClass_Elixirs
TN.Flasks=SubClass_Flasks
TN.Products=SubClass_Other		-- Источник==Алхимия и НЕ Potion,Elixir,Flask

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 isAlchemy(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 (ReagentsForAlchemy[tonumber(ItemID)] or CraftedByAlchemy[tonumber(ItemID)] or subType==SubClass_Recipe_Alchemy)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isHerb(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end
	return (subType==SubClass_Herbs)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isReagent(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 (ReagentsForAlchemy[tonumber(ItemID)] and subType ~= SubClass_Herbs)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isPotion(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end
	return (subType==SubClass_Potions)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isElixir(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end
	return (subType==SubClass_Elixirs)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isFlask(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end
	return (subType==SubClass_Flasks)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isProduct(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 (CraftedByAlchemy[tonumber(ItemID)] and subType~=SubClass_Potions and subType~=SubClass_Elixirs and subType~=SubClass_Flasks)
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_Alchemy)
end
-----------------------------------------------------------------------------------------------------------------------------------------
CombuctorSet:Register(TN.Alchemy, IconPathName, isAlchemy)

CombuctorSet:RegisterSubSet(TN.All,		TN.Alchemy,nil,isAlchemy)
CombuctorSet:RegisterSubSet(TN.Herbs,	TN.Alchemy,nil,isHerb)
CombuctorSet:RegisterSubSet(TN.Reagents,TN.Alchemy,nil,isReagent)
CombuctorSet:RegisterSubSet(TN.Potions,	TN.Alchemy,nil,isPotion)
CombuctorSet:RegisterSubSet(TN.Elixirs,	TN.Alchemy,nil,isElixir)
CombuctorSet:RegisterSubSet(TN.Flasks,	TN.Alchemy,nil,isFlask)
CombuctorSet:RegisterSubSet(TN.Products,TN.Alchemy,nil,isProduct)
CombuctorSet:RegisterSubSet(TN.Recipes,	TN.Alchemy,nil,isRecipe)
