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

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

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

-- AucItemSubClasses
local SubClass_Herbs				=select(6, GetAuctionItemSubClasses(6))
local SubClass_Reagents				=select(2, GetAuctionItemSubClasses(9))
local SubClass_Scrolls				=select(7, GetAuctionItemSubClasses(4))
local SubClass_Other				=select(5, GetAuctionItemSubClasses(9))
local SubClass_Recipe_Inscription	=select(12, GetAuctionItemSubClasses(7))

-- Tab Names
local TN={}
TN.Inscription=SubClass_Recipe_Inscription
TN.All=ALL 								-- Источник==Начертание ИЛИ Используется==Начертание или Рецепт
-- Материалы
TN.Herbs=SubClass_Herbs			 		-- Травы
TN.Reagents=SubClass_Reagents			-- Использется==Начертание И НЕ Травы
-- Продукты
TN.Glyphs=Class_Glyphs					-- Символы
TN.Scrolls=SubClass_Scrolls				-- Символы
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 isInscription(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 (ReagentsForInscription[tonumber(ItemID)] or subType==SubClass_Herbs or CraftedByInscription[tonumber(ItemID)] or subType==SubClass_Recipe_Inscription)
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

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

	return (ReagentsForInscription[tonumber(ItemID)] and subType~=SubClass_Herbs)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isGlyph(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not type then return false end
	return (type==Class_Glyphs)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isScroll(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end
	return (subType==SubClass_Scrolls)
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
	if not subType then return false end

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

	return (CraftedByInscription[tonumber(ItemID)] and type~=Class_Glyphs and subType~=SubClass_Scrolls)
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_Inscription)
end
-----------------------------------------------------------------------------------------------------------------------------------------
CombuctorSet:Register(TN.Inscription, IconPathName, isInscription)

CombuctorSet:RegisterSubSet(TN.All,			TN.Inscription,nil,isInscription)
CombuctorSet:RegisterSubSet(TN.Herbs,		TN.Inscription,nil,isHerb)
CombuctorSet:RegisterSubSet(TN.Reagents,	TN.Inscription,nil,isReagent)
CombuctorSet:RegisterSubSet(TN.Glyphs,		TN.Inscription,nil,isGlyph)
CombuctorSet:RegisterSubSet(TN.Scrolls,		TN.Inscription,nil,isScroll)
CombuctorSet:RegisterSubSet(TN.Products,	TN.Inscription,nil,isProduct)
CombuctorSet:RegisterSubSet(TN.Recipes,		TN.Inscription,nil,isRecipe)
