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

local p = {}

function p.init(frame)
    local intr = frame:getParent().args["intr"]
    local pagename = tostring( mw.title:getCurrentTitle() )
    local root = string.sub(pagename, 0, -3)
    return p.conj(root, intr)
end

function p.conj(root, intr)
    local function link(affix)
        return require("Module:links").full_link({lang = lang, term = root .. affix})
    end

    local function row(r)
        return ""
    end

    local t = {"a", "i", "o"}

    local val = [=[<div class="NavFrame" style="width: 40em;">
<div class="NavHead"><span lang="io" style="font-style:italic;">]=] .. root .. [=[ar</span> 的變位</div>
<div class="NavContent">
{| style="background-color:#F9F9F9;border-collapse:separate;border-spacing:2px;width:100%" class="inflection-table"
|-
|style="background-color:#c8dfef;" colspan=2|[[Image:Jankó-stelo.svg|50px|link=|alt=]]
!style="background-color:#c8dfef;" colspan=2|現在時
!style="background-color:#c8dfef;" colspan=2|過去時
!style="background-color:#c8dfef;" colspan=2|未來時]=]
    local function threecells(preword, affix, words)
        val = val .. "\n|-\n!style=\"background-color:#c8dfef;\" colspan=2|" .. preword

        for i = 1, 3, 1 do
            val = val .. "\n|style=\"background-color:#F9F9F9;\" colspan=2|"

            if type(affix) == "table" then
                if affix[i] ~= "" then
                    val = val .. link(affix[i])
                end
            else
                val = val .. link(t[i] .. affix)
            end
        end
    end

    local function sixcells(preword, interfix)
        val = val .. "\n|-\n!style=\"background-color:#c8dfef;\" rowspan=2|" .. preword

        val = val .. "\n!style=\"background-color:#c8dfef;\"|單數"
        for i = 1, 3, 1 do
            val = val .. "\n|style=\"background-color:#F9F9F9;\" colspan=2|" .. link(t[i] .. interfix .. "o")
        end

        val = val .. "\n|-\n!style=\"background-color:#c8dfef;\"|複數"
        for i = 1, 3, 1 do
            val = val .. "\n|style=\"background-color:#F9F9F9;\" colspan=2|" .. link(t[i] .. interfix .. "i")
        end
    end

    threecells("不定式", "r")
    threecells("時態", "s")
    threecells("條件語氣", {"us", "", ""})
    threecells("命令語氣", {"ez", "", ""})
    threecells("形容詞化主動分詞", "nta")
    threecells("副詞化主動分詞", "nte")
    sixcells("名詞化主動分詞", "nt")
    if intr ~= "yes" then threecells("形容詞被動分詞", "ta") end
    if intr ~= "yes" then threecells("副詞化被動分詞", "te") end
    if intr ~= "yes" then sixcells("名詞化被動分詞", "t") end

val = val .. [=[

|}
</div></div>]=]

    return val
end


return p