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 00:31, 25 January 2026 by Esportsamaze (talk | contribs) (Created page with "local p = {} local cargo = mw.ext.cargo local html = mw.html local lang = mw.getLanguage('en') -- Helper: Format Number with Commas (Indian Locale is handled by your JS, we just output raw number wrapped in span) local function formatCurrency(amount) if not amount then return "0" end -- We output the raw number inside the span. Your MediaWiki:Common.js 'indian-currency' script -- picks this up and adds the ₹ symbol and correct commas automatically. re...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}
local cargo = mw.ext.cargo
local html = mw.html
local lang = mw.getLanguage('en')

-- Helper: Format Number with Commas (Indian Locale is handled by your JS, we just output raw number wrapped in span)
local function formatCurrency(amount)
    if not amount then return "0" end
    -- We output the raw number inside the span. Your MediaWiki:Common.js 'indian-currency' script 
    -- picks this up and adds the ₹ symbol and correct commas automatically.
    return '<span class="indian-currency">' .. amount .. '</span>'
end

-- Function 1: Display a Prize Row (for Tournament Pages)
function p.row(frame)
    local args = frame:getParent().args
    local place = args.place or "0"
    local money = args.money or "0"
    local recipient = args.recipient or ""
    local team = args.recipient_team or args.team or ""
    
    local root = html.create('tr')
    
    -- 1. Rank Cell
    local rankCell = root:tag('td'):addClass('col-rank')
    if place == '1' then rankCell:wikitext('🏆')
    elseif place == '2' then rankCell:wikitext('🥈')
    elseif place == '3' then rankCell:wikitext('🥉')
    else rankCell:tag('span'):addClass('prize-rank-number'):wikitext('#' .. place)
    end
    
    -- 2. Money Cell
    root:tag('td'):addClass('col-money'):wikitext(formatCurrency(money))
    
    -- 3. Team/Recipient Cell
    local teamCell = root:tag('td'):addClass('col-team')
    local flexDiv = teamCell:tag('div'):addClass('prize-team-flex')
    
    -- Logo Logic
    local logoName = (team ~= "" and team) or recipient
    local logoFile = logoName .. '.png'
    local logoBox = flexDiv:tag('span'):addClass('prize-logo-box')
    
    if mw.title.new('File:' .. logoFile).exists then
        logoBox:wikitext('[[File:' .. logoFile .. '|30px|link=' .. logoName .. ']]')
    else
        logoBox:wikitext('[[File:Shield_team.png|30px|link=' .. logoName .. ']]')
    end
    
    -- Name Logic
    if recipient ~= "" then
        flexDiv:tag('span'):addClass('prize-team-name'):wikitext('[[' .. recipient .. ']]')
    else
        flexDiv:tag('span'):addClass('prize-team-name'):css('color','#888'):css('font-style','italic'):css('padding-left','5px'):wikitext('TBD')
    end
    
    return tostring(root)
end

-- Function 2: Team History Table (For Team Pages)
function p.history(frame)
    local args = frame:getParent().args
    local teamName = args.team or mw.title.getCurrentTitle().text
    
    -- Query Cargo
    local tables = "Tournament_Prizes"
    local fields = "tournament, place, money"
    local queryArgs = {
        where = "recipient = '" .. teamName .. "' OR recipient_team = '" .. teamName .. "'",
        orderBy = "money DESC",
        limit = 50
    }
    
    local results = cargo.query(tables, fields, queryArgs)
    
    local container = html.create('div')
    
    -- A. Calculate Total Earnings
    local totalMoney = 0
    if #results > 0 then
        for _, row in ipairs(results) do
            totalMoney = totalMoney + (tonumber(row.money) or 0)
        end
    end
    
    -- B. Display Summary Box
    container:tag('div')
        :css('background', 'var(--bg-header)')
        :css('padding', '10px')
        :css('border', '1px solid var(--border-main)')
        :css('border-radius', '6px')
        :css('margin-bottom', '10px')
        :css('width', '100%')
        :css('max-width', '500px')
        :css('font-weight', 'bold')
        :css('text-align', 'center')
        :css('font-size', '1.1em')
        :wikitext('Total Estimated Earnings: ' .. formatCurrency(totalMoney))
        
    -- C. Display History Table
    local tbl = container:tag('table')
        :addClass('wikitable flat-table sortable')
        :css('width', '100%')
        :css('max-width', '600px')
        :css('text-align', 'center')
        
    local header = tbl:tag('tr')
    header:tag('th'):css('text-align', 'left'):wikitext('Tournament')
    header:tag('th'):wikitext('Ranked')
    header:tag('th'):css('text-align', 'right'):wikitext('Prize Money')
    
    if #results > 0 then
        for _, row in ipairs(results) do
            local tr = tbl:tag('tr')
            tr:tag('td'):css('text-align', 'left'):css('font-weight', 'bold'):wikitext('[[' .. row.tournament .. ']]')
            tr:tag('td'):wikitext("'''" .. row.place .. "'''")
            tr:tag('td'):css('text-align', 'right'):wikitext(formatCurrency(row.money))
        end
    else
        container:tag('div'):css('padding','15px'):css('color','#666'):wikitext('No prize data recorded yet.')
    end
    
    return tostring(container)
end

return p