The German far-right party AfD finished well in the European elections, but has also suffered serious legal setbacks.