Module:RostersStart

local util_args = require('Module:ArgsUtil') local util_esports = require('Module:EsportsUtil') local util_form = require('Module:FormUtil') 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 i18n = require('Module:i18nUtil')

local TOGGLE_DATA = { show_attr = '.RosterPlayers', hide_attr = '.RosterLogos', show_class = 'RosterPlayers', hide_class = 'RosterLogos', }

local FORM_INFO = { form = 'TournamentPlayerInformation', template = 'TPI' }

local h = {} local p = {} function p.main(frame) i18n.init('RostersStart') local args = util_args.merge local overviewPage = util_esports.getOverviewPage(args.page) local output = { h.addShowHideButton, h.addLinks(args, overviewPage), h.addMaxTeams(args.maxteams, args.pools), }	return util_table.concat(output, '') end

function h.addShowHideButton TOGGLE_DATA.show_text = i18n.print('show_text') TOGGLE_DATA.hide_text = i18n.print('hide_text') return tostring(util_toggle.printSectionToggler(nil, TOGGLE_DATA)) end

function h.addLinks(args, page) local displays = h.getDisplays(args) local links = h.getLinks(args, page) return tostring(h.makeLinkButtons(displays, links)) end

function h.getDisplays(args) local displays = { args.rosterswaps and 'swaps', util_args.castAsBool(args.showrosterpage) and 'byGame', 'chart' }	return util_table.removeFalseEntries(displays) end

function h.getLinks(args, page) local links = { util_args.nilToFalse(args.rosterswaps), util_args.castAsBool(args.showrosterpage) and h.getRosterPage(args.rosterpage, page), util_form.fullURL(FORM_INFO, { page = page }) }	return util_table.removeFalseEntries(links) end

function h.getRosterPage(rosterpage, page) if rosterpage then return rosterpage end return page .. '/Team Rosters' end

function h.makeLinkButtons(displays, links) local tbl = mw.html.create for k, v in ipairs(displays) do		tbl:tag('div') :addClass('external-link-button') :addClass('plainlinks') :wikitext(util_text.link(links[k], i18n.print(v))) end return tbl end

function h.addMaxTeams(maxteams, pools) local poolclass = util_args.castAsBool(pools) and 'pools' or 'tournament-rosters' if util_args.castAsBool(maxteams) then return (' '):format(poolclass, maxteams) else -- empty div so people can always put an 'end' at the end of the section return (' '):format(poolclass) end end

return p