A man charged in an undercover FBI operation with plotting to bomb a synagogue and Jewish school in South Florida during the recent Passover observance suffers from long-term mental illness and is no terrorist, his attorney said Tuesday.

Lawyer Joaquin Padilla said at a bail hearing that James Medina of Hollywood had been involuntarily committed by his family for psychiatric treatment on at least two occasions and that family members believe his unspecified illness dates to childhood.

"He has had mental health issues for a long time," Padilla said. "This is not a homegrown terrorist."

Still, U.S. Magistrate Judge Andrea Simonton agreed with prosecutors that Medina, 40, should not be released on bail because he is a danger to the community and at risk of fleeing. Medina faces life in prison if convicted of attempting to use a weapon of mass destruction.

According to the FBI, Medina first told an informant he wanted to attack the Aventura Turnberry Jewish Center using an AK-47-style weapon. It was the informant who suggested the idea of a bomb, FBI agent David Clancy testified at the hearing.

"We instructed the source to tell Mr. Medina he can get various things including an explosive device," Clancy testified.

Medina was arrested last month after accepting the dummy bomb from the informant. When the investigation began, Clancy added, Medina was living with two other men -- one of whom possessed an AK-47 rifle.

Simonton noted that if the FBI had not substituted the bomb idea for the gun, Medina might have carried out his original plan.

"It is certainly a horrific thought," she said.

Padilla said Medina -- who also goes by James Muhammad -- converted to Islam four or five years ago after getting divorced. Prosecutors noted that he has numerous arrests over the years, including for assault, stalking and armed robbery.

Clancy said that after his arrest, Medina explained to the agents why he wanted to target Jews and the Aventura center in his planned attack.

"Mr. Medina believes the Jews are the cause of the present state of the world and all the wars," the agent said.

On FBI recordings, Medina is quoted as saying he would credit his attack to the Islamic State terror group and even made up leaflets to that effect that he planned to leave at the Jewish center. Clancy, however, testified that it was the FBI informant who first brought up the Islamic State and other terror organizations. None had a link to Medina.

Still, Assistant U.S. Attorney Marc Anton said Medina rejected numerous opportunities to back out of the plot, even when told he would likely kill women and children at the synagogue.

"This is a defendant who wanted to terrorize a temple," Anton said. "This is a very violent individual with intense hatred for the Jews and intent on causing mass casualties."

Medina is scheduled to enter a formal plea to the charge next week. A trial date has not been set.