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

Module:Team: Difference between revisions

From eSportsAmaze
No edit summary
No edit summary
Line 7: Line 7:
-- ============================================================
-- ============================================================


-- Currency Formatter (Styled for the new design)
-- Currency Formatter
local function formatCurrency(amount)
local function formatCurrency(amount)
     if not amount then return "0" end
     if not amount then return "0" end
    -- Adds the Indian Rupee symbol class/formatting
     return '<span class="indian-currency">₹ ' .. amount .. '</span>'
     return '<span class="indian-currency">₹ ' .. amount .. '</span>'
end
-- Social Icons (SAME AS TOURNAMENTS)
local function getSocials(args)
    local container = html.create('div'):addClass('fib-socials')
    local hasSocials = false
   
    -- List of supported platforms and their icon files
    local platforms = {
        {arg='instagram', file='Icon_instagram.png'},
        {arg='twitter',  file='Icon_twitter.png'},
        {arg='youtube',  file='Icon_youtube.png'},
        {arg='discord',  file='Icon_discord.png'},
        {arg='facebook',  file='Icon_facebook.png'},
        {arg='website',  file='Icon_website.png'}
    }
   
    for _, p in ipairs(platforms) do
        -- Check if the argument exists and is not empty
        if args[p.arg] and args[p.arg] ~= "" then
            hasSocials = true
            -- Render the icon linked to the URL provided in args
            container:wikitext('[[File:' .. p.file .. '|24px|link=' .. args[p.arg] .. '|class=social-img]]')
        end
    end
   
    if hasSocials then return tostring(container) else return "" end
end
end


Line 22: Line 48:
     local hasDark = mw.title.new('File:' .. darkFile).exists
     local hasDark = mw.title.new('File:' .. darkFile).exists
      
      
    -- Use .fib-image container (Same as Tournaments)
     local container = html.create('div'):addClass('fib-image')
     local container = html.create('div'):addClass('fib-image')
      
      
    -- Light Mode Image
     local lSpan = container:tag('span'):addClass('logo-lightmode')
     local lSpan = container:tag('span'):addClass('logo-lightmode')
     if hasLight then  
     if hasLight then lSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else lSpan:wikitext('[[File:Shield_team.png|180px]]') end
        lSpan:wikitext('[[File:' .. lightFile .. '|220px]]')  
    else  
        lSpan:wikitext('[[File:Shield_team.png|180px]]')  
    end
      
      
    -- Dark Mode Image
     local dSpan = container:tag('span'):addClass('logo-darkmode')
     local dSpan = container:tag('span'):addClass('logo-darkmode')
     if hasDark then  
     if hasDark then dSpan:wikitext('[[File:' .. darkFile .. '|220px]]') elseif hasLight then dSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else dSpan:wikitext('[[File:Shield_team_dark.png|180px]]') end
        dSpan:wikitext('[[File:' .. darkFile .. '|220px]]')  
    elseif hasLight then  
        dSpan:wikitext('[[File:' .. lightFile .. '|220px]]')  
    else  
        dSpan:wikitext('[[File:Shield_team_dark.png|180px]]')  
    end
      
      
     return tostring(container)
     return tostring(container)
Line 47: Line 60:


-- ============================================================
-- ============================================================
-- MAIN 1: TEAM INFOBOX (UPDATED TO FLAT DESIGN)
-- MAIN 1: TEAM INFOBOX (UPDATED)
-- ============================================================
-- ============================================================
function p.infobox(frame)
function p.infobox(frame)
Line 53: Line 66:
     local team = args.name or mw.title.getCurrentTitle().text
     local team = args.name or mw.title.getCurrentTitle().text
      
      
    -- 1. Create Root with New Class
     local root = html.create('div'):addClass('flat-infobox')
     local root = html.create('div'):addClass('flat-infobox')
      
      
     -- 2. Header
     -- Header
     root:tag('div'):addClass('fib-header')
     root:tag('div'):addClass('fib-header')
         :tag('div'):addClass('fib-title'):wikitext(team)
         :tag('div'):addClass('fib-title'):wikitext(team)
      
      
     -- 3. Logo
     -- Logo
     root:wikitext(getInfoboxLogo(team, args.image, args.image_dark))
     root:wikitext(getInfoboxLogo(team, args.image, args.image_dark))
      
      
     -- 4. Calculations (Rank & Earnings)
     -- Calculations
    -- Auto-Rank (Krafton Rankings)
     local rankTables = "Krafton_Rankings"
     local rankTables = "Krafton_Rankings"
     local rankFields = "rank"
     local rankFields = "rank"
Line 71: Line 82:
     local rankVal = (#rankResult > 0) and ("#" .. rankResult[1].rank) or "Unranked"
     local rankVal = (#rankResult > 0) and ("#" .. rankResult[1].rank) or "Unranked"
      
      
    -- Total Earnings (Auto-Sum)
     local prizeTables = "Tournament_Prizes"
     local prizeTables = "Tournament_Prizes"
     local prizeFields = "SUM(money)=total"
     local prizeFields = "SUM(money)=total"
Line 78: Line 88:
     local earnings = (#prizeResult > 0 and prizeResult[1].total) or "0"
     local earnings = (#prizeResult > 0 and prizeResult[1].total) or "0"
      
      
    -- Status Color Logic
     local statusColor = "#333"
     local statusColor = "#333"
     local statusText = args.status or "Active"
     local statusText = args.status or "Active"
     if args.status then
     if args.status then
         local s = args.status:lower()
         local s = args.status:lower()
         if s == "active" then statusColor = "#16a34a" -- Green
         if s == "active" then statusColor = "#16a34a"
         elseif s == "inactive" or s == "disbanded" then statusColor = "#dc2626" -- Red
         elseif s == "inactive" or s == "disbanded" then statusColor = "#dc2626"
         end
         end
     end
     end


     -- 5. GRID 1: Status & Rank
     -- Grid 1: Status & Rank
     local grid1 = root:tag('div'):addClass('fib-grid')
     local grid1 = root:tag('div'):addClass('fib-grid')
   
     grid1:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Status'):done():tag('div'):addClass('fib-value-sm'):css('color', statusColor):wikitext(statusText):done()
    -- Cell: Status
     grid1:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Krafton Rank'):done():tag('div'):addClass('fib-value-sm'):wikitext(rankVal):done()
     grid1:tag('div'):addClass('fib-cell')
        :tag('div'):addClass('fib-label-sm'):wikitext('Status'):done()
        :tag('div'):addClass('fib-value-sm'):css('color', statusColor):wikitext(statusText):done()
       
    -- Cell: Rank
     grid1:tag('div'):addClass('fib-cell')
        :tag('div'):addClass('fib-label-sm'):wikitext('Krafton Rank'):done()
        :tag('div'):addClass('fib-value-sm'):wikitext(rankVal):done()


     -- 6. GRID 2: Country & Tag
     -- Grid 2: Country & Tag
     local grid2 = root:tag('div'):addClass('fib-grid')
     local grid2 = root:tag('div'):addClass('fib-grid')
   
     grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Country'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.country or 'TBD'):done()
    -- Cell: Country
     grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Tag'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.short_code or '-'):done()
     grid2:tag('div'):addClass('fib-cell')
        :tag('div'):addClass('fib-label-sm'):wikitext('Country'):done()
        :tag('div'):addClass('fib-value-sm'):wikitext(args.country or 'TBD'):done()
       
    -- Cell: Short Code
     grid2:tag('div'):addClass('fib-cell')
        :tag('div'):addClass('fib-label-sm'):wikitext('Tag'):done()
        :tag('div'):addClass('fib-value-sm'):wikitext(args.short_code or '-'):done()


     -- 7. Earnings Section (Highlighted)
     -- Earnings Section
     if earnings and earnings ~= "0" then
     if earnings and earnings ~= "0" then
         root:tag('div'):addClass('fib-prize')
         root:tag('div'):addClass('fib-prize')
Line 121: Line 114:
     end
     end
      
      
     -- 8. Info List
     -- Info List
     local list = root:tag('div'):addClass('fib-list')
     local list = root:tag('div'):addClass('fib-list')
     local function addRow(label, value)
     local function addRow(label, value)
         if value and value ~= "" then
         if value and value ~= "" then
             list:tag('div'):addClass('fib-row')
             list:tag('div'):addClass('fib-row'):tag('div'):addClass('fib-label'):wikitext(label):done():tag('div'):addClass('fib-data'):wikitext(value):done()
                :tag('div'):addClass('fib-label'):wikitext(label):done()
                :tag('div'):addClass('fib-data'):wikitext(value):done()
         end
         end
     end
     end
      
      
     addRow('Full Name', args.other_team)
     addRow('Full Name', args.other_team)
     if args.sponsors then
     if args.sponsors then addRow('Sponsors', args.sponsors:gsub(",", "<br>")) end
        addRow('Sponsors', args.sponsors:gsub(",", "<br>"))
    end
      
      
     -- 9. Social Media (Using styled container)
     -- [[ UPDATED: Social Icons ]]
     if args.instagram or args.twitter or args.youtube then
     root:wikitext(getSocials(args))
        local socialDiv = root:tag('div'):addClass('fib-socials')
       
        -- Since current data uses text links (e.g., [url Name]), we render them simply
        -- If you update data to just be URLs later, we can add icons here.
        if args.instagram then socialDiv:wikitext('<span style="font-weight:bold;">[' .. args.instagram .. ' IG]</span>') end
        if args.twitter then socialDiv:wikitext('<span style="font-weight:bold;">[' .. args.twitter .. ' X]</span>') end
        if args.youtube then socialDiv:wikitext('<span style="font-weight:bold;">[' .. args.youtube .. ' YT]</span>') end
    end


     return tostring(root)
     return tostring(root)
Line 151: Line 132:


-- ============================================================
-- ============================================================
-- MAIN 2: AUTOMATIC TOURNAMENT HISTORY (Preserved)
-- MAIN 2: HISTORY & ROSTER (Keep exactly as before)
-- ============================================================
-- ============================================================
function p.history(frame)
function p.history(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local team = args.team or mw.title.getCurrentTitle().subpageText
     local team = args.team or mw.title.getCurrentTitle().subpageText
   
     local tables, fields = "StageStandings", "tournament, stage, totalpts, matchesplayed, wwcd, elimpts, lastmatchrank, result"
    -- Query StageStandings
     local queryArgs = { where = "team = '" .. team .. "'", orderBy = "tournament DESC", limit = 50 }
     local tables = "StageStandings"
    local fields = "tournament, stage, totalpts, matchesplayed, wwcd, elimpts, lastmatchrank, result"
     local queryArgs = {
        where = "team = '" .. team .. "'",
        orderBy = "tournament DESC",
        limit = 50
    }
   
     local results = cargo.query(tables, fields, queryArgs)
     local results = cargo.query(tables, fields, queryArgs)
      
      
Line 172: Line 145:
      
      
     if #results > 0 then
     if #results > 0 then
        -- Uses your 'modern-history-table' CSS class
         local tbl = root:tag('table'):addClass('modern-history-table')
         local tbl = root:tag('table'):addClass('modern-history-table')
       
        -- Header
         local thead = tbl:tag('thead'):tag('tr')
         local thead = tbl:tag('thead'):tag('tr')
         thead:tag('th'):wikitext('Tournament')
         thead:tag('th'):wikitext('Tournament'); thead:tag('th'):wikitext('Stage'); thead:tag('th'):wikitext('Rank')
        thead:tag('th'):wikitext('Stage')
         thead:tag('th'):wikitext('MP'); thead:tag('th'):wikitext('WWCD'); thead:tag('th'):wikitext('Elims'); thead:tag('th'):wikitext('Pts')
        thead:tag('th'):wikitext('Rank')
         thead:tag('th'):wikitext('MP')
        thead:tag('th'):wikitext('WWCD')
        thead:tag('th'):wikitext('Elims')
        thead:tag('th'):wikitext('Pts')
          
          
        -- Rows
         for _, row in ipairs(results) do
         for _, row in ipairs(results) do
             local tr = tbl:tag('tr')
             local tr = tbl:tag('tr')
           
            -- Color code result
             local res = (row.result or ""):lower()
             local res = (row.result or ""):lower()
             if res == "q" or res == "qualified" then tr:css('background-color', '#E9FFF0') -- Greenish
             if res == "q" or res == "qualified" then tr:css('background-color', '#E9FFF0')
             elseif res == "e" or res == "eliminated" then tr:css('background-color', '#FFE9E9') -- Reddish
             elseif res == "e" or res == "eliminated" then tr:css('background-color', '#FFE9E9') end
            end
              
              
             tr:tag('td'):css('font-weight','bold'):wikitext('[[' .. row.tournament .. ']]')
             tr:tag('td'):css('font-weight','bold'):wikitext('[[' .. row.tournament .. ']]')
Line 203: Line 164:
             tr:tag('td'):css('text-align','center'):css('font-weight','800'):wikitext(row.totalpts)
             tr:tag('td'):css('text-align','center'):css('font-weight','800'):wikitext(row.totalpts)
         end
         end
     else
     else root:wikitext("''No tournament data found for this team.''") end
        root:wikitext("''No tournament data found for this team.''")
    end
   
     return tostring(root)
     return tostring(root)
end
end


-- ============================================================
-- MAIN 3: ACTIVE ROSTER TABLE (Preserved)
-- ============================================================
function p.activeRoster(frame)
function p.activeRoster(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local team = args.team or mw.title.getCurrentTitle().subpageText
     local team = args.team or mw.title.getCurrentTitle().subpageText
    local results = cargo.query("Players", "id, real_name, role, nationality, image", { where = "current_team = '" .. team .. "'", orderBy = "role ASC, id ASC" })
      
      
    -- Query Players
     local root = html.create('table'):addClass('wikitable flat-table sortable'):css('width', '100%'):css('text-align', 'center')
    local tables = "Players"
    local fields = "id, real_name, role, nationality, image"
    local queryArgs = {
        where = "current_team = '" .. team .. "'",
        orderBy = "role ASC, id ASC"
    }
   
    local results = cargo.query(tables, fields, queryArgs)
   
     local root = html.create('table')
    root:addClass('wikitable flat-table sortable')
        :css('width', '100%')
        :css('text-align', 'center')
       
     local header = root:tag('tr')
     local header = root:tag('tr')
     header:tag('th'):wikitext('ID')
     header:tag('th'):wikitext('ID'); header:tag('th'):wikitext('Name'); header:tag('th'):wikitext('Role'); header:tag('th'):wikitext('Nationality')
    header:tag('th'):wikitext('Name')
    header:tag('th'):wikitext('Role')
    header:tag('th'):wikitext('Nationality')
      
      
     if #results > 0 then
     if #results > 0 then
         for _, row in ipairs(results) do
         for _, row in ipairs(results) do
             local tr = root:tag('tr')
             local tr = root:tag('tr')
           
            -- Cell 1: ID with Image
             local idCell = tr:tag('td'):css('text-align', 'left'):css('font-weight', 'bold')
             local idCell = tr:tag('td'):css('text-align', 'left'):css('font-weight', 'bold')
             if row.image and row.image ~= "" then
             if row.image and row.image ~= "" then idCell:wikitext('[[File:' .. row.image .. '|30px|link=' .. row.id .. ']] ') end
                idCell:wikitext('[[File:' .. row.image .. '|30px|link=' .. row.id .. ']] ')
            end
             idCell:wikitext('[[' .. row.id .. ']]')
             idCell:wikitext('[[' .. row.id .. ']]')
           
             tr:tag('td'):wikitext(row.real_name); tr:tag('td'):wikitext(row.role); tr:tag('td'):wikitext(row.nationality)
             tr:tag('td'):wikitext(row.real_name)
            tr:tag('td'):wikitext(row.role)
            tr:tag('td'):wikitext(row.nationality)
         end
         end
     else
     else root:tag('tr'):tag('td'):attr('colspan', '4'):wikitext('No players currently listed for this team.') end
        root:tag('tr'):tag('td'):attr('colspan', '4'):wikitext('No players currently listed for this team.')
    end
   
     return tostring(root)
     return tostring(root)
end
end


return p
return p

Revision as of 06:59, 28 January 2026

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

local p = {}
local cargo = mw.ext.cargo
local html = mw.html

-- ============================================================
-- HELPER FUNCTIONS
-- ============================================================

-- Currency Formatter
local function formatCurrency(amount)
    if not amount then return "0" end
    return '<span class="indian-currency">₹ ' .. amount .. '</span>'
end

-- Social Icons (SAME AS TOURNAMENTS)
local function getSocials(args)
    local container = html.create('div'):addClass('fib-socials')
    local hasSocials = false
    
    -- List of supported platforms and their icon files
    local platforms = {
        {arg='instagram', file='Icon_instagram.png'},
        {arg='twitter',   file='Icon_twitter.png'},
        {arg='youtube',   file='Icon_youtube.png'},
        {arg='discord',   file='Icon_discord.png'},
        {arg='facebook',  file='Icon_facebook.png'},
        {arg='website',   file='Icon_website.png'}
    }
    
    for _, p in ipairs(platforms) do
        -- Check if the argument exists and is not empty
        if args[p.arg] and args[p.arg] ~= "" then
            hasSocials = true
            -- Render the icon linked to the URL provided in args
            container:wikitext('[[File:' .. p.file .. '|24px|link=' .. args[p.arg] .. '|class=social-img]]')
        end
    end
    
    if hasSocials then return tostring(container) else return "" end
end

-- New Logo Logic (Matches Tournament Infobox Style)
local function getInfoboxLogo(teamName, image, imageDark)
    local lightFile = (image ~= "" and image) or (teamName .. '.png')
    local darkFile = (imageDark ~= "" and imageDark) or (teamName .. '_dark.png')
    
    local hasLight = mw.title.new('File:' .. lightFile).exists
    local hasDark = mw.title.new('File:' .. darkFile).exists
    
    local container = html.create('div'):addClass('fib-image')
    
    local lSpan = container:tag('span'):addClass('logo-lightmode')
    if hasLight then lSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else lSpan:wikitext('[[File:Shield_team.png|180px]]') end
    
    local dSpan = container:tag('span'):addClass('logo-darkmode')
    if hasDark then dSpan:wikitext('[[File:' .. darkFile .. '|220px]]') elseif hasLight then dSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else dSpan:wikitext('[[File:Shield_team_dark.png|180px]]') end
    
    return tostring(container)
end

-- ============================================================
-- MAIN 1: TEAM INFOBOX (UPDATED)
-- ============================================================
function p.infobox(frame)
    local args = frame:getParent().args
    local team = args.name or mw.title.getCurrentTitle().text
    
    local root = html.create('div'):addClass('flat-infobox')
    
    -- Header
    root:tag('div'):addClass('fib-header')
        :tag('div'):addClass('fib-title'):wikitext(team)
    
    -- Logo
    root:wikitext(getInfoboxLogo(team, args.image, args.image_dark))
    
    -- Calculations
    local rankTables = "Krafton_Rankings"
    local rankFields = "rank"
    local rankArgs = { where = "name = '" .. team .. "' AND type='Team'", limit = 1 }
    local rankResult = cargo.query(rankTables, rankFields, rankArgs)
    local rankVal = (#rankResult > 0) and ("#" .. rankResult[1].rank) or "Unranked"
    
    local prizeTables = "Tournament_Prizes"
    local prizeFields = "SUM(money)=total"
    local prizeArgs = { where = "recipient = '" .. team .. "'" }
    local prizeResult = cargo.query(prizeTables, prizeFields, prizeArgs)
    local earnings = (#prizeResult > 0 and prizeResult[1].total) or "0"
    
    local statusColor = "#333"
    local statusText = args.status or "Active"
    if args.status then
        local s = args.status:lower()
        if s == "active" then statusColor = "#16a34a"
        elseif s == "inactive" or s == "disbanded" then statusColor = "#dc2626"
        end
    end

    -- Grid 1: Status & Rank
    local grid1 = root:tag('div'):addClass('fib-grid')
    grid1:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Status'):done():tag('div'):addClass('fib-value-sm'):css('color', statusColor):wikitext(statusText):done()
    grid1:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Krafton Rank'):done():tag('div'):addClass('fib-value-sm'):wikitext(rankVal):done()

    -- Grid 2: Country & Tag
    local grid2 = root:tag('div'):addClass('fib-grid')
    grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Country'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.country or 'TBD'):done()
    grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Tag'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.short_code or '-'):done()

    -- Earnings Section
    if earnings and earnings ~= "0" then
        root:tag('div'):addClass('fib-prize')
            :tag('div'):addClass('fib-label-sm'):wikitext('Total Earnings'):done()
            :tag('div'):addClass('fib-prize-val'):wikitext(formatCurrency(earnings)):done()
    end
    
    -- Info List
    local list = root:tag('div'):addClass('fib-list')
    local function addRow(label, value)
        if value and value ~= "" then
            list:tag('div'):addClass('fib-row'):tag('div'):addClass('fib-label'):wikitext(label):done():tag('div'):addClass('fib-data'):wikitext(value):done()
        end
    end
    
    addRow('Full Name', args.other_team)
    if args.sponsors then addRow('Sponsors', args.sponsors:gsub(",", "<br>")) end
    
    -- [[ UPDATED: Social Icons ]]
    root:wikitext(getSocials(args))

    return tostring(root)
end

-- ============================================================
-- MAIN 2: HISTORY & ROSTER (Keep exactly as before)
-- ============================================================
function p.history(frame)
    local args = frame:getParent().args
    local team = args.team or mw.title.getCurrentTitle().subpageText
    local tables, fields = "StageStandings", "tournament, stage, totalpts, matchesplayed, wwcd, elimpts, lastmatchrank, result"
    local queryArgs = { where = "team = '" .. team .. "'", orderBy = "tournament DESC", limit = 50 }
    local results = cargo.query(tables, fields, queryArgs)
    
    local root = html.create('div')
    root:wikitext('== Tournament Statistics ==')
    
    if #results > 0 then
        local tbl = root:tag('table'):addClass('modern-history-table')
        local thead = tbl:tag('thead'):tag('tr')
        thead:tag('th'):wikitext('Tournament'); thead:tag('th'):wikitext('Stage'); thead:tag('th'):wikitext('Rank')
        thead:tag('th'):wikitext('MP'); thead:tag('th'):wikitext('WWCD'); thead:tag('th'):wikitext('Elims'); thead:tag('th'):wikitext('Pts')
        
        for _, row in ipairs(results) do
            local tr = tbl:tag('tr')
            local res = (row.result or ""):lower()
            if res == "q" or res == "qualified" then tr:css('background-color', '#E9FFF0')
            elseif res == "e" or res == "eliminated" then tr:css('background-color', '#FFE9E9') end
            
            tr:tag('td'):css('font-weight','bold'):wikitext('[[' .. row.tournament .. ']]')
            tr:tag('td'):wikitext(row.stage)
            tr:tag('td'):css('font-weight','bold'):css('text-align','center'):wikitext('#' .. (row.lastmatchrank or '?'))
            tr:tag('td'):css('text-align','center'):wikitext(row.matchesplayed)
            tr:tag('td'):css('text-align','center'):wikitext(row.wwcd)
            tr:tag('td'):css('text-align','center'):wikitext(row.elimpts)
            tr:tag('td'):css('text-align','center'):css('font-weight','800'):wikitext(row.totalpts)
        end
    else root:wikitext("''No tournament data found for this team.''") end
    return tostring(root)
end

function p.activeRoster(frame)
    local args = frame:getParent().args
    local team = args.team or mw.title.getCurrentTitle().subpageText
    local results = cargo.query("Players", "id, real_name, role, nationality, image", { where = "current_team = '" .. team .. "'", orderBy = "role ASC, id ASC" })
    
    local root = html.create('table'):addClass('wikitable flat-table sortable'):css('width', '100%'):css('text-align', 'center')
    local header = root:tag('tr')
    header:tag('th'):wikitext('ID'); header:tag('th'):wikitext('Name'); header:tag('th'):wikitext('Role'); header:tag('th'):wikitext('Nationality')
    
    if #results > 0 then
        for _, row in ipairs(results) do
            local tr = root:tag('tr')
            local idCell = tr:tag('td'):css('text-align', 'left'):css('font-weight', 'bold')
            if row.image and row.image ~= "" then idCell:wikitext('[[File:' .. row.image .. '|30px|link=' .. row.id .. ']] ') end
            idCell:wikitext('[[' .. row.id .. ']]')
            tr:tag('td'):wikitext(row.real_name); tr:tag('td'):wikitext(row.role); tr:tag('td'):wikitext(row.nationality)
        end
    else root:tag('tr'):tag('td'):attr('colspan', '4'):wikitext('No players currently listed for this team.') end
    return tostring(root)
end

return p