DETROIT (WWJ/AP) – A judge has refused to set bond and release a Dearborn Heights man accused of plotting to attack a Detroit church, although he questioned whether inflammatory statements cited by agents violated the law.

Khalil Abu-Rayyan is not charged with terrorism-related crimes. But investigators say he’s made threats against a church, police and others in support of the Middle Eastern terror group ISIS. The 21-year-old has been in custody for about two weeks on a gun charge.

READ MORE: Ribs RnB Music Festival Kicks Off This Weekend In Downtown Detroit

His father, Rayyan Abo-Rayyan, pledged to take responsibility if his son is released on bond. But U.S. Magistrate Judge R. Steven Whalen says he must protect the community. He held a hearing Tuesday.

The FBI says Abu-Rayyan has expressed support for Islamic State. Defense attorney Todd Shanker says he was simply trying to impress an undercover agent.

According to the documents, Abu-Rayyan was under federal surveillance starting in May 2015. It was found that Abu-Rayyan was posting and retweeting ISIS-supporting posts on Twitter, along with photos of him firing an AK-47 and an AR-25 at a gun range.

Abu-Rayyan allegedly told an undercover agent through social media about his plans for an attack.

Click here to read the complaint (.pdf format)

READ MORE: Judge Says Michigan Gov. Whitmer Won't Have To Testify In Abortion Lawsuit

“I tried to shoot up a church one day,” Abu-Rayyan posted, the complaint said. “It’s one of the biggest ones in Detroit. I had it planned out. I bought a bunch of bullets. I practiced reloading and unloading. But my dad searched my car one day and he found everything. He found the gun and the bullets and a mask I was going to wear.”

The church in question went unnamed in the documents, but was said to have 6,000 members. Abu-Rayyan allegedly went on to explain why he picked the church as a target.

“It’s easy, and a lot of people go there,” the post read. “Plus people are not allowed to carry guns in church. Plus it would make the news. Everybody would’ve heard. Honestly I regret not doing it. (If I) can’t go do jihad at the Middle East, I would do my jihad over here.”

Abu-Rayyan was pulled over for speeding on Oct. 7 when officers found an unlicensed pistol inside his car and noticed a strong smell of marijuana. He told police during questioning that he was trying to hide the gun from the officer. He pleaded guilty to possession of marijuana and is scheduled for trial on a concealed weapon carrying charge.

Court documents say that days after pleading guilty to marijuana charges, Abu-Rayyan took to social media again and told the undercover agent that he wanted to kill his arresting officer — who was in the hospital following a heart attack — and that he carries a “large knife or sword” in his car in case he gets into a fight.

“I would gladly behead people if I needed to,” he allegedly told the agent. “It is my dream to behead someone.”

MORE NEWS: MDHHS Lifts No-Contact Recommendation In Huron River Chemical Spill

TM and © Copyright 2016 CBS Radio Inc. and its relevant subsidiaries. CBS RADIO and EYE Logo TM and Copyright 2016 CBS Broadcasting Inc. Used under license. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed. The Associated Press contributed to this report.