local export = {}

function export.show(frame)
	-- [[mw:Extension:Scirbunto/Lua_reference_manual#Accessing_parameters_from_wikitext]]
	-- it changes parameters order from original to unpredictable
	-- example: |p=15|10=1|20=2|30=3 >> |30=3|p=15|20=2|10=1 (1234 >> 4132)
	local args = frame:getParent().args
	
	local p = ( args["p"] and tonumber(args["p"]) or error("Missing parameter 'p' (position-X)") )
	
	local bottom
	for border in pairs(args) do
		if border~="p" and border~="default" then
			border = tonumber(border)
			if p >= border then	-- this border is bottom
				if bottom==nil or border > bottom then	-- old bottom is farther
					bottom = border
				end
			end
		end
	end
	
	if bottom==nil then
		return (args["default"] or "")
	end
	
	bottom = args[tostring(bottom)]
	if bottom=="@" then
		return (args["default"] or "")
	end
	
	return bottom
end

return export