Tunable hydrogen storage in magnesium-transition metal compounds: First-principles calculations