require('strict')

local getArgs = require('Module:Arguments').getArgs

local p = {}

function p.main(frame)
    local args = getArgs(frame)
    return p._main(args)
end

function p._main(args)
    local tab = {}
    
    local name = args[1]
    local original = args[2]
    local original_language = 'ja'
    local english = args[3] or args.na or args.en 
    local english2 = args[4] or args.eu or args.en2
    

    if name then
        table.insert(tab, name)
    end
    
    if original then
        if mw.ustring.find( original, '^[a-z][a-z][a-z]?:.+$' ) then
            original_language, original = mw.ustring.match( original, '([a-z][a-z][a-z]?):(.+)$' )
        end
        table.insert(tab,
            '<span lang="' .. original_language .. '" style="font-size: 90%;">' .. 
            '-{' .. original .. '}-' ..
            '</span>'
        )
    end

    if english then
        table.insert(tab,
            '<span lang="' .. 'en' .. '" style="font-size: 90%;">' .. 
            "''" .. '-{' .. english .. '}-' .. "''" ..
            '</span>'
        )
    end
    
    if english2 then
        table.insert(tab,
            '<span lang="' .. 'en' .. '" style="font-size: 90%;">' .. 
            "''" .. '-{' .. english2 .. '}-' .. "''" ..
            '</span>'
        )
    end


    return '<div class="plainlist" style="line-height: 120%;">' .. '\n* ' ..
        table.concat(tab, '\n* ') ..
        '</div>'

end

return p