Theory of spin glasses