Module:Legend

local util_args = require('Module:ArgsUtil') local util_text = require('Module:TextUtil') local util_toggle = require("Module:ToggleUtil")

local ORDER = { 'upwith3bye', 'upwith2bye', 'semifinals', 'upwithbye', 'proceed', 'up', 'stayup', 'stay', 'staydown', 'down', 'drop', 'autorelegate', 'clinch-up', 'clinch-down', 'boldtext', 'incomplete', 'specialqualify' }

local p = {} local h = {} function p.main(frame) local args = util_args.merge local th = mw.html.create p._main(th, args) return th end

function p._main(th, args) local outerdiv = th:tag('div') :wikitext(args.display or 'Standings') :css({position = 'relative'}) local button = util_toggle.popupButton(outerdiv) button.button:addClass('legend-icon') :addClass('table-header-rightcontent') button.inner:addClass('legend-table') :css({			['margin-left'] = (((args.legendwidth or 8) - 250) / 2) .. 'px',			width = '250px'		 }) local tbl = button.inner:tag('table') :addClass('legend-table') h.printLegendTable(tbl, args, util_text.splitOrNil(args.legendorder) or ORDER) return outerdiv end

function h.printLegendTable(tbl, args, order) h.printTableHeader(tbl) for _, v in ipairs(order) do h.printLegendRow(tbl, v, args[v], args[v .. 'css']) end end

function h.printTableHeader(tbl) local tr = tbl:tag('tr') tr:tag('th') :addClass('legend-header') :wikitext('Legend') end

function h.printLegendRow(tbl, class, display, css) if not display then return end local tr = tbl:tag('tr') tr:tag('td') :addClass('standings-' .. class) :cssText(css) :wikitext(display) end

return p