Dynamic wavefront shaping with high-quality-factor resonant metasurfaces