Module:Infobox road/sections
local p = {}
 
 local getArgs = require('Module:Arguments').getArgs
 local lengthModule = require(&quot;Module:Infobox road/length&quot;)
 local parserModule = require(&quot;Module:Road data/parser&quot;)
 local parser = parserModule.parser
 local frame = mw.getCurrentFrame()
 
 local function country(args)
 	local state = args.state or args.province
 	local country
 	local countryModule = mw.loadData(&quot;Module:Road data/countrymask&quot;)
 	local country = args.country or countryModule[state]
 	
 	return country
 end
 
 -- HEADER COLORS
 
 function p.headerStyle(args)
 	local deleted = args.decommissioned or args.deleted
 	local uc = args.header_type == &quot;under construction&quot; or args.header_type == &quot;const&quot; or args.header_type == &quot;uc&quot;
 	local minor = args.header_type == &quot;minor&quot;
 	local hist = args.header_type == &quot;hist&quot; or args.header_type == &quot;historic&quot; or args.header_type == &quot;historical&quot; or args.header_type == &quot;scenic&quot;
 	local color = parser(args, 'color')
 	
 	if freeway then
 		return &quot;header-MUTCDblue&quot;
 	elseif uc then
 		return &quot;header-uc&quot;
 	elseif minor then
 		return &quot;header-minor&quot;
 	elseif deleted and header == 'hist' or deleted and color == 'hist' then
 		return &quot;header-deleted-hist&quot;
 	elseif deleted then
 		return &quot;header-deleted&quot;
 	elseif hist then
 		return &quot;header-hist&quot;
 	elseif color then
 		return &quot;header-&quot; .. color
 	elseif args.state or args.province or args.country then
 		local country = country(args)
 		return &quot;header-&quot; .. country or &quot;header-default&quot;
 	else
 		return &quot;header-default&quot;
 	end
 end
 
 function p._section(args)
 	if args.section1 or args.length_km1 or args.length_mi1 or args.length_notes1 or args.direction_a1 or
 		args.terminus_a1 or args.junction1 or args.junctions1 or args.direction_b1 or args.terminus_b1 then
 	
 	local infobox_args = {
 		['child'] = &quot;yes&quot;,
 		['decat'] = &quot;yes&quot;,
 		['headerclass'] = p.headerStyle(args)
 	}
 	local i = 1
 	while (1) do
 		local num = i
 		local j = ((i - 1) * 5) + 1
 		local headern = &quot;header&quot; .. j
 		local lengthLabeln = &quot;label&quot; .. (j + 1)
 		local lengthDatan = &quot;data&quot; .. (j + 1)
 		local directionAn = &quot;label&quot; .. (j + 2)
 		local terminusAn = &quot;data&quot; .. (j + 2)
 		local jctClassn = &quot;class&quot; .. (j + 3)
 		local jctLabeln = &quot;label&quot; .. (j + 3)
 		local jctDatan = &quot;data&quot; .. (j + 3)
 		local directionBn = &quot;label&quot; .. (j + 4)
 		local terminusBn = &quot;data&quot; .. (j + 4)
 		
 		if args['section' .. i] or args[&quot;length_km&quot; .. i] or args[&quot;length_mi&quot; .. i] or args[&quot;length_notes&quot; .. i] or args[&quot;direction_a&quot; .. i] or
 			args[&quot;terminus_a&quot; .. i] or args[&quot;junction&quot; .. i] or args[&quot;junctions&quot; .. i] or args[&quot;direction_b&quot; .. i] or args[&quot;terminus_b&quot; .. i] then
 				
 			if i == 1 then
 				infobox_args['title'] = args['section' .. i] or &quot;Section &quot; .. i
 			else
 				infobox_args[headern] = args['section' .. i] or &quot;Section &quot; .. i
 			end
 		end
 		
 		infobox_args[lengthLabeln] = &quot;Length&quot;
 		infobox_args[lengthDatan] = lengthModule._length(num, args)
 
 		local dir_a = args[&quot;direction_a&quot; .. i] or args.direction_a or ''
 		if dir_a ~= '' then
 			infobox_args[directionAn] = dir_a .. &quot;&amp;nbsp;end&quot;
 		else
 			infobox_args[directionAn] = &quot;From&quot;
 		end
 
 		infobox_args[terminusAn] = args[&quot;terminus_a&quot; .. i]
 		infobox_args[jctClassn] = &quot;plainlist&quot;
 		infobox_args[jctLabeln] = &quot;Major intersections&quot;
 		infobox_args[jctDatan] = args[&quot;junction&quot; .. i] or args[&quot;junctions&quot; .. i]
 
 		local dir_b = args[&quot;direction_b&quot; .. i] or args.direction_b or ''
 		if dir_b ~= '' then
 			infobox_args[directionBn] = dir_b .. &quot;&amp;nbsp;end&quot;
 		else
 			infobox_args[directionBn] = &quot;From&quot;
 		end
 
 		infobox_args[terminusBn] = args[&quot;terminus_b&quot; .. i]
 		
 		if i == 25 then
 			break
 		else
 			i = i + 1
 		end
 	end
 
 	return frame:expandTemplate ({title='Infobox', args = infobox_args})
 	
 	else return nil
 	end
 end
 
 function p.section(frame)
 	args = getArgs(frame)
 	return p._section(args)
 end
 
 local function loop(args)
 	local ring_road = args.ring_road or ''
 	if ring_road ~= '' then
 		return &quot;[[Ring road]] around &quot; .. ring_road
 	end
 	local beltway_city = args.beltway_city or ''
 	if beltway_city ~= '' then
 		return &quot;[[Beltway]] around &quot; .. beltway_city
 	end
 	local orbital = args.orbital or ''
 	if orbital ~= '' then
 		return &quot;[[Orbital road|Orbital]] around &quot; .. orbital
 	end
 	local loop = args.loop or ''
 	if loop ~= '' then
 		return &quot;[[Loop road|Loop]] around &quot; .. loop
 	end
 	local tloop = args.tloop or ''
 	if tloop == 'none' then
 		return &quot;Tourist loop&quot;
 	elseif tloop ~= '' then
 		return &quot;Tourist loop around &quot; .. tloop
 	end
 	return nil
 end
 
 function p._main(args)
 	
 	if args.terminus_a or args.junction or args.junctions or args.terminus_b or args.ring_road or args.beltway_city or
 		args.orbital or args.loop or args.tloop then
 	
 		local infobox_args = {
 			['child'] = &quot;yes&quot;,
 			['decat'] = &quot;yes&quot;,
 		}
 		
 		infobox_args['title'] = args.section0 or &quot;Major junctions&quot;
 		infobox_args['data1'] = loop(args)
 	
 		local dir_a = args.direction_a or ''
 		if dir_a ~= '' then
 			infobox_args['label2'] = dir_a .. &quot;&amp;nbsp;end&quot;
 		else
 			infobox_args['label2'] = &quot;From&quot;
 		end
 	
 		infobox_args['data2'] = args.terminus_a
 		infobox_args['class3'] = &quot;plainlist&quot;
 		infobox_args['label3'] = &quot;&lt;span style='display:none;'&gt;Major intersections&lt;/span&gt;&quot;
 		infobox_args['data3'] = args.junction or args.junctions
 	
 		local dir_b = args.direction_b or ''
 		if dir_b ~= '' then
 			infobox_args['label4'] = dir_b .. &quot;&amp;nbsp;end&quot;
 		else
 			infobox_args['label4'] = &quot;To&quot;
 		end
 	
 		infobox_args['data4'] = args.terminus_b
 	
 		return frame:expandTemplate ({title='Infobox', args = infobox_args})
 		
 	else
 		return nil
 	end
 end
 
 function p.main(frame)
 	args = getArgs(frame)
 	return p._main(args)
 end