Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:StaffCard

From Vault Hunters Official Wiki

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

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    
    -- Get parameters
    local handle = args.handle or args[1] or ''
    local ign = args.ign or args[2] or ''
    local roles = args.roles or args[3] or ''
    local bio = args.bio or args[4] or ''
    local avatar = args.avatar or ''
    local status = args.status or 'active'
    local joined = args.joined or ''
    local discord = args.discord or ''
    local pronouns = args.pronouns or ''
    
    -- Check if we're being called from the template page itself (no parameters)
    -- This prevents errors when viewing the template page directly
    local hasAnyArgs = false
    for k, v in pairs(args) do
        if v and v ~= '' then
            hasAnyArgs = true
            break
        end
    end
    
    -- If no arguments provided (viewing template page), return empty string
    if not hasAnyArgs then
        return ''
    end
    
    -- Validate required fields for actual usage
    if handle == '' then
        return '<div class="error">Error: Handle is required for staff card</div>'
    end
    
    -- Build the card HTML
    local html = mw.html.create('div')
        :addClass('staff-card')
        :attr('data-handle', handle)
    
    -- Header section
    local header = html:tag('div'):addClass('staff-card-header')
    
    -- Avatar
    local avatarDiv = header:tag('div'):addClass('staff-card-avatar')
    if avatar ~= '' then
        avatarDiv:tag('img'):attr('src', avatar):attr('alt', handle .. ' avatar')
    else
        -- Use first letter of handle as fallback
        avatarDiv:wikitext(mw.ustring.sub(handle, 1, 1))
    end
    
    -- Info section
    local info = header:tag('div'):addClass('staff-card-info')
    info:tag('h3'):wikitext(handle)
    
    if ign ~= '' then
        info:tag('div'):addClass('staff-card-ign'):wikitext('IGN: ' .. ign)
    end
    
    if pronouns ~= '' then
        info:tag('div'):addClass('staff-card-pronouns'):wikitext('(' .. pronouns .. ')')
    end
    
    -- Roles section
    if roles ~= '' then
        local rolesDiv = html:tag('div'):addClass('staff-card-roles')
        local roleList = mw.text.split(roles, ',')
        for _, role in ipairs(roleList) do
            role = mw.text.trim(role)
            if role ~= '' then
                rolesDiv:tag('span'):addClass('staff-card-role'):wikitext(role)
            end
        end
    end
    
    -- Bio section
    if bio ~= '' then
        html:tag('div'):addClass('staff-card-bio'):wikitext(bio)
    end
    
    -- Footer section
    local footer = html:tag('div'):addClass('staff-card-footer')
    
    -- Status and meta info
    local meta = footer:tag('div'):addClass('staff-card-meta')
    
    -- Status indicator
    local statusSpan = meta:tag('span')
        :addClass('staff-card-status')
        :addClass(status:lower())
        :wikitext(status)
    
    -- Joined date
    if joined ~= '' then
        meta:tag('span'):wikitext('Joined: ' .. joined)
    end
    
    -- Discord handle
    if discord ~= '' then
        meta:tag('span'):wikitext('Discord: ' .. discord)
    end
    
    return tostring(html)
end

return p