Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 02:42, 25 January 2026 by Esportsamaze (talk | contribs)

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

local p = {}
local html = mw.html
local title = mw.title.getCurrentTitle()

function p.main(frame)
    local args = frame:getParent().args
    
    -- 1. Collect Tab Names
    local tabNames = {}
    local i = 1
    while args[i] do
        table.insert(tabNames, args[i])
        i = i + 1
    end
    
    -- 2. Auto-Detect the Base (Root) Page
    local basePage = args.base
    if not basePage then
        -- Check if we are currently sitting on one of the tabs (e.g., ".../The Grind")
        local currentSub = title.subpageText
        local isTabSubpage = false
        
        for _, name in ipairs(tabNames) do
            if name == currentSub then
                isTabSubpage = true
                break
            end
        end
        
        if isTabSubpage then
            basePage = title.baseText -- Go up one level (parent is the root)
        else
            basePage = title.prefixedText -- We are already on the root
        end
    end

    -- 3. Setup Styles (Main vs Sub)
    local isSub = (args.type == 'sub')
    local containerClass = isSub and 'pastel-bar' or 'chrome-tabs-container'
    local tabClass = isSub and 'pastel-pill' or 'chrome-tab'
    
    -- 4. Build the Tabs
    local root = html.create('div'):addClass(containerClass)
    
    for _, name in ipairs(tabNames) do
        local target = ""
        
        -- === THE FIX ===
        -- If the tab is "Overview", link to the Base Page directly.
        -- Otherwise, link to Base Page + "/" + Tab Name.
        if name == 'Overview' then
            target = basePage
        else
            target = basePage .. '/' .. name
        end
        
        -- Determine Active State
        local isActive = (title.prefixedText == target)
        
        local tabDiv = root:tag('div'):addClass(tabClass)
        if isActive then tabDiv:addClass('active') end
        
        tabDiv:wikitext('[[' .. target .. '|' .. name .. ']]')
    end
    
    return tostring(root)
end

return p