Module:UserPredictionsUser

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_esports = require('Module:EsportsUtil') local util_html = require('Module:HtmlUtil') local util_math = require('Module:MathUtil') local util_predictions = require('Module:PredictionsUtil') local util_sort = require('Module:SortUtil') local util_table = require('Module:TableUtil') local util_text = require('Module:TextUtil') local util_title = require('Module:TitleUtil') local util_vars = require('Module:VarsUtil') local i18n = require('Module:i18nUtil')

local USER

local h = {}

local p = {} function p.main(frame) i18n.init('PredictionsUtil', 'UserPredictionsUser') local args = util_args.merge(true) USER = h.getUser(args) local eventList = h.getEventList(args) return h.makeOutput(eventList) end

function h.getUser(args) return args.user or util_title.titleparts(nil, 1, 2) end

function h.getEventList(args) local query = h.getQuery(args) return util_cargo.queryAndCast(query) end

function h.getQuery(args) local ret = { tables = { 'Tournaments=IT', 'UserPredictions=UP' }, join = 'IT._pageName=UP.OverviewPage', fields = { 'IT.Name=EventName', 'UP.OverviewPage=OverviewPage', 'UP.NumberCorrect=NumberCorrect', 'UP.NumberOver=NumberOver', 'UP.NumberMadeAndOver=NumberMadeAndOver', 'UP._pageName=_pageName', },		where = h.getWhere(args), orderBy = 'IT.Date DESC', }	return ret end

function h.getWhere(args) local tbl = { ('UP.User="%s"'):format(USER) }	return util_cargo.concatWhere(tbl) end

function h.makeOutput(eventList) local output = mw.html.create h.printActions(output) h.printContent(output, eventList) return output end

function h.printActions(output) output:tag('h2'):wikitext(i18n.default('headingActions')) local ul = output:tag('ul') util_predictions.printRefreshThisPageButton(ul:tag('li')) ul:tag('li'):wikitext(i18n.print('refreshEvent')) end

function h.printContent(output, eventList) output:tag('h2'):wikitext(i18n.default('headingContent')) local ul = output:tag('ul') for _, row in ipairs(eventList) do		h.printRow(ul, row) end end

function h.printRow(ul, row) local li = ul:tag('li') :wikitext(h.makeLink(row), ' - ', h.makeTotal(row)) util_predictions.printRefreshTargetButton(li, row._pageName) end

function h.makeLink(row) return util_text.intLink(row._pageName, row.EventName) end

function h.makeTotal(row) return i18n.print('totals', row.NumberCorrect, row.NumberOver, row.NumberMadeAndOver) end

return p