Updated

An Egyptian flight student who was arrested after posting threatening comments about Donald Trump on his Facebook page agreed Friday to leave the country by July.

Immigration authorities agreed to let Emadeldin Elsayed, 23, return to Egypt voluntarily instead of deporting him, so long as he departs by July 5. Elsayed, who is being held at a jail in Southern California, appeared at a hearing in immigration court in Los Angeles shackled and wearing a yellow jail jumpsuit.

His lawyer, Hani Bushra, told Immigration Judge Kevin Riley that he may seek another bond hearing for the aspiring pilot from Cairo because he believes Elsayed's detention is illegal.

Immigration authorities arrested Elsayed at his Los Angeles-area flight school on Feb. 12, eight days after the Secret Service interviewed him about a post he wrote on his Facebook page. It said he would be willing to serve a life sentence for killing the Republican presidential hopeful.

Federal prosecutors have not charged him with a crime, but his visa was revoked.

Elsayed said in a phone interview earlier this week that Trump's comments about banning Muslims from traveling to the United States angered him, but he never intended to harm anyone.

Trump has used especially tough talk on immigration during his campaign. He has vowed to build a wall along the entire Mexican border and called for a temporary ban on Muslims entering the country.