Module:ListOfTeams

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 i18n = require('Module:i18nUtil')

local m_country = require('Module:Country') local m_region = require('Module:Region') local m_team = require('Module:Team')

local Socials = require('Module:Infobox/Social').makeSocialSection

local COLUMNS = { 'TeamDisplay', 'Socials', 'Roster' }

local h = {}

local p = {} function p.main(frame) local args = util_args.merge(true) i18n.init('ListOfTeams') h.castArgs(args) local data = util_cargo.queryAndCast(                                   h.makeQuery(args)                  ) h.formatRows(data) return h.makeOutput(data) end

function h.castArgs(args) args.region = args.region and m_region.medium(args.region) args.country = args.country and m_country.name(args.country) end

function h.makeAndRunQuery(args) return util_cargo.queryAndCast(h.makeQuery(args)) end

function h.makeQuery(args) local query = { tables = { 'Teams=T', 'ListplayerCurrent=LPC' }, join = { 'T._pageName=LPC.Team' }, fields = h.getFields, where = h.getWhere(args), orderBy = 'T._pageName ASC', oneToMany = { fields = { 'LPC.Link=Players' }, groupBy = { 'Team' }, },	}	return query end

function h.getFields return { 'T.Name=Team', 'T.Twitter=twitter', -- 'T.Youtube=youtube', 'T.Facebook=facebook', 'T.Instagram=instagram', 'T.Vk=vk', } end

function h.getWhere(args) local where = { args.region and ('Region="%s"'):format(args.region), args.country and ('Location="%s"'):format(args.country), 'IsDisbanded="0"', }	return util_cargo.concatWhere(where) end

function h.formatRows(data) util_map.rowsInPlace(data, h.formatOneRow) end

function h.formatOneRow(row) row.Roster = util_table.concat(row.Players, ' • ', util_esports.playerLinked) row.TeamDisplay = m_team.rightmediumlinked(row.Team) row.Socials = table.concat(Socials(row)) end

function h.makeOutput(data) local output = mw.html.create local tbl = output:tag('table') :addClass('wikitable') :addClass('sortable') util_html.printHeaderFromI18n(tbl, COLUMNS) util_html.printRowsByList(tbl, data, COLUMNS) return output end

return p