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

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

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

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

-- Tab Names
local TN={}
TN.Leatherworking=SubClass_Recipe_Leatherworking
TN.All=ALL 								-- Источник==Начертание ИЛИ Используется==Начертание или Рецепт
-- Материалы
TN.Leather=SubClass_Leather			 	-- Кожа
TN.Reagents=SubClass_Reagents			-- Использется==Кожевничество И НЕ Кожа
-- Продукты
TN.Armor=Class_Armor					-- Изготовленная броня
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 isLeatherworking(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

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

	--return true
	return (ReagentsForLeatherworking[tonumber(ItemID)] or CraftedByLeatherworking[tonumber(ItemID)] or subType==SubClass_Recipe_Leatherworking)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isLeather(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end
	return (subType==SubClass_Leather)
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 true
	return (ReagentsForLeatherworking[tonumber(ItemID)] and subType~=SubClass_Leather)
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 (CraftedByLeatherworking[tonumber(ItemID)] and type==Class_Armor)
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 (CraftedByLeatherworking[tonumber(ItemID)] and ReagentsForLeatherworking[tonumber(ItemID)]==nil and subType~=SubClass_Leather and type~=Class_Armor)
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_Leatherworking)
end
-----------------------------------------------------------------------------------------------------------------------------------------
CombuctorSet:Register(TN.Leatherworking, IconPathName, isLeatherworking)

CombuctorSet:RegisterSubSet(TN.All,			TN.Leatherworking,nil,isLeatherworking)
CombuctorSet:RegisterSubSet(TN.Leather,		TN.Leatherworking,nil,isLeather)
CombuctorSet:RegisterSubSet(TN.Reagents,	TN.Leatherworking,nil,isReagent)
CombuctorSet:RegisterSubSet(TN.Armor,		TN.Leatherworking,nil,isArmor)
CombuctorSet:RegisterSubSet(TN.Products,	TN.Leatherworking,nil,isProduct)
CombuctorSet:RegisterSubSet(TN.Recipes,		TN.Leatherworking,nil,isRecipe)
