A statistical theory of nuclear reactions based on a variational principle