--[==[
To inspect the content of this data module, use [[Special:ExpandTemplates]]
and enter the following input text:
  {{#invoke:Road data/dump|dump|module=Module:<name-of-this-module>}}

To inspect the content of this data module when editing, enter the following
into the Debug console:
  local util = require("Module:Road data/util")
  print(util.arrayToString(p))
To inspect a particular route type, change `p` above to include the route type,
e.g., `p.I` and `p["US-Hist"]`.
]==]

-- Virginia
local VA = {}

local util = require("Module:Road data/util")
local format = mw.ustring.format
util.addAll(VA, require("Module:Road data/strings/USA"))

local suffix = " ([dab||%dab%, |]Virginia)"
local suffix2 = " [dab||(%dab%)|]"

VA.I.link = "Interstate %route% (Virginia)"

for k, v in pairs(VA) do if k:find ("^I") then 
	v.link = VA.I.link
	end
end
VA["I-Express"].link = "Interstate %route% Express (Virginia)"        

VA.US.link = "U.S. Route %route% in Virginia"

for k, v in pairs(VA) do if k:find ("^US %d") then 
	v.link = VA.US.link
	end
end

for _,auxType in ipairs({"Alt", "Bus", "Byp", "City", "Conn", "Emerg", "Opt", "Scenic", "Spur", "Temp", "Toll", "Truck"}) do
	local spec = VA[" aux "][auxType]
		for k, v in pairs(VA) do if k:find (auxType) then if k:find ("^US") then
			v.link = VA.US.base .. " " .. spec.name .. suffix
			end
		end
	end
end

for _,type in ipairs({'US 1961'}) do
	for _,auxType in ipairs({"Alt", "Bus", "Byp", "Conn", "Spur", "Toll"}) do
		local spec = VA[" aux "][auxType]
		VA[type .. "-" .. auxType] = {
			shield = VA[type].shield,
			name = VA[type].name .. " " .. spec.name,
			link = VA[type].base .. " " .. spec.name .. suffix,
			abbr = VA[type].abbr .. " " .. spec.abbrsuffix,
			banner = spec.bannerprefix .. " plate.svg",
			aux = spec.aux,
			width = VA[type].width
		}
	end
end

VA["US-Alt-Bus"] = {
	shield = VA.US.shield,
	name = VA["US-Alt"].name .. " Business",
	link = "U.S. Route %route% Alternate Business ([dab||%dab%, |]Virginia)",
	abbr = "US&nbsp;%route% Alt. Bus.",
	banner = "Business alternate plate.svg",
	width = "expand",
	aux = VA[" aux "].Bus,
}

VA["US-Old"] = {
	shield = VA.US.shield,
	name = VA.US.name .. " Business",
	link = VA.US.link,
	abbr = VA.US.abbr,
	banner = "Old plate.svg",
	width = "expand"
}

VA.SR = {
	shield = {
		default = "Virginia %route%.svg",
		["90000"] = "",
		["90004"] = ""
	},
	shieldmain = {
		default = "Virginia %route%.svg",
		["102"] = {"Virginia %route%.svg", "WV-%route%.svg"},
		["311"] = {"Virginia %route%.svg", "WV-%route%.svg"},
		["90000"] = "",
		["90004"] = ""
	},
	base = "Virginia State Route %route%",
	name = {
		default = "State Route %route%",
		["102"] = "Virginia State Route %route% and<br>West Virginia Route %route%",
		["311"] = "Virginia State Route %route% and<br>West Virginia Route %route%"
	},
	link = "Virginia State Route %route%[dab|| (%dab%)|]",
	abbr = "SR&nbsp;%route%",
	width = "expand"
	
}
VA.VA = VA.SR

VA.Sec = {
	shield = "Circle sign %route%.svg",
	name = VA.SR.name.default,
	link = {
		ifexists   = true,
		arg   = "county",
		default   = "Virginia State Route %route% (%county% County)",
		otherwise   = VA.SR.link
	},
	abbr = VA.SR.abbr
}

for _,type in ipairs({'SR', 'VA'}) do
	for _,auxType in ipairs({"Alt", "Bus", "Byp", "Truck", "Toll"}) do
		local spec = VA[" aux "][auxType]
		VA[type .. "-" .. auxType] = {
			shield = VA.SR.shield.default,
			name = VA.SR.name.default .. " " .. spec.name,
			link = VA.SR.base .. " " .. spec.name .. suffix2,
			abbr = VA.SR.abbr .. " " .. spec.abbrsuffix,
			banner = spec.bannerprefix .. " plate.svg",
			aux = spec.aux,
			width = VA.SR.width
		}
	end
end
VA["SR-Toll"].banner = "Toll plate yellow.svg"
VA["VA-Toll"].banner = VA["SR-Toll"].banner

for _,year in ipairs({"1918", "1924", "1956"}) do -- add 1980 when shields are made
	VA["SR " .. year] = {
		shield = format("Virginia %%route%% (%s).svg", year),
		base = VA.SR.base,
		name = VA.SR.name.default,
		link = VA.SR.link,
		abbr = VA.SR.abbr,
		width = "square",
	}
end
VA["VA 1924"] = VA["SR 1924"]

VA.GWMP = {
	shield = "",
	name = "George Washington Memorial Parkway",
	link = "George Washington Memorial Parkway",
	abbr = "George Washington Parkway"
}

VA.Bike = {
	shield = "US Bike %route% (M1-8).svg",
	name = "%route%",
	link = "",
	abbr = "%route%"
}

VA.Byway = {
	shield = "Virginia D6-V1.svg",
	name = "Virginia Byway",
	link = "Virginia Byway",
	abbr = "Virginia Byway"
}

VA.ISR = {
	shield = {VA.I.shield, VA.SR.shield},
	shieldmain = {VA.I.shieldmain, VA.SR.shield},
	name = VA.I.name .. " and " .. VA.SR.name.default,
	link = "Interstate %route% and State Route %route% (Virginia)",
	abbr = "Route %route%",
	bannersuffix = {"blue", ""}
}

-- add new types above this line if you want it to have the state highway browse and maint
for k, v in pairs(VA) do if k:find ("^%a") then
	v.maint = "[[Virginia Department of Transportation|VDOT]]"
	end
end
        
VA.KY = {alias = {module = "USA/KY", type = "KY"}}
VA.MD = {alias = {module = "USA/MD", type = "MD"}}
VA["I-MD"] = {alias = {module = "USA/MD", type = "I"}}
VA.NC = {alias = {module = "USA/NC", type = "NC"}}
VA.TN = {alias = {module = "USA/TN", type = "SR"}}
VA["TN-Sec"] = {alias = {module = "USA/TN", type = "Sec"}}
VA.WV = {alias = {module = "USA/WV", type = "WV"}}
VA["US-WV"] = {alias = {module = "USA/WV", type = "US"}}

return VA