yu no

Documentation for this module may be created at Module:Tabs/doc

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local fulltitle = mw.title.getCurrentTitle().text
    local current_tab = args.current_tab or ""
    local tabs = {}
    
    local active_index = 0

    for i = 1, 9 do
        local tab_target = args["tab" .. i]
        if tab_target and tab_target ~= "" then
            if current_tab == "tab" .. i or fulltitle == tab_target then
                active_index = i
                break
            elseif string.sub(fulltitle, 1, string.len(tab_target) + 1) == tab_target .. "/" then
                active_index = i
            end
        end
    end

    for i = 1, 9 do
        local tab_target = args["tab" .. i]
        local tab_label = args["tab" .. i .. "a"]

        if tab_target and tab_target ~= "" then
            local class = "tab"
            local display_label = (tab_label and tab_label ~= "") and tab_label or tab_target

            if i == active_index then
                class = class .. " current_tab"
            end

            local tab_content = string.format('[[%s|<div class="%s">%s</div>]]', tab_target, class, display_label)
            table.insert(tabs, tab_content)
        end
    end

    local output = '<div class="article_tabs">' .. table.concat(tabs) .. '</div><div style="clear:both;"></div>'
    return output
end

return p