Avalanches and edge-of-chaos learning in neuromorphic nanowire networks