Module:TeamRoster

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_map = require('Module:MapUtil') local util_table = require('Module:TableUtil') local util_text = require('Module:TextUtil') local util_toggle = require('Module:ToggleUtil') local util_vars = require('Module:VarsUtil') local m_team = require('Module:Team')

local StoreTournamentRoster = require('Module:StoreTournamentRoster')

local lang = mw.getLanguage('en')

local h = {}

local p = {} function p.main(frame) local args = util_args.merge h.castArgs(args) return p._main(args) end

function p._main(args) StoreTournamentRoster.init local playerData = StoreTournamentRoster.getPlayerData(args) local teamData = StoreTournamentRoster.getTeamData(args, playerData) StoreTournamentRoster.store(playerData, teamData, args) return h.makeOutput(playerData, teamData, args) end

function h.castArgs(args) if args.team then args.team = m_team.teamlinkname(args.team) end end

function h.makeOutput(playerData, teamData, args) util_toggle.initSectionToggler local tbl = h.initTable h.printCaption(tbl, args.seed) h.printHeader(tbl, teamData.Team, args.footnoteteamn) h.printLogo(tbl, teamData.Team) h.printPlayers(tbl, playerData) return tbl end function h.initTable local tbl = mw.html.create('table') :addClass('wikitable tournament-roster') return tbl end

function h.printCaption(tbl, seed) tbl:tag('caption') :addClass('tournament-roster-span') :wikitext(seed) end

function h.printHeader(tbl, team, footnoten) local th = tbl:tag('tr'):tag('th') :addClass('tournament-roster-header') local outerdiv = th:tag('div') :css('position','relative') h.printNameAndFootnote(outerdiv, team, footnoten) local innerdiv = outerdiv:tag('div') :css({ position = "absolute", right = "2px", top = '0' }) h.printOneToggler(innerdiv, 'Show', 'RosterLogos', false) h.printOneToggler(innerdiv, 'Hide', 'RosterPlayers', true) end

function h.printNameAndFootnote(div, team, footnoten) div:wikitext(m_team.mediumplainlinked(team)) :wikitext(util_html.makeFootnoteN(footnoten)) end

function h.printOneToggler(div, image, class, isHidden) local span = div:tag('span') :addClass(class) :wikitext((''):format(image)) util_toggle.tagSectionToggler(span, isHidden) end

function h.printLogo(tbl, team) local logo_tr = tbl:tag('tr') :addClass('RosterLogos') local logo = logo_tr:tag('td') :addClass('tournament-roster-logo-cell') :wikitext(m_team.square(team, { size = 123, title = "Click to Show Roster" })) util_toggle.tagSectionToggler(logo_tr) end

function h.printPlayers(tbl, playerData) for _, player in ipairs(playerData) do		h.printOnePlayer(tbl, player) end end

function h.printOnePlayer(tbl, player) local tr = h.initPlayerRow(tbl) h.printPlayerCell(tr, player) end

function h.initPlayerRow(tbl) local tr = tbl:tag('tr') :addClass('RosterPlayers') util_toggle.tagSectionToggle(tr, true) return tr end

function h.printPlayerCell(tr, player) local td = tr:tag('td') :addClass('tournament-roster-player-cell') h.printRole(td, player.Role) h.printFlagAndName(td, player) end

function h.printRole(td, role) td:tag('span') :addClass('tournament-roster-role') :wikitext(role:images({sep=''})) end

function h.printFlagAndName(td, player) td:tag('span') :addClass('tournament-roster-player') :wikitext(player.Flag:image) :wikitext(' ') :wikitext(util_esports.playerLinked(player.Link)) if player.FootnoteN then td:wikitext(util_html.makeFootnoteN(player.FootnoteN)) end end

return p