local export = {}

function export.tag_form(form, tag)
    if form ~= "" then
        return "<" .. (tag or "span") .. " lang=\"gem-pro\" class=\"Unicode\">*" .. form .. "</" .. (tag or "span") .. ">"
    else
        return "&mdash;"
    end
end

-- Make a link out of a form, or show a dash if empty.
function export.link_form(form, tag)
    if not SUBPAGENAME then
        SUBPAGENAME = mw.title.getCurrentTitle().subpageText
    end
    
    if type(form) == "table" then
        for n, subform in pairs(form) do
            form[n] = export.link_form(subform, tag)
        end
        return table.concat(form, ", ")
    else
        if form ~= "" then
            return "<" .. (tag or "span") .. " lang=\"gem-pro\" class=\"Unicode\">[[Reconstruction:原始日耳曼語/" .. form .. "|*" .. form .. "]]</" .. (tag or "span") .. ">"
        else
            return "&mdash;"
        end
    end
end

-- Add a -t- to a word, which alters the final consonant.
function export.add_t(word)
    word = word .. "t"
    
    word = mw.ustring.gsub(word, "gdt$", "hst")
    word = mw.ustring.gsub(word, "skt$", "st")
    word = mw.ustring.gsub(word, "stt$", "st")
    
    word = mw.ustring.gsub(word, "[bp]t$", "ft")
    word = mw.ustring.gsub(word, "[dtþ]t$", "st")
    word = mw.ustring.gsub(word, "[gk]t$", "ht")
    word = mw.ustring.gsub(word, "[gkh]wt$", "ht")
    
    return word
end

-- Change all e to i
function export.i_mutation(word)
    return word:gsub("e", "i")
end

return export