local m_utilities = require("Module:utilities")
local m_links = require("Module:links")
local m_translit = require("Module:Goth-translit")

local lang = require("Module:languages").getByCode("got")

local export = {}


local function postprocess(args, data)
	for key, form in pairs(data.forms) do
		-- Do not show passive forms for verbs that don't have them
		if args["nopasv"] and key:find("pasv") then
			form = nil
		end
		
		data.forms[key] = form
	end
	
	-- Check if the lemma form matches the page name
	if data.forms["inf"] and lang:makeEntryName(m_translit.tr_reverse(data.forms["inf"][1])) ~= mw.title.getCurrentTitle().text then
		table.insert(data.categories, "變位形式不對應頁面名稱的" ..lang:getCanonicalName() .. "條目")
	end
end


local function make_Latn(args, names)
	for _, name in ipairs(names) do
		if args[name] then
			if type(args[name]) == "table" then
				for i, _ in ipairs(args[name]) do
					args[name][i] = m_translit.tr(args[name][i])
				end
			else
				args[name] = m_translit.tr(args[name])
			end
		end
	end
end


-- Inflection functions

export["st"] = function(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		[2] = {required = true, default = "{{{2}}}"},
		[3] = {required = true, default = "{{{3}}}"},
		[4] = {required = true, default = "{{{4}}}"},
		["imp2sg"] = {},
		["past2sg"] = {},
		
		["class"] = {},
		["irr"] = {type = "boolean"},
		["j"] = {},
		["nopasv"] = {type = "boolean"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	make_Latn(args, {1, 2, 3, 4, "imp2sg", "past2sg"})
	
	if args["j"] and not (args["j"] == "ji" or args["j"] == "ei") then
		error("Invalid value for parameter j=, must be \"ji\", \"ei\" or empty.")
	end
	
	local data = {
		forms = {},
		info = (args["class"] and "" .. args["class"] .. "類" or "") .. "強變化" .. (args["j"] and ",j-現在時" or "") .. (args["irr"] and ",不規則" or ""),
		categories = {lang:getCanonicalName() .. (args["class"] and "" .. args["class"] .. "類" or "") .. "強變化" .. (args["j"] and "j-現在時 " or "") .. "動詞"}
		}
	
	if args["irr"] then
		table.insert(data.categories, lang:getCanonicalName() .. "不規則動詞")
	end
	
	-- Present indicative
	data.forms["pres_indc_1sg"] = {args[1] .. (args["j"] and "j" or "") .. "a"}
	data.forms["pres_indc_2sg"] = {args[1] .. (args["j"] or "i") .. "s"}
	data.forms["pres_indc_3sg"] = {args[1] .. (args["j"] or "i") .. "þ"}
	data.forms["pres_indc_1du"] = {args[1] .. (args["j"] and "j" or "") .. "ōs"}
	data.forms["pres_indc_2du"] = {args[1] .. (args["j"] and "j" or "") .. "ats"}
	data.forms["pres_indc_1pl"] = {args[1] .. (args["j"] and "j" or "") .. "am"}
	data.forms["pres_indc_2pl"] = {args[1] .. (args["j"] or "i") .. "þ"}
	data.forms["pres_indc_3pl"] = {args[1] .. (args["j"] and "j" or "") .. "and"}
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {args[1] .. (args["j"] and "j" or "") .. "au"}
	data.forms["pres_subj_2sg"] = {args[1] .. (args["j"] and "j" or "") .. "ais"}
	data.forms["pres_subj_3sg"] = {args[1] .. (args["j"] and "j" or "") .. "ai"}
	data.forms["pres_subj_1du"] = {args[1] .. (args["j"] and "j" or "") .. "aiwa"}
	data.forms["pres_subj_2du"] = {args[1] .. (args["j"] and "j" or "") .. "aits"}
	data.forms["pres_subj_1pl"] = {args[1] .. (args["j"] and "j" or "") .. "aima"}
	data.forms["pres_subj_2pl"] = {args[1] .. (args["j"] and "j" or "") .. "aiþ"}
	data.forms["pres_subj_3pl"] = {args[1] .. (args["j"] and "j" or "") .. "aina"}
	
	-- Imperative
	data.forms["impr_2sg"] = {args["imp2sg"] or args[1] .. (args["j"] and "ei" or "")}
	data.forms["impr_3sg"] = {args[1] .. (args["j"] and "j" or "") .. "adau"}
	data.forms["impr_2du"] = {args[1] .. (args["j"] and "j" or "") .. "ats"}
	data.forms["impr_2pl"] = {args[1] .. (args["j"] or "i") .. "þ"}
	data.forms["impr_3pl"] = {args[1] .. (args["j"] and "j" or "") .. "andau"}
	
	-- Passive indicative
	data.forms["pasv_indc_1sg"] = {args[1] .. (args["j"] and "j" or "") .. "ada"}
	data.forms["pasv_indc_2sg"] = {args[1] .. (args["j"] and "j" or "") .. "aza"}
	data.forms["pasv_indc_3sg"] = {args[1] .. (args["j"] and "j" or "") .. "ada"}
	data.forms["pasv_indc_1pl"] = {args[1] .. (args["j"] and "j" or "") .. "anda"}
	data.forms["pasv_indc_2pl"] = {args[1] .. (args["j"] and "j" or "") .. "anda"}
	data.forms["pasv_indc_3pl"] = {args[1] .. (args["j"] and "j" or "") .. "anda"}
	
	-- Passive subjunctive
	data.forms["pasv_subj_1sg"] = {args[1] .. (args["j"] and "j" or "") .. "aidau"}
	data.forms["pasv_subj_2sg"] = {args[1] .. (args["j"] and "j" or "") .. "aizau"}
	data.forms["pasv_subj_3sg"] = {args[1] .. (args["j"] and "j" or "") .. "aidau"}
	data.forms["pasv_subj_1pl"] = {args[1] .. (args["j"] and "j" or "") .. "aindau"}
	data.forms["pasv_subj_2pl"] = {args[1] .. (args["j"] and "j" or "") .. "aindau"}
	data.forms["pasv_subj_3pl"] = {args[1] .. (args["j"] and "j" or "") .. "aindau"}
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {args[2]}
	data.forms["past_indc_2sg"] = {args["past2sg"] or args[2] .. "t"}
	data.forms["past_indc_3sg"] = {args[2]}
	data.forms["past_indc_1du"] = {args[3] .. "u"}
	data.forms["past_indc_2du"] = {args[3] .. "uts"}
	data.forms["past_indc_1pl"] = {args[3] .. "um"}
	data.forms["past_indc_2pl"] = {args[3] .. "uþ"}
	data.forms["past_indc_3pl"] = {args[3] .. "un"}
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {args[3] .. "jau"}
	data.forms["past_subj_2sg"] = {args[3] .. "eis"}
	data.forms["past_subj_3sg"] = {args[3] .. "i"}
	data.forms["past_subj_1du"] = {args[3] .. "eiwa"}
	data.forms["past_subj_2du"] = {args[3] .. "eits"}
	data.forms["past_subj_1pl"] = {args[3] .. "eima"}
	data.forms["past_subj_2pl"] = {args[3] .. "eiþ"}
	data.forms["past_subj_3pl"] = {args[3] .. "eina"}
	
	-- Non-finite forms
	data.forms["inf"]       = {args[1] .. (args["j"] and "j" or "") .. "an"}
	data.forms["pres_ptcp"] = {args[1] .. (args["j"] and "j" or "") .. "ands"}
	data.forms["past_ptcp"] = {args[4] .. "ans"}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


export["wk1"] = function(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		[2] = {},
		
		["j"] = {required = true, default = "ji"},
		["nopasv"] = {type = "boolean"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	make_Latn(args, {1, 2})
	
	if not (args["j"] == "ji" or args["j"] == "ei") then
		error("Invalid value for parameter j=, must be \"ji\" or \"ei\".")
	end
	
	local data = {forms = {}, info = "1類弱變化", categories = {lang:getCanonicalName() .. "1類弱變化動詞"}}
	
	-- Present indicative
	data.forms["pres_indc_1sg"] = {args[1] .. "ja"}
	data.forms["pres_indc_2sg"] = {args[1] .. args["j"] .. "s"}
	data.forms["pres_indc_3sg"] = {args[1] .. args["j"] .. "þ"}
	data.forms["pres_indc_1du"] = {args[1] .. "jōs"}
	data.forms["pres_indc_2du"] = {args[1] .. "jats"}
	data.forms["pres_indc_1pl"] = {args[1] .. "jam"}
	data.forms["pres_indc_2pl"] = {args[1] .. args["j"] .. "þ"}
	data.forms["pres_indc_3pl"] = {args[1] .. "jand"}
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {args[1] .. "jau"}
	data.forms["pres_subj_2sg"] = {args[1] .. "jais"}
	data.forms["pres_subj_3sg"] = {args[1] .. "jai"}
	data.forms["pres_subj_1du"] = {args[1] .. "jaiwa"}
	data.forms["pres_subj_2du"] = {args[1] .. "jaits"}
	data.forms["pres_subj_1pl"] = {args[1] .. "jaima"}
	data.forms["pres_subj_2pl"] = {args[1] .. "jaiþ"}
	data.forms["pres_subj_3pl"] = {args[1] .. "jaina"}
	
	-- Imperative
	data.forms["impr_2sg"] = {(args[2] or args[1]) .. "ei"}
	data.forms["impr_3sg"] = {args[1] .. "jadau"}
	data.forms["impr_2du"] = {args[1] .. "jats"}
	data.forms["impr_2pl"] = {args[1] .. args["j"] .. "þ"}
	data.forms["impr_3pl"] = {args[1] .. "jandau"}
	
	-- Passive indicative
	data.forms["pasv_indc_1sg"] = {args[1] .. "jada"}
	data.forms["pasv_indc_2sg"] = {args[1] .. "jaza"}
	data.forms["pasv_indc_3sg"] = {args[1] .. "jada"}
	data.forms["pasv_indc_1pl"] = {args[1] .. "janda"}
	data.forms["pasv_indc_2pl"] = {args[1] .. "janda"}
	data.forms["pasv_indc_3pl"] = {args[1] .. "janda"}
	
	-- Passive subjunctive
	data.forms["pasv_subj_1sg"] = {args[1] .. "jaidau"}
	data.forms["pasv_subj_2sg"] = {args[1] .. "jaizau"}
	data.forms["pasv_subj_3sg"] = {args[1] .. "jaidau"}
	data.forms["pasv_subj_1pl"] = {args[1] .. "jaindau"}
	data.forms["pasv_subj_2pl"] = {args[1] .. "jaindau"}
	data.forms["pasv_subj_3pl"] = {args[1] .. "jaindau"}
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {(args[2] or args[1]) .. "ida"}
	data.forms["past_indc_2sg"] = {(args[2] or args[1]) .. "idēs"}
	data.forms["past_indc_3sg"] = {(args[2] or args[1]) .. "ida"}
	data.forms["past_indc_1du"] = {(args[2] or args[1]) .. "idēdu"}
	data.forms["past_indc_2du"] = {(args[2] or args[1]) .. "idēduts"}
	data.forms["past_indc_1pl"] = {(args[2] or args[1]) .. "idēdum"}
	data.forms["past_indc_2pl"] = {(args[2] or args[1]) .. "idēduþ"}
	data.forms["past_indc_3pl"] = {(args[2] or args[1]) .. "idēdun"}
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {(args[2] or args[1]) .. "idēdjau"}
	data.forms["past_subj_2sg"] = {(args[2] or args[1]) .. "idēdeis"}
	data.forms["past_subj_3sg"] = {(args[2] or args[1]) .. "idēdi"}
	data.forms["past_subj_1du"] = {(args[2] or args[1]) .. "idēdeiwa"}
	data.forms["past_subj_2du"] = {(args[2] or args[1]) .. "idēdeits"}
	data.forms["past_subj_1pl"] = {(args[2] or args[1]) .. "idēdeima"}
	data.forms["past_subj_2pl"] = {(args[2] or args[1]) .. "idēdeiþ"}
	data.forms["past_subj_3pl"] = {(args[2] or args[1]) .. "idēdeina"}
	
	-- Non-finite forms
	data.forms["inf"]       = {args[1] .. "jan"}
	data.forms["pres_ptcp"] = {args[1] .. "jands"}
	data.forms["past_ptcp"] = {(args[2] or args[1]) .. "iþs"}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


export["wk1ir"] = function(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		[2] = {required = true, default = "{{{2}}}"},
		
		["j"] = {required = true, default = "ji"},
		["nopasv"] = {type = "boolean"},
        ["pastpart"] = {}
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	make_Latn(args, {1, 2})
	
	if not (args["j"] == "ji" or args["j"] == "ei") then
		error("Invalid value for parameter j=, must be \"ji\" or \"ei\".")
	end
	
	local data = {forms = {}, info = "1類弱變化不規則", categories = {lang:getCanonicalName() .. "1類弱變化不規則動詞"}}
	
	-- Present indicative
	data.forms["pres_indc_1sg"] = {args[1] .. "ja"}
	data.forms["pres_indc_2sg"] = {args[1] .. args["j"] .. "s"}
	data.forms["pres_indc_3sg"] = {args[1] .. args["j"] .. "þ"}
	data.forms["pres_indc_1du"] = {args[1] .. "jōs"}
	data.forms["pres_indc_2du"] = {args[1] .. "jats"}
	data.forms["pres_indc_1pl"] = {args[1] .. "jam"}
	data.forms["pres_indc_2pl"] = {args[1] .. args["j"] .. "þ"}
	data.forms["pres_indc_3pl"] = {args[1] .. "jand"}
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {args[1] .. "jau"}
	data.forms["pres_subj_2sg"] = {args[1] .. "jais"}
	data.forms["pres_subj_3sg"] = {args[1] .. "jai"}
	data.forms["pres_subj_1du"] = {args[1] .. "jaiwa"}
	data.forms["pres_subj_2du"] = {args[1] .. "jaits"}
	data.forms["pres_subj_1pl"] = {args[1] .. "jaima"}
	data.forms["pres_subj_2pl"] = {args[1] .. "jaiþ"}
	data.forms["pres_subj_3pl"] = {args[1] .. "jaina"}
	
	-- Imperative
	data.forms["impr_2sg"] = {args[1] .. "ei"}
	data.forms["impr_3sg"] = {args[1] .. "jadau"}
	data.forms["impr_2du"] = {args[1] .. "jats"}
	data.forms["impr_2pl"] = {args[1] .. args["j"] .. "þ"}
	data.forms["impr_3pl"] = {args[1] .. "jandau"}
	
	-- Passive indicative
	data.forms["pasv_indc_1sg"] = {args[1] .. "jada"}
	data.forms["pasv_indc_2sg"] = {args[1] .. "jaza"}
	data.forms["pasv_indc_3sg"] = {args[1] .. "jada"}
	data.forms["pasv_indc_1pl"] = {args[1] .. "janda"}
	data.forms["pasv_indc_2pl"] = {args[1] .. "janda"}
	data.forms["pasv_indc_3pl"] = {args[1] .. "janda"}
	
	-- Passive subjunctive
	data.forms["pasv_subj_1sg"] = {args[1] .. "jaidau"}
	data.forms["pasv_subj_2sg"] = {args[1] .. "jaizau"}
	data.forms["pasv_subj_3sg"] = {args[1] .. "jaidau"}
	data.forms["pasv_subj_1pl"] = {args[1] .. "jaindau"}
	data.forms["pasv_subj_2pl"] = {args[1] .. "jaindau"}
	data.forms["pasv_subj_3pl"] = {args[1] .. "jaindau"}
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {args[2] .. "a"}
	data.forms["past_indc_2sg"] = {args[2] .. "ēs"}
	data.forms["past_indc_3sg"] = {args[2] .. "a"}
	data.forms["past_indc_1du"] = {args[2] .. "ēdu"}
	data.forms["past_indc_2du"] = {args[2] .. "ēduts"}
	data.forms["past_indc_1pl"] = {args[2] .. "ēdum"}
	data.forms["past_indc_2pl"] = {args[2] .. "ēduþ"}
	data.forms["past_indc_3pl"] = {args[2] .. "ēdun"}	
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {args[2] .. "ēdjau"}
	data.forms["past_subj_2sg"] = {args[2] .. "ēdeis"}
	data.forms["past_subj_3sg"] = {args[2] .. "ēdi"}
	data.forms["past_subj_1du"] = {args[2] .. "ēdeiwa"}
	data.forms["past_subj_2du"] = {args[2] .. "ēdeits"}
	data.forms["past_subj_1pl"] = {args[2] .. "ēdeima"}
	data.forms["past_subj_2pl"] = {args[2] .. "ēdeiþ"}
	data.forms["past_subj_3pl"] = {args[2] .. "ēdeina"}
	-- Non-finite forms
	data.forms["inf"]       = {args[1] .. "jan"}
	data.forms["pres_ptcp"] = {args[1] .. "jands"}
	data.forms["past_ptcp"] = {args["pastpart"] or args[2] .. "s"}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


export["wk2"] = function(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		
		["nopasv"] = {type = "boolean"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	make_Latn(args, {1})
	
	local data = {forms = {}, info = "2類弱變化", categories = {lang:getCanonicalName() .. "2類弱變化動詞"}}
	
	-- Present indicative
	data.forms["pres_indc_1sg"] = {args[1] .. "ō"}
	data.forms["pres_indc_2sg"] = {args[1] .. "ōs"}
	data.forms["pres_indc_3sg"] = {args[1] .. "ōþ"}
	data.forms["pres_indc_1du"] = {args[1] .. "ōs"}
	data.forms["pres_indc_2du"] = {args[1] .. "ōts"}
	data.forms["pres_indc_1pl"] = {args[1] .. "ōm"}
	data.forms["pres_indc_2pl"] = {args[1] .. "ōþ"}
	data.forms["pres_indc_3pl"] = {args[1] .. "ōnd"}
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {args[1] .. "ō"}
	data.forms["pres_subj_2sg"] = {args[1] .. "ōs"}
	data.forms["pres_subj_3sg"] = {args[1] .. "ō"}
	data.forms["pres_subj_1du"] = {args[1] .. "ōwa"}
	data.forms["pres_subj_2du"] = {args[1] .. "ōts"}
	data.forms["pres_subj_1pl"] = {args[1] .. "ōma"}
	data.forms["pres_subj_2pl"] = {args[1] .. "ōþ"}
	data.forms["pres_subj_3pl"] = {args[1] .. "ōna"}
	
	-- Imperative
	data.forms["impr_2sg"] = {args[1] .. "ō"}
	data.forms["impr_3sg"] = {args[1] .. "ōdau"}
	data.forms["impr_2du"] = {args[1] .. "ōts"}
	data.forms["impr_2pl"] = {args[1] .. "ōþ"}
	data.forms["impr_3pl"] = {args[1] .. "ōndau"}
	
	-- Passive indicative
	data.forms["pasv_indc_1sg"] = {args[1] .. "ōda"}
	data.forms["pasv_indc_2sg"] = {args[1] .. "ōza"}
	data.forms["pasv_indc_3sg"] = {args[1] .. "ōda"}
	data.forms["pasv_indc_1pl"] = {args[1] .. "ōnda"}
	data.forms["pasv_indc_2pl"] = {args[1] .. "ōnda"}
	data.forms["pasv_indc_3pl"] = {args[1] .. "ōnda"}
	
	-- Passive subjunctive
	data.forms["pasv_subj_1sg"] = {args[1] .. "ōdau"}
	data.forms["pasv_subj_2sg"] = {args[1] .. "ōzau"}
	data.forms["pasv_subj_3sg"] = {args[1] .. "ōdau"}
	data.forms["pasv_subj_1pl"] = {args[1] .. "ōndau"}
	data.forms["pasv_subj_2pl"] = {args[1] .. "ōndau"}
	data.forms["pasv_subj_3pl"] = {args[1] .. "ōndau"}
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {args[1] .. "ōda"}
	data.forms["past_indc_2sg"] = {args[1] .. "ōdēs"}
	data.forms["past_indc_3sg"] = {args[1] .. "ōda"}
	data.forms["past_indc_1du"] = {args[1] .. "ōdēdu"}
	data.forms["past_indc_2du"] = {args[1] .. "ōdēduts"}
	data.forms["past_indc_1pl"] = {args[1] .. "ōdēdum"}
	data.forms["past_indc_2pl"] = {args[1] .. "ōdēduþ"}
	data.forms["past_indc_3pl"] = {args[1] .. "ōdēdun"}
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {args[1] .. "ōdēdjau"}
	data.forms["past_subj_2sg"] = {args[1] .. "ōdēdeis"}
	data.forms["past_subj_3sg"] = {args[1] .. "ōdēdi"}
	data.forms["past_subj_1du"] = {args[1] .. "ōdēdeiwa"}
	data.forms["past_subj_2du"] = {args[1] .. "ōdēdeits"}
	data.forms["past_subj_1pl"] = {args[1] .. "ōdēdeima"}
	data.forms["past_subj_2pl"] = {args[1] .. "ōdēdeiþ"}
	data.forms["past_subj_3pl"] = {args[1] .. "ōdēdeina"}
	
	-- Non-finite forms
	data.forms["inf"]       = {args[1] .. "ōn"}
	data.forms["pres_ptcp"] = {args[1] .. "ōnds"}
	data.forms["past_ptcp"] = {args[1] .. "ōþs"}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


export["wk3"] = function(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		
		["nopasv"] = {type = "boolean"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	make_Latn(args, {1})
	
	local data = {forms = {}, info = "3類弱變化", categories = {lang:getCanonicalName() .. "3類弱變化動詞"}}
	
	-- Present indicative
	data.forms["pres_indc_1sg"] = {args[1] .. "a"}
	data.forms["pres_indc_2sg"] = {args[1] .. "ais"}
	data.forms["pres_indc_3sg"] = {args[1] .. "aiþ"}
	data.forms["pres_indc_1du"] = {args[1] .. "ōs"}
	data.forms["pres_indc_2du"] = {args[1] .. "āts"}
	data.forms["pres_indc_1pl"] = {args[1] .. "ām"}
	data.forms["pres_indc_2pl"] = {args[1] .. "aiþ"}
	data.forms["pres_indc_3pl"] = {args[1] .. "ānd"}
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {args[1] .. "au"}
	data.forms["pres_subj_2sg"] = {args[1] .. "ais"}
	data.forms["pres_subj_3sg"] = {args[1] .. "ai"}
	data.forms["pres_subj_1du"] = {args[1] .. "aiwa"}
	data.forms["pres_subj_2du"] = {args[1] .. "aits"}
	data.forms["pres_subj_1pl"] = {args[1] .. "aima"}
	data.forms["pres_subj_2pl"] = {args[1] .. "aiþ"}
	data.forms["pres_subj_3pl"] = {args[1] .. "aina"}
	
	-- Imperative
	data.forms["impr_2sg"] = {args[1] .. "ai"}
	data.forms["impr_3sg"] = {args[1] .. "ādau"}
	data.forms["impr_2du"] = {args[1] .. "āts"}
	data.forms["impr_2pl"] = {args[1] .. "aiþ"}
	data.forms["impr_3pl"] = {args[1] .. "āndau"}
	
	-- Passive indicative
	data.forms["pasv_indc_1sg"] = {args[1] .. "āda"}
	data.forms["pasv_indc_2sg"] = {args[1] .. "āza"}
	data.forms["pasv_indc_3sg"] = {args[1] .. "āda"}
	data.forms["pasv_indc_1pl"] = {args[1] .. "ānda"}
	data.forms["pasv_indc_2pl"] = {args[1] .. "ānda"}
	data.forms["pasv_indc_3pl"] = {args[1] .. "ānda"}
	
	-- Passive subjunctive
	data.forms["pasv_subj_1sg"] = {args[1] .. "aidau"}
	data.forms["pasv_subj_2sg"] = {args[1] .. "aizau"}
	data.forms["pasv_subj_3sg"] = {args[1] .. "aidau"}
	data.forms["pasv_subj_1pl"] = {args[1] .. "aindau"}
	data.forms["pasv_subj_2pl"] = {args[1] .. "aindau"}
	data.forms["pasv_subj_3pl"] = {args[1] .. "aindau"}
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {args[1] .. "aida"}
	data.forms["past_indc_2sg"] = {args[1] .. "aidēs"}
	data.forms["past_indc_3sg"] = {args[1] .. "aida"}
	data.forms["past_indc_1du"] = {args[1] .. "aidēdu"}
	data.forms["past_indc_2du"] = {args[1] .. "aidēduts"}
	data.forms["past_indc_1pl"] = {args[1] .. "aidēdum"}
	data.forms["past_indc_2pl"] = {args[1] .. "aidēduþ"}
	data.forms["past_indc_3pl"] = {args[1] .. "aidēdun"}
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {args[1] .. "aidēdjau"}
	data.forms["past_subj_2sg"] = {args[1] .. "aidēdeis"}
	data.forms["past_subj_3sg"] = {args[1] .. "aidēdi"}
	data.forms["past_subj_1du"] = {args[1] .. "aidēdeiwa"}
	data.forms["past_subj_2du"] = {args[1] .. "aidēdeits"}
	data.forms["past_subj_1pl"] = {args[1] .. "aidēdeima"}
	data.forms["past_subj_2pl"] = {args[1] .. "aidēdeiþ"}
	data.forms["past_subj_3pl"] = {args[1] .. "aidēdeina"}
	
	-- Non-finite forms
	data.forms["inf"]       = {args[1] .. "ān"}
	data.forms["pres_ptcp"] = {args[1] .. "ānds"}
	data.forms["past_ptcp"] = {args[1] .. "aiþs"}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


export["wk4"] = function(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		
		["nopasv"] = {type = "boolean"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	make_Latn(args, {1})
	
	local data = {forms = {}, info = "4類弱變化", categories = {lang:getCanonicalName() .. "4類弱變化動詞"}}
	
	-- Present indicative
	data.forms["pres_indc_1sg"] = {args[1] .. "na"}
	data.forms["pres_indc_2sg"] = {args[1] .. "nis"}
	data.forms["pres_indc_3sg"] = {args[1] .. "niþ"}
	data.forms["pres_indc_1du"] = {args[1] .. "nōs"}
	data.forms["pres_indc_2du"] = {args[1] .. "nats"}
	data.forms["pres_indc_1pl"] = {args[1] .. "nam"}
	data.forms["pres_indc_2pl"] = {args[1] .. "niþ"}
	data.forms["pres_indc_3pl"] = {args[1] .. "nand"}
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {args[1] .. "nau"}
	data.forms["pres_subj_2sg"] = {args[1] .. "nais"}
	data.forms["pres_subj_3sg"] = {args[1] .. "nai"}
	data.forms["pres_subj_1du"] = {args[1] .. "naiwa"}
	data.forms["pres_subj_2du"] = {args[1] .. "naits"}
	data.forms["pres_subj_1pl"] = {args[1] .. "naima"}
	data.forms["pres_subj_2pl"] = {args[1] .. "naiþ"}
	data.forms["pres_subj_3pl"] = {args[1] .. "naina"}
	
	-- Imperative
	data.forms["impr_2sg"] = {args[1] .. "n"}
	data.forms["impr_3sg"] = {args[1] .. "nadau"}
	data.forms["impr_2du"] = {args[1] .. "nats"}
	data.forms["impr_2pl"] = {args[1] .. "niþ"}
	data.forms["impr_3pl"] = {args[1] .. "nandau"}
	
	-- Passive indicative
	-- No forms
	
	-- Passive subjunctive
	-- No forms
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {args[1] .. "nōda"}
	data.forms["past_indc_2sg"] = {args[1] .. "nōdēs"}
	data.forms["past_indc_3sg"] = {args[1] .. "nōda"}
	data.forms["past_indc_1du"] = {args[1] .. "nōdēdu"}
	data.forms["past_indc_2du"] = {args[1] .. "nōdēduts"}
	data.forms["past_indc_1pl"] = {args[1] .. "nōdēdum"}
	data.forms["past_indc_2pl"] = {args[1] .. "nōdēduþ"}
	data.forms["past_indc_3pl"] = {args[1] .. "nōdēdun"}
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {args[1] .. "nōdēdjau"}
	data.forms["past_subj_2sg"] = {args[1] .. "nōdēdeis"}
	data.forms["past_subj_3sg"] = {args[1] .. "nōdēdi"}
	data.forms["past_subj_1du"] = {args[1] .. "nōdēdeiwa"}
	data.forms["past_subj_2du"] = {args[1] .. "nōdēdeits"}
	data.forms["past_subj_1pl"] = {args[1] .. "nōdēdeima"}
	data.forms["past_subj_2pl"] = {args[1] .. "nōdēdeiþ"}
	data.forms["past_subj_3pl"] = {args[1] .. "nōdēdeina"}
	
	-- Non-finite forms
	data.forms["inf"]       = {args[1] .. "nan"}
	data.forms["pres_ptcp"] = {args[1] .. "nands"}
	data.forms["past_ptcp"] = nil
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


export["pp"] = function(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		[2] = {required = true, default = "{{{2}}}"},
		[3] = {required = true, default = "{{{3}}}"},
		["pres2sg"] = {},
		["imp2sg"] = {},
		["pastpart"] = {},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	make_Latn(args, {1, 2, 3, "pres2sg", "imp2sg", "pastpart"})
	
	local data = {forms = {}, info = "過去時-現在時", categories = {lang:getCanonicalName() .. "過去時-現在時動詞"}}
	
	-- Present indicative
	data.forms["pres_indc_1sg"] = {args[2]}
	data.forms["pres_indc_2sg"] = {args["pres2sg"] or args[2] .. "t"}
	data.forms["pres_indc_3sg"] = {args[2]}
	data.forms["pres_indc_1du"] = {args[1] .. "u"}
	data.forms["pres_indc_2du"] = {args[1] .. "uts"}
	data.forms["pres_indc_1pl"] = {args[1] .. "um"}
	data.forms["pres_indc_2pl"] = {args[1] .. "uþ"}
	data.forms["pres_indc_3pl"] = {args[1] .. "un"}
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {args[1] .. "jau"}
	data.forms["pres_subj_2sg"] = {args[1] .. "eis"}
	data.forms["pres_subj_3sg"] = {args[1] .. "i"}
	data.forms["pres_subj_1du"] = {args[1] .. "eiwa"}
	data.forms["pres_subj_2du"] = {args[1] .. "eits"}
	data.forms["pres_subj_1pl"] = {args[1] .. "eima"}
	data.forms["pres_subj_2pl"] = {args[1] .. "eiþ"}
	data.forms["pres_subj_3pl"] = {args[1] .. "eina"}
	
	-- Imperative
	-- No forms (except at ōgan)
	data.forms["impr_2sg"] = {args["imp2sg"] or nil}
	
	-- Passive indicative
	-- No forms
	
	-- Passive subjunctive
	-- No forms
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {args[3] .. "a"}
	data.forms["past_indc_2sg"] = {args[3] .. "ēs"}
	data.forms["past_indc_3sg"] = {args[3] .. "a"}
	data.forms["past_indc_1du"] = {args[3] .. "ēdu"}
	data.forms["past_indc_2du"] = {args[3] .. "ēduts"}
	data.forms["past_indc_1pl"] = {args[3] .. "ēdum"}
	data.forms["past_indc_2pl"] = {args[3] .. "ēduþ"}
	data.forms["past_indc_3pl"] = {args[3] .. "ēdun"}
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {args[3] .. "ēdjau"}
	data.forms["past_subj_2sg"] = {args[3] .. "ēdeis"}
	data.forms["past_subj_3sg"] = {args[3] .. "ēdi"}
	data.forms["past_subj_1du"] = {args[3] .. "ēdeiwa"}
	data.forms["past_subj_2du"] = {args[3] .. "ēdeits"}
	data.forms["past_subj_1pl"] = {args[3] .. "ēdeima"}
	data.forms["past_subj_2pl"] = {args[3] .. "ēdeiþ"}
	data.forms["past_subj_3pl"] = {args[3] .. "ēdeina"}
	
	-- Non-finite forms
	data.forms["inf"]       = {args[1] .. "an"}
	data.forms["pres_ptcp"] = {args[1] .. "ands"}
	data.forms["past_ptcp"] = {args["pastpart"] or args[3] .. "s"}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


-- Irregular verbs


export["ufkunnan"] = function(frame)
	local params = {
		["pres2sg"] = {},
		["imp2sg"] = {},
		["pastpart"] = {},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	make_Latn(args, {1, 2, 3, "pres2sg", "imp2sg", "pastpart"})
	
	local data = {forms = {}, info = "不規則,混合3類弱變化和過去時-現在時", 	categories = {lang:getCanonicalName() .. "3類弱變化動詞", lang:getCanonicalName() .. "不規則動詞", lang:getCanonicalName() .. "過去時-現在時動詞"}
		}
	
	-- Present indicative
	data.forms["pres_indc_1sg"] = {"ufkunna"}
	data.forms["pres_indc_2sg"] = {"ufkunnais"}
	data.forms["pres_indc_3sg"] = {"ufkunnaiþ"}
	data.forms["pres_indc_1du"] = {"ufkunnōs"}
	data.forms["pres_indc_2du"] = {"ufkunnāts"}
	data.forms["pres_indc_1pl"] = {"ufkunnaim"}
	data.forms["pres_indc_2pl"] = {"ufkunnaiþ"}
	data.forms["pres_indc_3pl"] = {"ufkunnānd"}
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {"ufkunnau"}
	data.forms["pres_subj_2sg"] = {"ufkunnais"}
	data.forms["pres_subj_3sg"] = {"ufkunnai"}
	data.forms["pres_subj_1du"] = {"ufkunnaiwa"}
	data.forms["pres_subj_2du"] = {"ufkunnaits"}
	data.forms["pres_subj_1pl"] = {"ufkunnaima"}
	data.forms["pres_subj_2pl"] = {"ufkunnaiþ"}
	data.forms["pres_subj_3pl"] = {"ufkunnaina"}
	
	-- Imperative
	data.forms["impr_2sg"] = {"ufkunnai"}
	data.forms["impr_3sg"] = {"ufkunnādau"}
	data.forms["impr_2du"] = {"ufkunnāts"}
	data.forms["impr_2pl"] = {"ufkunnaiþ"}
	data.forms["impr_3pl"] = {"ufkunnāndau"}
	
	-- Passive indicative
	data.forms["pasv_indc_1sg"] = {"ufkunnāda"}
	data.forms["pasv_indc_2sg"] = {"ufkunnāza"}
	data.forms["pasv_indc_3sg"] = {"ufkunnāda"}
	data.forms["pasv_indc_1pl"] = {"ufkunnānda"}
	data.forms["pasv_indc_2pl"] = {"ufkunnānda"}
	data.forms["pasv_indc_3pl"] = {"ufkunnānda"}
	
	-- Passive subjunctive
	data.forms["pasv_subj_1sg"] = {"ufkunnaidau"}
	data.forms["pasv_subj_2sg"] = {"ufkunnaizau"}
	data.forms["pasv_subj_3sg"] = {"ufkunnaidau"}
	data.forms["pasv_subj_1pl"] = {"ufkunnaindau"}
	data.forms["pasv_subj_2pl"] = {"ufkunnaindau"}
	data.forms["pasv_subj_3pl"] = {"ufkunnaindau"}
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {"ufkunþa", "ufkunnaida"}
	data.forms["past_indc_2sg"] = {"ufkunþēs"}
	data.forms["past_indc_3sg"] = {"ufkunþa", "ufkunnaida"}
	data.forms["past_indc_1du"] = {"ufkunþēdu"}
	data.forms["past_indc_2du"] = {"ufkunþēduts"}
	data.forms["past_indc_1pl"] = {"ufkunþēdum"}
	data.forms["past_indc_2pl"] = {"ufkunþēduþ"}
	data.forms["past_indc_3pl"] = {"ufkunþēdun"}
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {"ufkunþēdjau"}
	data.forms["past_subj_2sg"] = {"ufkunþēdeis"}
	data.forms["past_subj_3sg"] = {"ufkunþēdi"}
	data.forms["past_subj_1du"] = {"ufkunþēdeiwa"}
	data.forms["past_subj_2du"] = {"ufkunþēdeits"}
	data.forms["past_subj_1pl"] = {"ufkunþēdeima"}
	data.forms["past_subj_2pl"] = {"ufkunþēdeiþ"}
	data.forms["past_subj_3pl"] = {"ufkunþēdeina"}
	
	-- Non-finite forms
	data.forms["inf"]       = {"ufkunnān"}
	data.forms["pres_ptcp"] = {"ufkunnānds"}
	data.forms["past_ptcp"] = {"ufkunnaiþs"}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


export["wiljan"] = function(frame)
	local params = {
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {
		forms = {}, info = "弱變化,不規則,無現在時直陳式",
		categories = {lang:getCanonicalName() .. "弱變化動詞", lang:getCanonicalName() .. "不規則動詞", lang:getCanonicalName() .. "不完全變化動詞"}
		}
	
	-- Present indicative
	-- No forms
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {"wiljau"}
	data.forms["pres_subj_2sg"] = {"wileis"}
	data.forms["pres_subj_3sg"] = {"wili"}
	data.forms["pres_subj_1du"] = {"wileiwa"}
	data.forms["pres_subj_2du"] = {"wileits"}
	data.forms["pres_subj_1pl"] = {"wileima"}
	data.forms["pres_subj_2pl"] = {"wileiþ"}
	data.forms["pres_subj_3pl"] = {"wileina"}
	
	-- Imperative
	-- No forms
	
	-- Passive indicative
	-- No forms
	
	-- Passive subjunctive
	-- No forms
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {"wilda"}
	data.forms["past_indc_2sg"] = {"wildēs"}
	data.forms["past_indc_3sg"] = {"wilda"}
	data.forms["past_indc_1du"] = {"wildēdu"}
	data.forms["past_indc_2du"] = {"wildēduts"}
	data.forms["past_indc_1pl"] = {"wildēdum"}
	data.forms["past_indc_2pl"] = {"wildēduþ"}
	data.forms["past_indc_3pl"] = {"wildēdun"}
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {"wildēdjau"}
	data.forms["past_subj_2sg"] = {"wildēdeis"}
	data.forms["past_subj_3sg"] = {"wildēdi"}
	data.forms["past_subj_1du"] = {"wildēdeiwa"}
	data.forms["past_subj_2du"] = {"wildēdeits"}
	data.forms["past_subj_1pl"] = {"wildēdeima"}
	data.forms["past_subj_2pl"] = {"wildēdeiþ"}
	data.forms["past_subj_3pl"] = {"wildēdeina"}
	
	-- Non-finite forms
	data.forms["inf"]       = {"wiljan"}
	data.forms["pres_ptcp"] = {"wiljands"}
	data.forms["past_ptcp"] = nil
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


export["wisan"] = function(frame)
	local params = {
		["prefix"] = {default = ""},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	make_Latn(args, {"prefix"})
	
	local data = {
		forms = {}, info = "5類強變化,不規則,異幹",
		categories = {lang:getCanonicalName() .. "5類強變化動詞", lang:getCanonicalName() .. "不規則動詞", lang:getCanonicalName() .. "異幹動詞"}
		}
	
	-- Present indicative
	data.forms["pres_indc_1sg"] = {args["prefix"] .. "im"}
	data.forms["pres_indc_2sg"] = {args["prefix"] .. "is"}
	data.forms["pres_indc_3sg"] = {args["prefix"] .. "ist"}
	data.forms["pres_indc_1du"] = {args["prefix"] .. "siju"}
	data.forms["pres_indc_2du"] = {args["prefix"] .. "sijuts"}
	data.forms["pres_indc_1pl"] = {args["prefix"] .. "sijum"}
	data.forms["pres_indc_2pl"] = {args["prefix"] .. "sijuþ"}
	data.forms["pres_indc_3pl"] = {args["prefix"] .. "sind"}
	
	-- Present subjunctive
	data.forms["pres_subj_1sg"] = {args["prefix"] .. "sijau"}
	data.forms["pres_subj_2sg"] = {args["prefix"] .. "sijais"}
	data.forms["pres_subj_3sg"] = {args["prefix"] .. "sijai"}
	data.forms["pres_subj_1du"] = {args["prefix"] .. "sijaiwa"}
	data.forms["pres_subj_2du"] = {args["prefix"] .. "sijaits"}
	data.forms["pres_subj_1pl"] = {args["prefix"] .. "sijaima"}
	data.forms["pres_subj_2pl"] = {args["prefix"] .. "sijaiþ"}
	data.forms["pres_subj_3pl"] = {args["prefix"] .. "sijaina"}
	
	-- Imperative
	-- No forms
	
	-- Passive indicative
	-- No forms
	
	-- Passive subjunctive
	-- No forms
	
	-- Past indicative
	data.forms["past_indc_1sg"] = {args["prefix"] .. "was"}
	data.forms["past_indc_2sg"] = {args["prefix"] .. "wast"}
	data.forms["past_indc_3sg"] = {args["prefix"] .. "was"}
	data.forms["past_indc_1du"] = {args["prefix"] .. "wēsu"}
	data.forms["past_indc_2du"] = {args["prefix"] .. "wēsuts"}
	data.forms["past_indc_1pl"] = {args["prefix"] .. "wēsum"}
	data.forms["past_indc_2pl"] = {args["prefix"] .. "wēsuþ"}
	data.forms["past_indc_3pl"] = {args["prefix"] .. "wēsun"}
	
	-- Past subjunctive
	data.forms["past_subj_1sg"] = {args["prefix"] .. "wēsjau"}
	data.forms["past_subj_2sg"] = {args["prefix"] .. "wēseis"}
	data.forms["past_subj_3sg"] = {args["prefix"] .. "wēsi"}
	data.forms["past_subj_1du"] = {args["prefix"] .. "wēseiwa"}
	data.forms["past_subj_2du"] = {args["prefix"] .. "wēseits"}
	data.forms["past_subj_1pl"] = {args["prefix"] .. "wēseima"}
	data.forms["past_subj_2pl"] = {args["prefix"] .. "wēseiþ"}
	data.forms["past_subj_3pl"] = {args["prefix"] .. "wēseina"}
	
	-- Non-finite forms
	data.forms["inf"]       = {args["prefix"] .. "wisan"}
	data.forms["pres_ptcp"] = {args["prefix"] .. "wisands"}
	data.forms["past_ptcp"] = {args["prefix"] .. "wisans"}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end

export["briggan"] = function(frame)
	local params = {
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)

	local data = {
		forms = {}, info = "3類強變化",
		categories = {lang:getCanonicalName() .. "3類強變化動詞"}
		}
	
    -- Present indicative
    data.forms["pres_indc_1sg"] = {"brigga"}
    data.forms["pres_indc_2sg"] = {"briggis"}
    data.forms["pres_indc_3sg"] = {"briggiþ"}
    data.forms["pres_indc_1du"] = {"briggōs"}
    data.forms["pres_indc_2du"] = {"briggats"}
    data.forms["pres_indc_1pl"] = {"briggam"}
    data.forms["pres_indc_2pl"] = {"briggiþ"}
    data.forms["pres_indc_3pl"] = {"briggand"}

    -- Present subjunctive
    data.forms["pres_subj_1sg"] = {"briggau"}
    data.forms["pres_subj_2sg"] = {"briggais"}
    data.forms["pres_subj_3sg"] = {"briggai"}
    data.forms["pres_subj_1du"] = {"briggaiwa"}
    data.forms["pres_subj_2du"] = {"briggaits"}
    data.forms["pres_subj_1pl"] = {"briggaima"}
    data.forms["pres_subj_2pl"] = {"briggaiþ"}
    data.forms["pres_subj_3pl"] = {"briggaina"}

    -- Imperative
    data.forms["impr_2sg"] = {"brigg"}
    data.forms["impr_3sg"] = {"briggadau"}
    data.forms["impr_2du"] = {"briggats"}
    data.forms["impr_2pl"] = {"briggiþ"}
    data.forms["impr_3pl"] = {"briggandau"}

    -- Passive indicative
    data.forms["pasv_indc_1sg"] = {"briggada"}
    data.forms["pasv_indc_2sg"] = {"briggaza"}
    data.forms["pasv_indc_3sg"] = {"briggada"}
    data.forms["pasv_indc_1pl"] = {"brigganda"}
    data.forms["pasv_indc_2pl"] = {"brigganda"}
    data.forms["pasv_indc_3pl"] = {"brigganda"}

    -- Passive subjunctive
    data.forms["pasv_subj_1sg"] = {"briggadau"}
    data.forms["pasv_subj_2sg"] = {"briggazau"}
    data.forms["pasv_subj_3sg"] = {"briggadau"}
    data.forms["pasv_subj_1pl"] = {"briggandau"}
    data.forms["pasv_subj_2pl"] = {"briggandau"}
    data.forms["pasv_subj_3pl"] = {"briggandau"}

    -- Past indicative
    data.forms["past_indc_1sg"] = {"brāhta"}
    data.forms["past_indc_2sg"] = {"brāhtēs"}
    data.forms["past_indc_3sg"] = {"brāhta"}
    data.forms["past_indc_1du"] = {"brāhtēdu"}
    data.forms["past_indc_2du"] = {"brāhtēduts"}
    data.forms["past_indc_1pl"] = {"brāhtēdum"}
    data.forms["past_indc_2pl"] = {"brāhtēduþ"}
    data.forms["past_indc_3pl"] = {"brāhtēdun"}

    -- Past subjunctive
    data.forms["past_subj_1sg"] = {"brāhtēdjau"}
    data.forms["past_subj_2sg"] = {"brāhtēdeis"}
    data.forms["past_subj_3sg"] = {"brāhtēdi"}
    data.forms["past_subj_1du"] = {"brāhtēdeiwa"}
    data.forms["past_subj_2du"] = {"brāhtēdeits"}
    data.forms["past_subj_1pl"] = {"brāhtēdeima"}
    data.forms["past_subj_2pl"] = {"brāhtēdeiþ"}
    data.forms["past_subj_3pl"] = {"brāhtēdeina"}

    -- Non-finite forms
    data.forms["inf"]       = {"briggan"}
    data.forms["pres_ptcp"] = {"briggands"}
    data.forms["past_ptcp"] = {"brāhts"}
    
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


-- Make the table
function make_table(data)
	local function repl(param)
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info or "")
		end
		
		local form = data.forms[param]
		
		if not form or #form == 0 then
			return "—"
		end
		
		local ret_Goth = {}
		local ret_Latn = {}
		
		for key, subform in ipairs(form) do
			table.insert(ret_Latn, m_links.full_link({lang = lang, term = subform, tr = "-"}))
			table.insert(ret_Goth, m_links.full_link({lang = lang, term = m_translit.tr_reverse(subform), tr = "-"}))
		end
		
		return table.concat(ret_Goth, ", ") .. "<br/>" ..  table.concat(ret_Latn, ", ")
	end
	
	local names = {
		["indc"] = "直陳式",
		["subj"] = "虛擬式",
		["impr"] = "命令式",
		
		["pres"] = "現在時",
		["pasv"] = "現在時被動語態",
		["past"] = "過去時",
		
		["1sg"] = "一單",
		["2sg"] = "二單",
		["3sg"] = "三單",
		["1du"] = "一雙",
		["2du"] = "二雙",
		["1pl"] = "一複",
		["2pl"] = "二複",
		["3pl"] = "三複",
	}
	
	local pns = {"1sg", "2sg", "3sg", "1du", "2du", "1pl", "2pl", "3pl"}
	local impr_pns = {"2sg", "3sg", "2du", "2pl", "3pl"}
	local moods = {"indc", "subj"}
	local tenses = {"pres", "past", "pasv"}
	
	local wikicode = {}
	
	table.insert(wikicode, "{| class=\"wikitable inflection-table vsSwitcher\" style=\"border-style: double; border-width: 3px;\" cellspacing=\"1\" data-toggle-category=\"變位\"")
	table.insert(wikicode, "|-")
	table.insert(wikicode, "! class=\"vsToggleElement\" style=\"background: #CCC; min-width: " .. (8 + #tenses * 12) .. "em; text-align: left;\" colspan=\"" .. (#tenses + 1) .. "\" | {{{info}}}")
	
	table.insert(wikicode, "|- class=\"vsHide\"")
	table.insert(wikicode, "! " .. mw.getContentLanguage():ucfirst("不定式"))
	table.insert(wikicode, "| colspan=\"" .. (#tenses) .. "\" | {{{inf}}}")
	
	for _, mood in ipairs(moods) do
		table.insert(wikicode, "|- class=\"vsHide\"")
		table.insert(wikicode, "! style=\"min-width: 8em;\" | " .. mw.getContentLanguage():ucfirst(names[mood]))
		
		for _, tense in ipairs(tenses) do
			table.insert(wikicode, "! style=\"min-width: 12em;\" | " .. mw.getContentLanguage():ucfirst(names[tense]))
		end
		
		for _, pn in ipairs(pns) do
			table.insert(wikicode, "|- class=\"vsHide\"")
			table.insert(wikicode, "! " .. mw.getContentLanguage():ucfirst(names[pn]))
			
			for _, tense in ipairs(tenses) do
				table.insert(wikicode, "| {{{" .. tense .. "_" .. mood .. "_" .. pn .. "}}}")
			end
		end
	end
	
	table.insert(wikicode, "|- class=\"vsHide\"")
	table.insert(wikicode, "! " .. mw.getContentLanguage():ucfirst(names["impr"]))
	table.insert(wikicode, "!")
	table.insert(wikicode, "! colspan=\"" .. (#tenses) .. "\" rowspan=\"" .. (#impr_pns + 1) .. "\"|")
	
	for _, pn in ipairs(impr_pns) do
		table.insert(wikicode, "|- class=\"vsHide\"")
		table.insert(wikicode, "! " .. mw.getContentLanguage():ucfirst(names[pn]))
		table.insert(wikicode, "| {{{impr_" .. pn .. "}}}")
	end
	
	table.insert(wikicode, "|- class=\"vsHide\"")
	table.insert(wikicode, "|")
	table.insert(wikicode, "! " .. mw.getContentLanguage():ucfirst("現在"))
	table.insert(wikicode, "! " .. mw.getContentLanguage():ucfirst("過去"))
	table.insert(wikicode, "! rowspan=\"2\" |")
	table.insert(wikicode, "|- class=\"vsHide\"")
	table.insert(wikicode, "! " .. mw.getContentLanguage():ucfirst("分詞"))
	table.insert(wikicode, "| {{{pres_ptcp}}}")
	table.insert(wikicode, "| {{{past_ptcp}}}")
	
	table.insert(wikicode, "|}")
	
	wikicode = table.concat(wikicode, "\n")
	
	return mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)
end

return export