The tiny Persian Gulf nation of Qatar is embroiled in a massive diplomatic crisis with Saudi Arabia and other close US allies. The Trump administration openly accuses it of sponsoring terrorism. So why did Washington just finalize a $12 billion arms deal that could give Qatar some of the most powerful military fighter jets on the planet?

The deal was in the works for a while — it’s actually part of a larger $21 billion agreement made back in November 2016, in the waning weeks of the Obama administration. This portion of the pact, a $12 billion deal for 36 F-15 planes, was signed by Defense Secretary James Mattis on Wednesday so contracting actions could begin.

The move is particularly striking because it comes while the Trump administration publicly struggles to figure out how to handle the wealthy nation, which houses one of the largest American military bases in the Middle East but also maintains ties to groups like Hamas and the Muslim Brotherhood.

Those ties, in turn, have sparked one of the biggest diplomatic standoffs in the Middle East in decades. On June 5, Saudi Arabia, Egypt, the United Arab Emirates, and Bahrain cut ties to the country and closed all land, sea, and air borders with it. (Four other countries, including Yemen, the Maldives, Mauritania, and Comoros, quickly followed suit.) They did so in part because Riyadh claims Doha’s backing of terrorist groups like ISIS are stronger than it lets on, and so Qatar’s neighbors wanted to send a strong message.

It’s a belief that Trump seems to share. “The nation of Qatar, unfortunately, has historically been a funder of terrorism at a very high level,” Trump said on June 9 in the Rose Garden. “We have to stop the funding of terrorism.”

Based on Trump’s comments, it seemed he agreed with Saudi Arabia and company. Now it’s not so clear, and it’s confusing seasoned leaders in this area.

“The mixed messages the administration is sending on many national security issues is baffling,” Sen. Tim Kaine (D-VA), a member of tbe Armed Services and Foreign Relations Committees, said in an interview.

Kaine’s discomfiture is fair. Sending a bunch of warplanes to Qatar doesn’t, on its face, seem like the most effective way for Trump to convey that he’s willing to go to the mat with the country over its terror ties.

Which isn’t to say that the deal doesn’t make sense by the twisted logic of US Middle East policy.

The US and Qatar have an unbelievably complicated relationship

Trump’s hardline rhetoric toward Qatar had the potential for serious real-world repercussions for the Pentagon. Qatar hosts the vitally important Al Udeid airbase, where some 10,000 US troops reside. It’s the nerve center of the fight against ISIS, so US defense officials have a different view of Qatar’s utility. After Trump’s comments, the Pentagon expressed its gratitude for Qatar’s partnership in the region.

Some veteran diplomats said the weapons deal could right a relationship that has looked like it might go off the rails at any time.

“This is an excellent time to make the sale,” Chase Untermeyer, US ambassador to Qatar from 2004 to 2007, stated in an interview. “There is nothing that more elegantly speaks to the fact that Qatar is a functional ally of the United States than the sales.”

The problem is that it’s not clear that all of the Trump administration actually feels that way. Just one hour before Trump lambasted Qatar on June 9, Secretary of State Rex Tillerson called for the Saudi-led bloc to ease the blockade and bring the standoff to an end. “Our expectation is that these countries will immediately take steps to de-escalate the situation,” he said.

A State Department official told the Washington Post’s Josh Rogin that Tillerson’s stance toward the country is the one being followed in the building — not Trump’s. “The policy that is being worked is the Tillerson policy, Trump’s comments notwithstanding,” said the official.

So even if Trump wants to punish Qatar, it seems State and DOD have different views on this issue, and are taking active measures to ensure the relationship with Qatar stays relatively stable.

Selling planes to Qatar — something that had long been planned — is definitely a way to make Qatar happy, as the tweet from its ambassador to the US shows. The weapons sale wasn’t meant as an “I’m sorry” gift by any means, but it might as well have been one.