local m_links = require("Module:links")
local lang = require("Module:languages").getByCode("non")
local export = {}

local accel_forms = {
	nsi = "indef|nom|s",
	nsd = "def|nom|s",
	npi = "indef|nom|p",
	npd = "def|nom|p",
	asi = "indef|acc|s",
	asd = "def|acc|s",
	api = "indef|acc|p",
	apd = "def|acc|p",
	dsi = "indef|dat|s",
	dsd = "def|dat|s",
	dpi = "indef|dat|p",
	dpd = "def|dat|p",
	gsi = "indef|gen|s",
	gsd = "def|gen|s",
	gpi = "indef|gen|p",
	gpd = "def|gen|p",
}

function export.create(frame)
	local args = frame:getParent().args
	local links = {}
	if not args[1] or args[1] == "" then
		return "―"
	else
		local accel_form = args[2]
		local accel
		if accel_form then
			if accel_forms[accel_form] then
				accel_form = accel_forms[accel_form]
			end
			accel = {form = accel_form}
		end
		local words = mw.text.split(args[1], "%s*,%s*")
		if words then
			for i,j in ipairs(words) do
				table.insert(links, m_links.full_link({lang = lang, term = j, accel = accel}))
			end
		end
	end
	return table.concat(links, ", ")
end

return export