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

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

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

-- AucItemSubClasses
local SubClass_Materials			=select(4, GetAuctionItemSubClasses(6))
local SubClass_Reagents				=select(2, GetAuctionItemSubClasses(9))
local SubClass_Other				=select(5, GetAuctionItemSubClasses(9))
local SubClass_Recipe_Jewelcrafting	=select(11, GetAuctionItemSubClasses(7))

local SpellID=31252
local Prospecting=GetSpellInfo(SpellID)
if not Prospecting then
	Prospecting=SubClass_Materials
end 

-- Tab Names
local TN={}
TN.Jewelcrafting=SubClass_Recipe_Jewelcrafting
TN.All=ALL 								-- Источник==Кузнечное дело ИЛИ Используется==Кузнечное дело или Рецепт
-- Материалы
TN.Materials=Prospecting		 		-- Руда которую можно просеить
TN.Reagents=SubClass_Reagents			-- Используется==Ювелирное дело деле И НЕ Металл и камни
-- Продукты
TN.Jewels=Class_Jewels					-- Самоцветы
TN.Products=SubClass_Other				-- Источник==Кузнечное дело И НЕ Оружие И НЕ Броня
-- Рецепты
TN.Recipes=Class_Recipe					-- Рецепты для Кузнечного

local ItemID
-----------------------------------------------------------------------------------------------------------------------------------------
local function GetItemIDFromLink(itemLink)
	if not itemLink or itemLink=="" then return nil end

	local itemString = string.match(itemLink, "item[%-?%d:]+")
	if not itemString then return nil end
	
	local linkType, itemId, enchantId,jewelId1, jewelId2, jewelId3, jewelId4,suffixId, uniqueId = strsplit(":", itemString)
	if (linkType == 'item') then
		return itemId
	end
return nil
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isJewelcrafting(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
	if not type then return false end
	
	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end

	return (ReagentsForProspecting[tonumber(ItemID)] or ReagentsForJewelcrafting[tonumber(ItemID)] or CraftedByJewelcrafting[tonumber(ItemID)] or type==Class_Jewels or subType==SubClass_Recipe_Jewelcrafting)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isMaterial(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end

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

	return (ReagentsForProspecting[tonumber(ItemID)])
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isReagent(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 (ReagentsForJewelcrafting[tonumber(ItemID)] and CraftedByJewelcrafting[tonumber(ItemID)]==nil and type~=Class_Jewels)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isJewel(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not type then return false end
	
	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end
	
	return (type==Class_Jewels)
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 (CraftedByJewelcrafting[tonumber(ItemID)] and type~=Class_Jewels)
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_Jewelcrafting)
end
-----------------------------------------------------------------------------------------------------------------------------------------
CombuctorSet:Register(TN.Jewelcrafting, IconPathName, isJewelcrafting)

CombuctorSet:RegisterSubSet(TN.All,			TN.Jewelcrafting,nil,isJewelcrafting)
CombuctorSet:RegisterSubSet(TN.Materials,	TN.Jewelcrafting,nil,isMaterial)
CombuctorSet:RegisterSubSet(TN.Reagents,	TN.Jewelcrafting,nil,isReagent)
CombuctorSet:RegisterSubSet(TN.Jewels,		TN.Jewelcrafting,nil,isJewel)
CombuctorSet:RegisterSubSet(TN.Products,	TN.Jewelcrafting,nil,isProduct)
CombuctorSet:RegisterSubSet(TN.Recipes,		TN.Jewelcrafting,nil,isRecipe)
