Documentation for this module may be created at Module:Infobox road/map/doc

local p = {}
local format = mw.ustring.format

local mapsizes = {
	DEU = "200",
}

local function cleanName(name)
	name = mw.text.trim(name or '')
	name = name:gsub('^[Ff]ile:', '')
	name = name:gsub('^[Ii]mage:', '')
	return name
end

function p._map(args)
	local map = args.map or ''

	if args.map_custom == "yes" then
		if mw.text.trim(map) == '' then
			return nil
		end
		return format('<div style="white-space:nowrap;">%s</div>', map)
	end

	map = cleanName(map)
	if map == '' then
		return nil
	end

	local mapsize = mapsizes[args.country] or '290'
	local alt = args.map_alt or ''
	return format('[[File:%s|%spx|alt=%s]]', map, mapsize, alt)
end

function p.map(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local state = args.state or args.province
	if not args.country and state and state ~= '' then
		local ok, countryMask = pcall(mw.loadData, 'Module:Road data/countrymask')
		if ok and countryMask then
			args.country = countryMask[state]
		end
	end
	return p._map(args)
end

return p