Die Dokumentation für dieses Modul kann unter Modul:Infobox/Doku erstellt werden

local argutils = require("Module:Arguments")

local M = {}

local function build_main_section(args)
	local section = mw.html.create("div")
	section:addClass("infobox__section")
	
	if args.header ~= nil then
		local header = mw.html.create("div")
		header:attr("role", "heading")
		header:attr("aria-level", 1)
		header:addClass("infobox__main-header")
		header:wikitext(args.header)
		section:node(header)
	end
	
	if args.subheader ~= nil then
		local subheader = mw.html.create("p")
		subheader:addClass("infobox__subheader")
		subheader:wikitext(args.subheader)
		section:node(subheader)
	end
	
	if args.images ~= nil then
		for _, image_args in ipairs(args.images) do
			section:wikitext(image_args)
		end
	end
	
	return section
end

local function build_section_entry(args)
	if type(args) == "string" then
		local div = mw.html.create("div")
		div:addClass("infobox__section-entry")
		div:wikitext(args)
		return div
	else
		local dl = mw.html.create("dl")
		dl:addClass("infobox__section-entry")
		
		if args.label ~= nil then
			local dt = mw.html.create("dt")
			dt:addClass("infobox__section-entry-label")
			dt:wikitext(args.label)
			dl:node(dt)
		end
		if args.text ~= nil then
			local dd = mw.html.create("dd")
			dd:addClass("infobox__section-entry-text")
			dd:wikitext(args.text)
			dl:node(dd)
		end
		
		return dl
	end
end

local function build_section(args)
	local section = mw.html.create("div")
	section:addClass("infobox__section")
	
	if args.header ~= nil then
		local header = mw.html.create("div")
		header:attr("role", "heading")
		header:attr("aria-level", 2)
		header:addClass("infobox__section-header")
		header:wikitext(args.header)
		section:node(header)
	end
	
	if args.entries ~= nil then
		for _, entry_args in ipairs(args.entries) do
			section:node(build_section_entry(entry_args))
		end
	end
	
	return section
end

local function build(args)
	local wrapper = mw.html.create("div")
	wrapper:attr("role", "complementary")
	wrapper:addClass("infobox")
	
	wrapper:node(build_main_section(args))
	if args.sections ~= nil then
		for _, section_args in ipairs(args.sections) do
			wrapper:node(build_section(section_args))	
		end
	end
	
	return wrapper
end

function M.render(frame)
	local parentFrame = frame:getParent() or {}
	local flat_args = parentFrame.args or {}
	local args = argutils.parse_deep(flat_args)
	return tostring(build(args))
end

return M