President Trump's counterterrorism executive order keeping out many refugees, immigrants, visitors, and even residents demonstrated how shoddy policymaking can have grave political, moral, and security consequences.

Acting on Trump's new executive order, border officials on Saturday detained people at airports who had already been granted entry visas. They also detained some lawful permanent residents who unluckily booked their flights back home to the U.S. for the day after Trump's hasty rule.

This is inhumane, unjust and irrational.

Trump should put the rule on ice, go through the proper rule-making process and issue a sensible written rule with appropriate input from the nation's homeland security, law enforcement and counterterrorism officials. If he won't, congressional Republicans should intervene until, to borrow a phrase from the president, "our country's representatives can figure out what the hell is going on."

The executive order halts for 90 days all travel to America from seven terrorist-infested countries, halts indefinitely all entry from Syria, and suspends for 120 days any entry of refugees from anywhere in the world.

It's good that Trump wants to revamp our vetting process. ( Rigorous vetting is fitting and appropriate; why anyone would describe their own policy as "extreme vetting" is a mystery, rather like Mitt Romney calling himself a "severe" conservative.) A country has the right to determine who enters, and our government has a duty to its residents' safety. It has no corresponding legal duty to outsiders, even though this country has always regarded it as a welcome moral duty to give the oppressed a safe haven.

Finally, it's also good that Trump has moved away from his original proposal of a ban on all Muslims entering the country. (To be fair, he moved away from that many months ago, much though his most recalcitrant critics refuse to acknowledge that.)

But having accepted all this, it is nevertheless plain that this executive order was dreadful policymaking. Announcing such a weighty executive order at 4:52 on a Friday is not the hallmark of good government. The administration didn't even release the text until hours later.

While executive orders have the president's signature, and no secretary, chief of staff, or bureaucrat can contravene his will, there is still a proper process of making these orders. Custom, legal rulings and statute have shaped this process.

A president will typically consult the relevant agencies while crafting an order. For instance, border patrol officials will know far better than the White House what sort of enforcement is plausible, intrusive, time-consuming, or effective. The State Department will know details about different types of visas, different classes of visitors to the country, and different types of threats from different countries.

The Justice Department can provide not only expert input on law enforcement, but also everyday lawyerliness. DOJ's Office of Legal Counsel typically vets every executive order in the same way a company's general counsel might vet corporate documents.

Trump seems to have skipped consultation with relevant agencies and may have skipped over consultation even with the OLC.

"All executive orders and proclamations proposed to be issued by the president are reviewed by the Office of Legal Counsel for form and legality," the counsel office's website says. But it gave no comment when asked if it had reviewed this executive order. This could explain the order's sloppiness, including a passage that cites the wrong provision of immigration law.

DOJ had no input at all, a Justice official told NBC. State Department and Homeland Security officials were reportedly also left out of the loop.

At DHS, home to the border patrol, career staff didn't see the text of the order until Friday, the day Trump signed it, according to CNN. Customs and Border Protection officials told the New York Times they were only briefed (by phone) as President Trump signed the order Friday afternoon. Even John Kelly, new secretary of homeland security, only saw the final text just before Trump issued it.

DHS originally said the rule didn't apply to lawful permanent residents, that is, to green card holders. But the White House overruled that judgment, so residents, who had gone through intense and repeated vetting, and whose roots may be planted here in America and who may be on a path to citizenship, were detained at American airports and teed up for deportation.

This isn't anywhere close to rational anti-terrorism policy. This is, rather, incompetence and ignorance by a White House inexperienced in government and deliberately insulated from those with experience. If it is additionally tainted with bigotry or cruelty, that would make it worse.

Fully suspending the refugee program is overkill, for it is already rigorous. Very few people admitted as refugees — it seems to be only three — have been caught involving themselves in terrorism in the U.S. Three is too many, and suggests a need for better screening, but it is also too few to justify the blanket coverage of the latest executive order.

Trump hasn't explained a rational basis behind his 90-day suspension of entry from the seven countries covered, although the countries themselves were first identified by the Obama administration as requiring special care. Couldn't the order be more narrowly targeted to vet higher-risk immigrants or visitors?

DHS, State, and DOJ could address these questions and shape a rule that precisely addresses counterterrorism concerns.

Now that a federal judge has blocked all deportations under this rule, the Trump administration should suspend the executive order and go to the agencies, make them work overtime if needed, and cooperatively craft a more coherent immigration screening policy.

There is debate about what power Congress has to restrain the president; how much of his authority derives from the Constitution and how much from federal immigration law cited in the order. But what Congress has given, Congress can take away and it should use that power to press Trump to reform and redraft the order.

Turning lawful permanent residents into deportable aliens and lumping refugees in with terrorists isn't the way America ought to operate. Unilaterally and hurriedly issuing a rule without expert input from those who would have to implement it isn't the way a White House ought to operate.