A local man is accused of being a supporter of ISIS and planning a terror attack against a Detroit church, according to an affidavit that has been filed in federal court.

Khalil Abu-Rayyan was initially arrested on marijuana and firearm charges, but he has since been accused of much more serious crimes.

Abu-Rayyan has been the subject of FBI scrutiny since May 2015. During their surveillance of Abu-Rayyan, officials monitored his social media accounts. The affidavit states among the things they saw on his accounts were re-tweets of ISIS propaganda, including video of a Jordanian fighter pilot being burned alive, men being thrown off high rise buildings, the beheading of Christians in Egypt and news of ISIS victories.

There were also posts directly from Abu-Rayyan that raised red flags, according to the affidavit. One picture Abu-Rayyan posted shows him holding what appears to be a semi-automatic pistol and pointing his index finger up in a gesture common to ISIS supporters next to two other individuals dressed in camouflage.

Beginning in December 2015, an undercover investigator began interacting with Abu-Rayyan on social media. It was during this time that Abu-Rayyan revealed that he had an AK-47 machine gun.

According to the affidavit, photos posted to Abu-Rayyan's Twitter account on November 29, 2015 show him firing an AK-47 and an AR-25 at a firing range. One of the photos is captioned "Sahwat hunting." According to the affidavit, Sahwat is a term for Iraqis who oppose ISIS.

Also according to the court documents, Abu-Rayyan told the undercover investigator:

I tried to shoot up a church one day. I don't know the name of it, but it's close to my job. It's one of the biggest ones in Detroit. Ya, I had it planned out. I bought a bunch of bullets. I practiced a lot with it. 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 affidavit says that Abu-Rayyan went on to say:

It's easy, and a lot of people go there. 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.

Officials believe they have identified the church Abu-Rayyan was planning to attack. While it is not specifically named, the affidavit says it can accommodate up to 6,000 members.

According to court documents, he purchased a gun at a sporting goods store in Dearborn Heights in October of 2015 and lied on the form, stating he was not an unlawful drug user.

Two days after purchasing the .22 caliber gun, Abu-Rayyan was arrested after being pulled over by a Detroit police officer for speeding. During the stop, the officer saw Abu-Rayyan make several suspicious movements.

The officer also smelled a strong odor of marijuana.

During questioning, Abu-Rayyan told police that he was trying to hide the gun during the traffic stop. He said he was open carrying at work and forgot to put the gun in the trunk.

On January 15, Abu-Rayyan pleaded guilty to possession of marijuana. He is scheduled for trial on a charge of carrying a concealed weapon on February 16.

However, according to the affidavit, a few days after pleading guilty, Abu-Rayyan told the undercover investigator he wanted to kill the officer who arrested him. The officer was in the hospital after suffering a heart attack, and the affidavit says Abu-Rayyan wanted to do a "martyrdom operation" at the hospital and kill the police officer.

He also told the undercover officer, according to the affidavit, that he carried a sword in his car in case he gets into a fight and said he would gladly behead people.