Documentation for this module may be created at Module:Railway/format/doc

-- Format output of Module:Railway

local function station(lua_table)
	-- lua_table[i]["line"] = connecting line (with logo or color)
	-- lua_table[i]["part"] = connecting line part of (service)
	-- lua_table[i]["interchange"] = interchange station? true or false
	-- lua_table[i]["adjacent1"] = adjacent station 1
	-- lua_table[i]["towards1"] = towards 1
	-- lua_table[i]["adjacent2"] = adjacent station 2
	-- lua_table[i]["towards2"] = towards 2
	
	local interchange_icon = '[[File:Font Awesome 5 solid exchange-alt.svg|frameless|right|20x20px|link='
		.. (mw.wikibase.getSitelink('Q1147171') or 'd:Q1147171') .. ']]'
	
	local html_table = mw.html.create('table')
	html_table
		:addClass('wikitable')
		:css('margin', '0 auto')
		:css('text-align', 'center')
	local part_of
	for _, line_data in ipairs(lua_table) do
		if line_data["part"] ~= part_of then -- new heading
			part_of = line_data["part"]
			html_table
				:newline()
				:tag('tr')
					:newline()
					:tag('th')
						:attr('colspan', '3')
						:css('background-color', 'white;')
						:wikitext(line_data["part"] .. (line_data["interchange"] and interchange_icon or ''))
						:done()
					:done()
				:newline()
				:tag('tr')
					:newline()
					:tag('th')
						:wikitext('Station <')
						:done()
					:tag('th')
						:wikitext('Line')
						:done()
					:tag('th')
						:wikitext('> Station')
						:done()
					:done()
		end
		html_table
			:newline()
			:tag('tr')
				:newline()
				:tag('td')
					:wikitext(line_data['adjacent1'])
					:tag('br')
						:done()
					:tag('span')
						:css('font-size', 'smaller;')
						:wikitext(line_data['towards1'] ~= '' and (' &rarr; ' .. line_data['towards1']) or '')
						:done()
					:done()
				:tag('td')
					:wikitext(line_data['line'])
					:done()
				:tag('td')
					:wikitext(line_data['adjacent2'])
					:tag('br')
						:done()
					:tag('span')
						:css('font-size', 'smaller;')
						:wikitext(line_data['towards2'] ~= '' and (' &rarr; ' .. line_data['towards2']) or '')
						:done()
					:done()
				:done()
	end
	
	return tostring(html_table)
end

return {
	station = station
}