Module:ForgingBondsTable

local cargo = mw.ext.cargo local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local Datetime = require 'Module:DatetimeUtil' local p = {}

function p.main(frame) local fbQuery = cargo.query(		"ForgingBonds,ForgingBonds__Accessories",		"_pageName=pgname,Name=name,GROUP_CONCAT(DISTINCT ForgingBonds__Accessories._value SEPARATOR ',')=alist,StartTime=st,EndTime=et", {			join = "ForgingBonds._ID=ForgingBonds__Accessories._rowID",			orderBy = "StartTime",			groupBy = "WikiName",			limit = 5000,		})

local fbHeroes = List.group_by(cargo.query('ForgingBondsHeroes=FBH,Units=U', "FBH._pageName=page,Color,IFNULL(CONCAT(Name,': ',Title),Name)=unit", { join = 'FBH.Hero=U.WikiName', groupBy = 'FBH._pageName,Color', limit = 500, }), function (v) return v.page end) Hash.map_self(fbHeroes, function (vs)		return Hash.from_ipairs(vs, function (v) return v.Color, v.unit end)	end)

local fbAccRewards = List.group_by(cargo.query('ForgingBondsRewards', '_pageName,Accessory', { where = "Kind='accessory' AND Accessory IS NOT NULL", groupBy = '_pageName,Accessory', orderBy = "Score,IF(Color='red',1,IF(Color='orange',2,IF(Color='green',3,4)))", limit = 500, }), function (v) return v._pageName end) Hash.map_self(fbAccRewards, function (vs)		return List.map_self(vs, function (v) return v.Accessory end)	end)

local tbl = mw.html.create("table"):addClass("wikitable"):addClass("default"):css("text-align", "center") local row = tbl:tag("tr") row:tag("th"):attr("rowspan", 2):attr('scope', 'col'):wikitext("Name") row:tag("th"):attr("colspan", 4):attr('scope', 'colgroup'):wikitext("Current Event Characters") row:tag("th"):attr("rowspan", 2):attr('scope', 'col'):css('width', '200px'):wikitext("Bonus Accessories") row:tag("th"):attr("rowspan", 2):attr('scope', 'col'):css('width', '200px'):wikitext("Reward Accessories") row:tag("th"):attr("rowspan", 2):attr('scope', 'col'):wikitext("Event Dates")

row = tbl:tag("tr") row:tag("th"):attr('scope', 'col'):wikitext("") row:tag("th"):attr('scope', 'col'):wikitext("") row:tag("th"):attr('scope', 'col'):wikitext("") row:tag("th"):attr('scope', 'col'):wikitext("")

for _, fb in ipairs(fbQuery) do		row = tbl:tag("tr") row:tag("td"):wikitext(			frame:expandTemplate {title = "Banner Event", args = {bannerType = "Forging Bonds", text1 = fb["name"], fontSize = 4, link = fb["pgname"]}},			(' Forging Bonds: %s'):format(fb.pgname, fb.name)) local heroes = fbHeroes[fb.pgname] or {} row:tag("td"):wikitext(frame:expandTemplate {title = 'UnitIcon', args = {name = heroes.red, size = '50px'}}) row:tag("td"):wikitext(frame:expandTemplate {title = 'UnitIcon', args = {name = heroes.orange, size = '50px'}}) row:tag("td"):wikitext(frame:expandTemplate {title = 'UnitIcon', args = {name = heroes.green, size = '50px'}}) row:tag("td"):wikitext(frame:expandTemplate {title = 'UnitIcon', args = {name = heroes.blue, size = '50px'}}) row:tag("td"):wikitext(table.concat(List.map(mw.text.split(fb.alist, '%s*,%s*'), function (v)			return frame:expandTemplate {title = "IconFrame", args = {accessory = v}}		end), ' ')) row:tag('td'):wikitext(table.concat(List.map(fbAccRewards[fb.pgname] or {}, function (v)			return frame:expandTemplate {title = 'IconFrame', args = {accessory = v}}		end), ' '))

row:tag("td"):wikitext(Datetime.ht_range(fb.st, fb.et)) end

return tostring(tbl) end

return p