Module:RosterTooltip

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_html = require('Module:HtmlUtil') local util_map = require('Module:MapUtil') local util_table = require('Module:TableUtil') local Team = require('Module:TeamClass') local i18n = require('Module:i18nUtil') local TeamMembers = require('Module:QueryTeamMembers').main

local COLUMNS = { 'Residency', 'Country', 'Role', 'ID', 'NameFull', }

local h = {}

local p = {} function p.main(frame) local args = util_args.merge i18n.init('RosterTooltip') local pagename = args.page or mw.title.getCurrentTitle.text if not mw.title.new(pagename).exists then return '' end local team = Team(pagename):get local data = TeamMembers(team, {hideTrainees = true}) if #data == 0 then return h.makeEmptyRosterTable(pagename, team) end util_map.rowsInPlace(data, h.processRow) return h.makeOutput(data, team) end

function h.processRow(row) row.Residency = row.Residency:image row.Country = row.Country:image row.Role = row.RoleList:images return end

function h.makeOutput(data, team) local tbl = h.initializeTable h.printHeadings(tbl, team) util_html.printRowsByList(tbl, data, COLUMNS) return tbl end

function h.printHeadings(tbl, team) util_html.printColspanHeader(tbl, i18n.print('title', team), #COLUMNS) local columnLabels = util_html.printHeaderFromI18n(tbl, COLUMNS) columnLabels:addClass('roster-tooltip-heading') end

function h.initializeTable local tbl = mw.html.create('table') :addClass('wikitable') :addClass('tippingover-tooltip') :addClass('tooltip-table') return tbl end

function h.makeEmptyRosterTable(pagename, team) if util_cargo.getOneResult(h.getDisbandedQuery(pagename)) then return h.printDisbandedTeam(team) else return h.printEmptyTable(team) end end

function h.getDisbandedQuery(pagename) local disbandedQuery = { tables = 'Teams', fields = 'IsDisbanded [boolean]', where = ('_pageName="%s"'):format(pagename), }	return disbandedQuery end

function h.printDisbandedTeam(team) local tbl = h.initializeTable tbl:tag('tr'):tag('th') :wikitext(i18n.print('disbandedHeading', team)) return tbl end

function h.printEmptyTable(team) local tbl = h.initializeTable h.printHeadings(tbl, team) tbl:tag('tr'):tag('td') :attr('colspan',#COLUMNS) :addClass('roster-tooltip-none') :wikitext(i18n.print('noResultsText')) return tbl end

return p