Module:ExtendedRosterStart

local util_args = require('Module:ArgsUtil') local util_map = require('Module:MapUtil') local util_table = require('Module:TableUtil') local util_vars = require('Module:VarsUtil') local Team = require('Module:TeamClass') local COLS = { 'res', 'country', 'role', 'id', 'name', res = { text = '', width = "26px", class = 'res' }, country = { text = '', width = "28px", class = 'country' }, role = { text = '', width = "27px", class = 'role' }, id = { text = 'ID', width = '100px', class = 'id' }, name = { text = 'Name', width = '170px', class = 'name' }, }

local h = {} local p = {} function p.main(frame) local args = util_args.merge util_vars.setBool('nores',args.nores) local cols = h.setCols(args) local output = { ' ',		h.tableInit(util_args.castAsBool(args.nores)), h.makeOutput(cols) }	return util_table.concat(output, '', tostring) end

function h.setCols(args) local cols = mw.clone(COLS) h.setWidths(cols, args) if util_args.castAsBool(args.nores) then table.remove(cols,1) end h.addTeamCols(cols, args) return cols end

function h.addTeamCols(cols, args) local teamsize = h.getTeamsize(args) local rounds = tonumber(args.rounds or 0) or 0 local i = 1 while args['team' .. i] or args['round' .. i] or i <= rounds do cols[#cols+1] = 'team' .. i cols['team' .. i] = { text = h.getColTitle(args, i, teamsize), class = 'unsortable round' }		i = i + 1 end end

function h.getTeamsize(args) if args.teamsize then return args.teamsize elseif args.team15 or args.round15 then return 45 else return 40 end end

function h.getColTitle(args, i, teamsize) if args['team' .. i] then return Team(args['team' .. i]):imagelink{ size = teamsize } elseif args['round' .. i] then return args['round' .. i]	else return 'R' .. i	end end

function h.setWidths(cols, args) if args['id-width'] then cols[4].width = args['id-width'] cols[5].width = args['name-width'] end end

function h.tableInit(nores) local resclass = nores and h.getClass('nores') or h.getClass('hasres') return (' '):format(resclass) end

function h.makeOutput(cols) local tr = mw.html.create('tr') for _, v in ipairs(cols) do		local col = cols[v] tr:tag('th') :wikitext(col.text) :addClass(h.getClasses(col.class)) :css('width', col.width) :css('min-width', col.width) end return tr end

function h.getClasses(str) if not str then return nil end return util_map.splitAndConcat(str, ' ', h.getClass, ' ') end

function h.getClass(str) if not str then return nil elseif str == 'unsortable' then return str else return 'extended-rosters-' .. str end end

return p