Documentation for this module may be created at Module:Weapons/nav/doc

local WeaponData = require([[Module:Weapons/ppdata]])

local function makeTooltip(dataParam, image, link, name)
	return string.format('<span class="tooltip" data-param="%s" data-param2="Weapons">[[File:%s|x19px]]&nbsp;<span style="border-bottom:1px dotted;">[[%s|%s]]</span></span>',
		dataParam,
		image or 'Panel.png',
		link,
		name or link
	)
end

local function makeGunTable(data)
	local subTable = mw.html.create('table')

	for _, v in ipairs(data) do
		subTable:addClass('Wikitable')
			:css('width', '100%')
			:css('font-size', 'small')
			:tag('tr')
				:tag('th')
					:addClass('navboxhead')
					:attr('colspan', '2')
					:wikitext(v.Type)
				:done()
			:done()

		local str, w, j
		for _, trigger in ipairs(v.Triggers) do
			str = {}
			for i, weap in ipairs(trigger.Weapons) do
				if weap.Family and weap.Name == weap.Family then
					j = 1
					table.insert(str, makeTooltip(weap.Name, weap.Image, weap.Name)..'&nbsp;(')
					while trigger.Weapons[i + j] and weap.Family == trigger.Weapons[i + j].Family do
						str[#str] = str[#str]..makeTooltip(trigger.Weapons[i + j].Name, trigger.Weapons[i + j].Image, trigger.Weapons[i + j].Name, WeaponData.gsub(trigger.Weapons[i + j].Name, weap.Family))..',&nbsp;'
						j = j + 1
					end
					str[#str] = string.sub(str[#str], 1, -8)
					if j > 1 then str[#str] = str[#str]..')' end
				elseif not weap.Family then
					table.insert(str, makeTooltip(weap.Name, weap.Image, weap.Name))
				end
			end
			str = table.concat(str, ' • ')

			subTable:tag('tr')
				:tag('td')
					:addClass('navboxgroup')
					:wikitext(trigger.Name)
				:done()
				:tag('td')
					:css('font-size', 'small')
					:css('font-weight', 'normal')
					:css('text-align', 'left')
					:wikitext(str)
				:done()
			:done()
		end
	end
	
	return subTable
end

local function makeMeleeTable(data)
	local subTable = mw.html.create('table')

	for _, v in ipairs(data) do
		subTable:addClass('Wikitable')
			:css('width', '100%')
			:css('font-size', 'small')
			:tag('tr')
				:tag('th')
					:addClass('navboxhead')
					:attr('colspan', '2')
					:wikitext(v.Type)
				:done()
			:done()

		local str, w, j
		for _, class in ipairs(v.Classes) do
			str = {}
			for i, weap in ipairs(class.Weapons) do
				if weap.Family and weap.Name == weap.Family then
					j = 1
					table.insert(str, makeTooltip(weap.Name, weap.Image, weap.Name)..'&nbsp;(')
					while class.Weapons[i + j] and weap.Family == class.Weapons[i + j].Family do
						str[#str] = str[#str]..makeTooltip(class.Weapons[i + j].Name, class.Weapons[i + j].Image, class.Weapons[i + j].Name, WeaponData.gsub(class.Weapons[i + j].Name, weap.Family))..',&nbsp;'
						j = j + 1
					end
					str[#str] = string.sub(str[#str], 1, -8)
					if j > 1 then str[#str] = str[#str]..')' end
				elseif not weap.Family then
					table.insert(str, makeTooltip(weap.Name, weap.Image, weap.Name))
				end
			end
			str = table.concat(str, ' • ')

			subTable:tag('tr')
				:tag('td')
					:addClass('navboxgroup')
					:wikitext(class.Name)
				:done()
				:tag('td')
					:css('font-size', 'small')
					:css('font-weight', 'normal')
					:css('text-align', 'left')
					:wikitext(str)
				:done()
			:done()
		end
	end
	
	return subTable
end

return {
buildWeaponNav = function(frame)
    local data = WeaponData.ppData();
    
    local navTable = mw.html.create('table')
		:addClass('navbox mw-collapsible mobile-hidden')
		:tag('tr')
			:tag('th')
				:css('text-align', 'center')
				:wikitext('[[Weapons]] • [[Damage]] • [[{{#ifeq:{{NAMESPACE}}|Conclave|PvP Weapon Comparison|Weapon Comparison}}|Compare All]] • [[Weapon Cosmetics|Cosmetics]]')
			:done()
		:done()
		:tag('tr')
			:tag('th')
				:css('padding', '0')
				:tag('div')
					:addClass('tabber-borderless')
					:tag('tabber')
						:wikitext('|-|Primaries= '):node(makeGunTable(data.Primary))
						:wikitext('|-|Secondaries= '):node(makeGunTable(data.Secondary))
						:wikitext('|-|Melees= '):node(makeMeleeTable(data.Melee))
						:wikitext('|-|Archwing= '):node(makeMeleeTable(data.Archwing))
						:wikitext('|-|Robotic= '):node(makeGunTable(data.Robotic))
					:done()
				:done()
			:done()
		:done()
		
	return frame:preprocess(tostring(navTable))
end
}
Community content is available under CC-BY-SA unless otherwise noted.