Module:MostRecentGameIncluded

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_esports = require('Module:EsportsUtil') local util_form = require('Module:FormUtil') local util_html = require('Module:HtmlUtil') local util_map = require('Module:MapUtil') local util_math = require('Module:MathUtil') local util_sort = require('Module:SortUtil') local util_stats = require('Module:StatsUtil') local util_table = require('Module:TableUtil') local util_text = require('Module:TextUtil') local util_title = require('Module:TitleUtil') local util_toggle = require("Module:ToggleUtil") local util_vars = require('Module:VarsUtil') local i18n = require('Module:i18nUtil') local Sprite = require('Module:Sprite').sprite

--- -- expectations of query param: -- tables include ScoreboardGames aliased as SG and Tournaments aliased as T ---

local h = {}

local p = {} function p.main(args, query) local argsCopy = mw.clone(args) h.castArgs(argsCopy) if not argsCopy.showrecentgame then return '' end i18n.init('MostRecentGameIncluded') local recentGameQuery = h.getRecentGameQuery(query) local game = util_cargo.getOneRow(recentGameQuery) if not game then return '' end return h.makeOutput(game) end

function h.castArgs(argsCopy) argsCopy.showrecentgame = true --util_args.castAsBool(argsCopy.showrecentgame) end

function h.getRecentGameQuery(query) local newQuery = mw.clone(query) newQuery.fields = { 'SG.Team1 [team]', 'SG.Team2 [team]', 'SG.Winner [number]', 'SG.Team1Picks [ChampionList]', 'SG.Team2Picks [ChampionList]', 'T.OverviewPage', 'T.StandardName', }	newQuery.orderBy = 'SG.DateTime_UTC DESC' newQuery.limit = 1 return newQuery end

function h.makeOutput(game) local output = mw.html.create output:wikitext(i18n.print('mrgi_intro')) util_toggle.printSimpleToggleButton(output, true) local dl = output:tag('dl') :addClass('recentgame-wrapper') util_toggle.tagSimpleToggledContent(dl, true) local dd = dl:tag('dd') :addClass('recentgame') h.printGame(dd, game) return output end

function h.printGame(dd, game) h.printOneTeam(dd, game, 1) dd:wikitext(i18n.print('vs')) h.printOneTeam(dd, game, 2) end

function h.printOneTeam(dd, game, n)	local div = dd:tag('div') :addClass(h.getTeamClass(n == tonumber(game.Winner))) :addClass('recentgame-team-' .. n)	h.printChampions(div, game, n)	h.printTeam(div, game, n) end

function h.getTeamClass(isWinner) if not isWinner then return nil end return 'recentgame-winner' end

function h.printChampions(div, game, n) if not game['Team' .. n .. 'Picks'] then return end div:tag('div') :addClass('recentgame-champions') :wikitext(game['Team' .. n .. 'Picks']:images) end

function h.printTeam(div, game, n)	div:tag('div') :addClass('recentgame-team') :wikitext(game['Team' .. n]:flairlink{len="medium"}) end

return p