
PeriodicTableFeedOMatic = AceLibrary("AceAddon-2.0"):new("AceHook-2.0")

function PeriodicTableFeedOMatic:OnEnable()
	if FOM_Feed then self:Hook("FOM_Feed") end
end

function PeriodicTableFeedOMatic:OnDisable()
	if FOM_Feed then self:Unhook("FOM_Feed") end
end

function PeriodicTableFeedOMatic:FOM_Feed(aFood)
	if not self.ImportDone then
		local sets = {
			{"foodclassbread", FOM_DIET_BREAD},
			{"foodclassfish", FOM_DIET_FISH},
			{"foodclassmeat", FOM_DIET_MEAT},
			{"foodclasscheese", FOM_DIET_CHEESE},
			{"foodclassfruit", FOM_DIET_FRUIT},
			{"foodclassfungus", FOM_DIET_FUNGUS},
			{"foodbonus", FOM_DIET_BONUS},
		}

		for _,vals in pairs(sets) do
			local dest = vals[2]
			PeriodicTable:ItemInSet(1, vals[1])
			FOM_Foods[dest] = {}
			for _,set in pairs(PeriodicTable.k.Food[vals[1]]) do
				if PeriodicTable.vars.cache[set] then
					for item,v in pairs(PeriodicTable.vars.cache[set]) do
						table.insert(FOM_Foods[dest], item)
					end
				end
			end
		end
		self.ImportDone = true
	end

	return self.hooks["FOM_Feed"](aFood)
end
