In the last month, the internet searches on his iPhone had grown dark.

"What weapons were used in Columbine"

"Sandyhook"

"Parkland shooter how many visits home"

"How many times were AR-15s used in mass shootings"

Then, on April 27 and again Monday, the young man walked the streets of Abington with a loaded AR-15 on his back. The first night, he told a police officer he was "doing this because people don't know the law," according to court documents. He had never interacted with law enforcement prior to that Friday.

What he was doing, while "passive aggressive," wasn't illegal, authorities said. In Pennsylvania and 44 other states, citizens are allowed to openly carry firearms in public places.

But the man's public displays led his friends to contact Abington police with additional information that made them concerned for his well-being and the public's safety.

On Thursday morning, the Abington Township Police Department ordered the man's involuntary commitment through an application for urgent evaluation and treatment for those who have posed a danger to themselves or others in the last month due to a mental illness. Once someone has been involuntarily committed, he or she cannot legally own or possess a firearm in the United States.

Authorities did not release his name, and he has not been charged with any crime. His name appeared on a search warrant but efforts to reach him or his family Friday night were unsuccessful.

After talking to the man's friends, officers also searched the township home where he lived, and the contents of his cellphone. The police findings — laid out in search warrants obtained by the Inquirer and Daily News — were alarming.

The man's friends, who are not identified in the documents, told police that he had joked about "shooting up" his schools — first Abington High School, which he attended as recently as last June, and then Penn State-Abington, which he attended earlier this year, according to the documents. He also talked of suicide. One friend said they didn't take the threats seriously at the time because the man had a "dark sense of humor," according to the documents.

But after he purchased the AR-15 in March, friends grew more concerned.

"I think he is throwing up some red flags, because he recently dropped out of school," one friend told police this week. "He gave me the impression that he feels he has nothing to lose in a way."

On April 27, he texted a different friend before taking his first walk with the AR-15.

"Wish me luck, I'm headin' out …," he wrote, attaching a picture of the gun. "I'm gonna record the whole thing in case I get shot."

That night, he walked for at least an hour, encountering an officer on Susquehanna Road and Maple Avenue. The man refused to identify himself and recorded his encounter with the officer on his phone, according to the documents.

Before 1 p.m. Monday, he set out on a longer route, walking near stores and schools and through residential neighborhoods, according to the documents. Several residents called 911 upon seeing him.

"It was scary. It frightened me," one caller said, according to the documents. "I was scared for my kids, who were in school."

In conversations with authorities that day, the man told them he was trying to "gauge the political climate" of the township and educate citizens about the Second Amendment.

On Tuesday, Abington Police Chief Patrick Molloy said the man was not believed to be a threat to the public at the time.

Online, reactions to the sightings initially sparked impassioned debates over gun rights. Some defended the man's actions, noting he was within his Second Amendment rights. Others said he was behaving as an irresponsible gun owner, or that those types of semiautomatic weapons should be outlawed.

"This case illustrates the very complex nature of balancing an individual's Second Amendment rights with our primary mission to protect and serve all of our citizens," Abington police said in a statement  Friday. "This individual's decision to exercise his rights does not, by itself, warrant an involuntary mental health evaluation."

Mental health affects a person's ability to own a firearm in Pennsylvania in two scenarios, according to Joshua G. Prince, a Berks County attorney who focuses on Second Amendment law.  Firearm ownership is prohibited  for a person who is involuntarily committed to a mental-health facility or who has been adjudicated incompetent to manage his or her affairs, Prince said.

Staff writer Tom Avril contributed to this article.