local S = minetest.get_translator("kilns")

local function get_description(stack)
	local def = minetest.registered_items[stack:get_name()]
	if def then
		return def.description or S("Unknown Item")
	else
		return S("Unknown Item")
	end
end

local function get_contents(fuelstack, instack, outstack)
	local str = S("Kiln") ..
		"\n" .. S("Contents") ..
		"\n" .. S("Fuel") .. ": "


	str = str .. fuelstack:get_count() .. "\n"

	if not instack:is_empty()
	then
		str = str .. S("To smelt") .. ": " .. get_description(instack) ..
			": " .. instack:get_count() .. "\n"
	end
	if not outstack:is_empty()
	then
		str = str .. S("Finished smelting") .. ": " .. get_description(outstack) ..
			": " .. outstack:get_count() .. "\n"
	end
	return str
end

local empty_text = S([[Empty Kiln
Use to put in items
Punch to take out a single item
Hold Special to process a whole stack at once
]])


local function update_infotext(meta, burning)
	local inv = meta:get_inventory()

	local fuelstack = inv:get_stack("fuel", 1)
	local instack = inv:get_stack("in", 1)
	local outstack = inv:get_stack("out", 1)


	local infotext
	if fuelstack:is_empty() and
		instack:is_empty() and
		outstack:is_empty()
	then
		infotext = empty_text
	else
		infotext = get_contents(fuelstack, instack, outstack)
	end
	meta:set_string("infotext", infotext)



end

return update_infotext
