Module:Infobox road/color
local p = {}
 
 Country = {}
 
 function Country:new(obj)
 	obj = obj or {}
 	setmetatable(obj, self)
 	self.__index = self
 	return obj
 end
 
 function Country:color(args)
 	local type = args.type
 	return self[type] or self.default
 end
 
 function Country:addTypesAsColor(types, color)
 	for i,type in pairs(types) do
 		self[type] = color
 	end
 end
 
 local colors = {}
 do
 	function colors:color(args)
 		local headerType = args.headerType
 		local countryArg = args.country
 		local headerTypeColor = self[headerType]
 		if headerTypeColor then return headerTypeColor end
 		local success, country = pcall(self.country, self, countryArg)
 		if not(success) then
 			return 'background:#cedff2;'
 		else
 			return country:color(args)
 		end
 	end
 	function colors:country(name)
 		local color = self[name]
 		if color then return color end
 		if name == 'CAN' or name == 'GBR' then
 			local module = require(string.format(&quot;Module:Infobox road/color/%s&quot;, name))
 			return module.colors
 		else
 			error(&quot;Country not included&quot;, 0)
 		end
 	end
 	
 	do -- Single-color countries
 		colors.BEL = Country:new{default = &quot;background:#0071B3; color:#fff;&quot;}
 		colors.BGD = Country:new{default = &quot;background:#2C6700; color:white;&quot;}
 		colors.CHN = Country:new{default = &quot;background:#006A4D; color:white;&quot;}
 		colors.ECU = Country:new{default = &quot;background:#006A4D; color:#fff;&quot;}
 		colors.EST = Country:new{default = &quot;background:#0079C1; color:white;&quot;}
 		colors.EUR = Country:new{default = &quot;background:#08842C; color:#fff;&quot;}
 		colors.JOR = Country:new{default = &quot;background:#0079C1; color:white;&quot;}
 		colors.HKG = Country:new{default = &quot;background:#006A4D; color:#fff;&quot;}
 		colors.ISL = Country:new{default = &quot;background:#FFD200; border:1px solid #000;&quot;}
 		colors.MEX = Country:new{default = &quot;background:#006A4D; color:white;&quot;}
 		colors.NZL = Country:new{default = &quot;background:#006A4D; color:#fff;&quot;}
 		colors.UKR = Country:new{default = &quot;background:#003F87; color:white;&quot;}
 		colors.URY = Country:new{default = &quot;background:#006A4D; color:white;&quot;}
 		colors.VNM = Country:new{default = &quot;background:#003399; color:white;&quot;}
 	end -- Single-color countries
 	
 	do -- Multi-color countries
 		do -- Albania
 			local ALB = Country:new{default = &quot;background:#00408B; color:#fff;&quot;}
 			ALB:addTypesAsColor({&quot;A&quot;}, &quot;background:#08842C; color:#fff;&quot;)
 			colors.ALB = ALB
 		end -- Albania
 		do -- Asian Highway Network
 			local ASIA = Country:new{default = &quot;background:#fff; border:1px solid #000;&quot;}
 			ASIA:addTypesAsColor({&quot;AH&quot;}, &quot;background:#1e2c76; color:white;&quot;)
 			colors.ASIA = ASIA
 		end -- Asian Highway Network
 		do -- Australia
 			local AUS = Country:new{default = &quot;background:#3A7119; color:#FFE133;&quot;}
 			AUS:addTypesAsColor({&quot;freeway&quot;}, &quot;background:#D2E2F9;&quot;)
 			AUS:addTypesAsColor({&quot;highway&quot;, &quot;city highway&quot;}, &quot;background:#E9F9D2;&quot;)
 			AUS:addTypesAsColor({&quot;road&quot;, &quot;rural road&quot;}, &quot;background:#FFFFE0;&quot;)
 			AUS:addTypesAsColor({&quot;street&quot;}, &quot;background:#F9E2D2;&quot;)
 			AUS:addTypesAsColor({&quot;track&quot;}, &quot;background:#fee8ab;&quot;)
 			colors.AUS = AUS
 		end -- Australia
 		do -- Austria
 			local AUT = Country:new{default = &quot;background:#fff; border:1px solid #000;&quot;}
 			AUT:addTypesAsColor({&quot;A&quot;, &quot;S&quot;, &quot;B&quot;}, &quot;background:#276FB7; color:#fff;&quot;)
 			colors.AUT = AUT
 		end -- Austria
 		do -- Bosnia and Herzegovina
 			local BIH = Country:new{default = &quot;background:#0B8F4B; color:white;&quot;}
 			BIH:addTypesAsColor({&quot;M&quot;, &quot;B&quot;}, &quot;background:#0066CC; color:white;&quot;)
 			BIH:addTypesAsColor({&quot;R&quot;}, &quot;background:#FFCC33; border:1px solid #000;&quot;)
 			colors.BIH = BIH
 		end -- Bulgaria		
 		do -- Bulgaria
 			local BGR = Country:new{default = &quot;background:#003F87; color:white;&quot;}
 			BGR:addTypesAsColor({&quot;A&quot;}, &quot;background:#006A4D; color:white;&quot;)
 			colors.BGR = BGR
 		end -- Bulgaria
 		do -- Croatia
 			local HRV = Country:new{default = &quot;background:#cedff2;&quot;}
 			HRV:addTypesAsColor({&quot;E&quot;, &quot;A&quot;}, &quot;background:#08842C; color:#fff;&quot;)
 			HRV:addTypesAsColor({&quot;D&quot;}, &quot;background:#0066CC; color:#fff;&quot;)
 			HRV:addTypesAsColor({&quot;Z&quot;}, &quot;background:#FFCC33; color:black;&quot;)
 			colors.HRV = HRV
 		end -- Croatia
 		do -- Cyprus
 			local CYP = Country:new{default = &quot;background:#003F87; color:#FFC000;&quot;}
 			CYP:addTypesAsColor({&quot;A&quot;}, &quot;background:#005024; color:#FFC000;&quot;)
 			colors.CYP = CYP
 		end -- Cyprus
 		do -- Czech Republic
 			local CZE = Country:new{default = &quot;background:#003F87; color:white;&quot;}
 			CZE:addTypesAsColor({&quot;D&quot;, &quot;R&quot;}, &quot;background:#006A4D; color:white;&quot;)
 			colors.CZE = CZE
 		end -- Czech Republic
 		do -- Denmark
 			local DNK = Country:new{default = &quot;background:#039; color:#fff;&quot;}
 			DNK:addTypesAsColor({&quot;E&quot;, &quot;M&quot;}, &quot;background:#006A4D; color:#fff;&quot;)
 			DNK:addTypesAsColor({&quot;S&quot;}, &quot;background:#fff; border:1px solid #af1e2d; color:#af1e2d;&quot;)
 			colors.DNK = DNK
 		end -- Denmark
 		do -- France
 			local FRA = Country:new{default = &quot;background:#fff; border:1px solid #000;&quot;}
 			FRA:addTypesAsColor({&quot;A&quot;}, &quot;background:#0079C1; color:#fff;&quot;)
 			FRA:addTypesAsColor({&quot;N&quot;}, &quot;background:#006A4D; color:#fff;&quot;)
 			colors.FRA = FRA
 			colors.MTQ = FRA
 		end -- France
 		do -- Georgia
 			local GEO = Country:new{default = &quot;background:#cedff2;&quot;}
 			GEO:addTypesAsColor({&quot;A&quot;, &quot;International&quot;}, &quot;background:#039; color:#fff;&quot;)
 			colors.GEO = GEO
 		end -- Georgia
 		do -- Germany
 			local DEU = Country:new{default = &quot;background:#cedff2;&quot;}
 			DEU:addTypesAsColor({&quot;A&quot;, &quot;Autobahn&quot;}, &quot;background:#039; color:#fff;&quot;)
 			DEU:addTypesAsColor({&quot;B&quot;, &quot;Bundesstraße&quot;, &quot;Bundesstrasse&quot;}, &quot;background:#FC3; color:black&quot;)
 			DEU:addTypesAsColor({&quot;E&quot;}, &quot;background:#08842C; color:#fff;&quot;)
 			colors.DEU = DEU
 		end -- Germany
                 do -- Ghana
 			local GHA = Country:new{default = &quot;background:#006A4D; color:#FFF;&quot;}
 			GHA:addTypesAsColor({&quot;N&quot;}, &quot;background:#0079C1; color:#FFF;&quot;)
 			colors.GHA = GHA
 		end -- Ghana
 		do -- Greece
 			local GRC = Country:new{default = &quot;background:#0079C1; color:#FFF;&quot;}
 			GRC:addTypesAsColor({&quot;A&quot;}, &quot;background:#006A4D; color:#FFF;&quot;)
 			colors.GRC = GRC
 		end -- Greece
 		do -- Hungary
 			local HUN = Country:new{default = &quot;background:#006A4D; color:#fff;&quot;}
 			HUN:addTypesAsColor({&quot;M&quot;}, &quot;background:#0079C1; color:#fff;&quot;)
 			colors.HUN = HUN
 		end -- Hungary
                 do -- Iran
 			local IRN = Country:new{default = &quot;background:#cedff2;&quot;}
 			IRN:addTypesAsColor({&quot;freeway&quot;}, &quot;background:#06c; color:#fff;&quot;)
 			IRN:addTypesAsColor({&quot;expressway&quot;}, &quot;background:#22B14C; color:#fff;&quot;)
 			IRN:addTypesAsColor({&quot;road&quot;}, &quot;background:#22B14C; color:#fff;&quot;)
 			IRN:addTypesAsColor({&quot;boulevard&quot;}, &quot;background:#fff; color:#000;&quot;)
 			IRN:addTypesAsColor({&quot;street&quot;}, &quot;background:#fff; color:#000;&quot;)
 			colors.IRN = IRN
 		end -- Iran
 		do -- Republic of Ireland
 			local IRL = Country:new{default = &quot;background:#cedff2;&quot;}
 			IRL:addTypesAsColor({&quot;M&quot;}, &quot;background:#0079C1; color:#fff;&quot;)
 			IRL:addTypesAsColor({&quot;N&quot;}, &quot;background:#00703C; color:#FFD200;&quot;)
 			IRL:addTypesAsColor({&quot;R&quot;}, &quot;background:#fff; border:1px solid #000;&quot;)
 			colors.IRL = IRL
 		end -- Republic of Ireland
 		do -- Italy
 			local ITA = Country:new{default = &quot;background:#cedff2;&quot;}
 			ITA:addTypesAsColor({&quot;A&quot;}, &quot;background:#08842C; color:#fff;&quot;)
 			ITA:addTypesAsColor({&quot;SS&quot;}, &quot;background:#003F87; color:#fff;&quot;)
 			ITA:addTypesAsColor({&quot;E&quot;}, &quot;background:#08842C; color:#fff;&quot;)
 			colors.ITA = ITA
 		end -- Italy
                 do -- Kosovo
 			local KOS = Country:new{default = &quot;background:#0066cc; color:#fff;&quot;}
 			KOS:addTypesAsColor({&quot;R&quot;}, &quot;background:#009933; color:#fff;&quot;)
 			KOS:addTypesAsColor({&quot;E&quot;}, &quot;background:#08842C; color:#fff;&quot;)
 			colors.KOS = KOS
 		end -- Netherlands
 		do -- Netherlands
 			local NLD = Country:new{default = &quot;background:#0079C1; color:#fff;&quot;}
 			NLD:addTypesAsColor({&quot;E&quot;}, &quot;background:#08842C; color:#fff;&quot;)
 			colors.NLD = NLD
 		end -- Netherlands
 		do -- Malaysia
 			local MYS = Country:new{default = &quot;background:#0079C1; color:#fff;&quot;}
 			MYS:addTypesAsColor({&quot;E&quot;}, &quot;background:#006A4D; color:#fff;&quot;)
 			colors.MYS = MYS
 		end -- Malaysia
         do -- Pakistan
 			local PAK = Country:new{default = &quot;background:#0066cc; color:#fff;&quot;}
 			PAK:addTypesAsColor({&quot;M&quot;}, &quot;background:#22B14C; color:#fff;&quot;)
 			PAK:addTypesAsColor({&quot;E&quot;}, &quot;background:#F5C31D; color:#000;&quot;)
 			colors.PAK = PAK
 		end -- Pakistan
 		do -- Poland
 			local POL = Country:new{default = &quot;background:#006A4D; color:#fff;&quot;}
 			POL:addTypesAsColor({&quot;A&quot;, &quot;S&quot;}, &quot;background:#0079C1; color:#fff;&quot;)
 			colors.POL = POL
 		end --Poland
 		do -- Slovakia
 			local SVK = Country:new{default = &quot;background:#0079C1; color:#fff;&quot;}
 			SVK:addTypesAsColor({&quot;D&quot;, &quot;R&quot;}, &quot;background:#006A4D; color:#fff;&quot;)
 			colors.SVK = SVK
 		end -- Slovakia
 		do -- South Africa
 			local ZAF = Country:new{default = &quot;background:#006A4D; color:#FFF;&quot;}
 			ZAF:addTypesAsColor({&quot;M&quot;, &quot;N&quot;}, &quot;background:#0079C1; color:#FFF;&quot;)
 			colors.ZAF = ZAF
 		end -- South Africa
 		do -- Spain
 			local ESP = Country:new{default = &quot;background:#E8E8E8;&quot;}
 			ESP:addTypesAsColor({&quot;A&quot;, &quot;AP&quot;, &quot;AS&quot;}, &quot;background:#039; color:#fff;&quot;)
 			ESP:addTypesAsColor({&quot;N&quot;}, &quot;background:#e41408; color:#fff;&quot;)
 			colors.ESP = ESP
 		end -- Spain
 		do -- Sri Lanka
 			local LKA = Country:new{default = &quot;background:#006A4D; color:#fff;&quot;}
 			LKA:addTypesAsColor({&quot;E&quot;}, &quot;background:#0079C1; color:#fff;&quot;)
 			LKA:addTypesAsColor({&quot;A&quot;}, &quot;background:#006A4D; color:#fff;&quot;)
 			colors.LKA = LKA
 		end -- Sri Lanka
 		do -- Switzerland
 			local CHE = Country:new{default = &quot;background:#cedff2;&quot;}
 			CHE:addTypesAsColor({&quot;E&quot;}, &quot;background:#08842C; color:#fff;&quot;)
 			colors.CHE = CHE
 		end -- Switzerland
 		do -- Turkey
 			local TUR = Country:new{default = &quot;background:#006A4D; color:#fff;&quot;}
 			TUR:addTypesAsColor({&quot;state&quot;, &quot;D&quot;}, &quot;background:#003F87; color:#fff;&quot;)
 			colors.TUR = TUR
 		end -- Turkey
 		do -- United States
 			local USA = Country:new{default = &quot;background:#006A4D; color:white;&quot;}
 			USA:addTypesAsColor({&quot;FFH&quot;, &quot;FR&quot;, &quot;NER&quot;, &quot;Rec&quot;, &quot;RE&quot;, &quot;Park&quot;}, &quot;background:#704214; color:white;&quot;)
 			colors.USA = USA
 		end -- United States
 	end -- Multi-color countries
 	
     do -- Built-in header types
 		colors[&quot;under construction&quot;] = &quot;background:#fc6;&quot;
 		colors[&quot;const&quot;] = &quot;background:#fc6;&quot;
 		colors[&quot;uc&quot;] = &quot;background:#fc6;&quot;
 		colors[&quot;historic&quot;] = &quot;background:#704214; color:white;&quot;
 		colors[&quot;historical&quot;] = &quot;background:#704214; color:white;&quot;
 		colors[&quot;hist&quot;] = &quot;background:#704214; color:white;&quot;
 		colors[&quot;scenic&quot;] = &quot;background:#704214; color:white;&quot;
 		colors[&quot;decommissioned&quot;] = &quot;background:#AAA;&quot;
 		colors[&quot;former&quot;] = &quot;background:#AAA;&quot;
 	end -- Built-in header types
 end
 
 function p._color(args)
 	return colors:color(args)
 end
 
 function p.color(frame)
 	local pframe = frame:getParent()
 	local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
 	local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
 	
 	local function emptyParam(param)
 		local empty = {[''] = true, ['¬'] = true}
 		if not(param) or empty[param] then
 			return nil
 		else
 			return param
 		end
 	end
 	
 	local state = config.state or args.state
 	state = emptyParam(state)
 	local province = config.province or args.province
 	province = emptyParam(province)
 	local type = config.type or args.type
 	local subtype = config.subtype or args.subtype or nil
 	
 	local headerType = args.header_type or config.header_type
 	headerType = emptyParam(headerType)
 	if headerType then
 		headerType = string.lower(headerType)
 	end
 	
 	local countryArg = config.country or args.country
 	countryArg = emptyParam(countryArg)
 	local country = countryArg
 	if not(country) then
 		if colors[headerType] then
 			country = ''
 		else
 			local stateParam = state or province
 			if not(stateParam) then
 				country = ''
 			else
 				local countryMask = require &quot;Module:Infobox road/meta/mask/country&quot;
 				country = countryMask._country(stateParam, countryArg)
 			end
 		end
 	end
 	
 	return p._color{country=country, state=state, province=province, type=type, subtype=subtype, headerType=headerType}
 end