local SousChef = SousChef
local u = SousChef.Utility
local m = SousChef.Media

function SousChef.AddRankToSlot(row)
    local slot = row.dataEntry.data
    local bagId = slot.bagId
    local slotIndex = slot.slotIndex
	local rankIcon = SousChef.getIcon(row)

	-- Allow for ingeniousclown's Inventory Grid View
	if row:GetWidth() - row:GetHeight() < 5 then	-- if we're mostly square
		rankIcon:SetDimensions(20,20)
		rankIcon:SetAnchor(TOPLEFT, row, TOPLEFT, 2)
	else
		rankIcon:SetDimensions(30, 30)
		rankIcon:SetAnchor(CENTER, row, CENTER, 200)
	end

	rankIcon:SetHidden(true)

	if ((GetItemCraftingInfo(bagId, slotIndex)) == CRAFTING_TYPE_PROVISIONING) then
		local texture = SousChef.Pantry[u.GetItemID(GetItemLink(bagId, slotIndex))]
		if SousChef.settings.showAltKnowledge then texture = SousChef.settings.Pantry[u.GetItemID(GetItemLink(bagId, slotIndex))] end
		if texture then
			rankIcon:SetColor(SousChef.settings.colour[1], SousChef.settings.colour[2], SousChef.settings.colour[3])
			rankIcon:SetHidden(false)
			if SousChef.settings.boldIcon then
				rankIcon:SetTexture(m.COOKINGB[texture])
			else
				rankIcon:SetTexture(m.COOKING[texture])
			end

		end
    else
        if SousChef.settings.processRecipes then
            if GetItemType(bagId, slotIndex) == ITEMTYPE_RECIPE then
            	if u.MatchInIgnoreList(slot.name) then return end
                local match = u.MatchInCookbook(slot.name)
                local gmatch = u.MatchInGlobalCookbook(slot.name)
                if (match and SousChef.settings.checkKnown == "known") or
                   (not match and SousChef.settings.checkKnown == "unknown")then
                    rankIcon:SetTexture(m.CANLEARN)
                    rankIcon:SetHidden(false)
                    if not match and gmatch and SousChef.settings.checkKnown == "unknown" and SousChef.settings.markAlt then
                        rankIcon:SetColor(1,1,1,0.2)
                    else
                        rankIcon:SetColor(1,1,1,1)
                    end
                end
            end
		end
	end
end