local h = {}

function h.find( parent, name )
	repeat
		if not parent then
			return nil, 'no parent'
		end

		local arg = parent:getArgument( name )
		if type( arg ) == 'string' then
			if mw.ustring.find( '^%s*$', arg )
				or mw.ustring.find( '^%s*uten%s*$', arg )
				or mw.ustring.find( '^%s*ingen%s*$', arg )
				or mw.ustring.find( '^%s*ikke%s*$', arg )
			then
				return nil, 'terminated lookup'
			end

			return arg, 'found'
		end

		parent = parent:getParent() -- this becomes nil for grandparents
	until ( not parent )
	return nil, 'exhausted parameter'
end

function h.main( frame )
	local parent = frame:getParent()

	for _,name in ipairs( frame.args ) do
		local arg, reason = h.find( parent, name )
		if arg then
			return arg
		end
	end

	local default = frame:getArgument( 'default' )
	if default then
		return default:expand()
	end

	return ''
end

return h