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 m_country = require('Module:Country') local m_region = require('Module:Region') local m_team = require('Module:Team') 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 = m_team.teamlinkname(pagename) local data = TeamMembers(team) 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 = m_region.onlyimage(row.Residency) row.Country = row.Country and m_country.onlyimage(row.Country) or '' row.Role = row.CompoundRole: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', where = ('_pageName="%s"'):format(pagename), types = { IsDisbanded = 'boolean' } }	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