In the span of a few hours on Thursday, prospects for a deal on immigration in Congress — including a solution for immigrants fearing the demise of the Deferred Action for Childhood Arrivals program — had gone from one senator calling negotiations “all peachy” to President Donald Trump announcing he’s tired of helping people from “shithole” countries.

What looked like a breakthrough day for DACA ended in limbo.

Early in the afternoon, Republicans and Democrats sounded like they’d made progress. “We have an agreement in principle and we are shopping it to our colleagues,” Sen. Jeff Flake (R-AZ), who is part of a bipartisan immigration working group with Sen. Lindsey Graham (R-SC) and three Democrats, said.

“It’s all peachy,” Flake said with a laugh in the early afternoon, noting that the agreement covered Trump’s four requirements: addressing DREAMers, border security, family-based immigration, and the visa lottery system.

The sentiment was short-lived.

Graham’s pitch to the president Thursday afternoon wasn’t a success. The White House’s congressional liaison, Marc Short, said there was a “ways to go,” and by mid-afternoon, White House press secretary Sarah Huckabee Sanders said there was no deal.

By late afternoon, the Washington Post was reporting that the president had shocked the senators by complaining about immigrants from “shithole” countries like Haiti and saying the US should take more immigrants from Norway instead.

Democrats and Republicans are trying to come to an agreement by the end of next week on what to do about the 690,000 unauthorized immigrants who are losing or set to lose their deportation protections under the DACA program. Congress has to come up with a deal to keep the government open in the next eight days, a deadline that has managed to escalate movement and action on DACA. But so far, it has yet to produce a proposal that has the blessing of Congress and the White House.

Senators push ahead with their idea

The Senate is pushing ahead with a proposal, even though Trump seemed to reject it today (after supporting it 48 hours ago). It’s impossible to know how the bill will fare in the Senate — until Thursday, the only people who knew what was in it were the six senators hashing out the deal — but it represents what experienced legislators in both parties think can pass.

The deal follows the contours laid out in Tuesday’s televised immigration meeting: It would give DREAMers a chance at legal status and a path to citizenship, while restricting them from sponsoring their parents, eliminating the diversity visa lottery, and funding some border projects.

Here’s what we know so far the deal would include:

Allowing young unauthorized immigrants who came to the US as children to get legal status — and eventually citizenship: The deal would allow hundreds of thousands of unauthorized immigrants who came to the US as children, and meet other requirements (which aren’t yet clear), to apply for provisional legal status in the US. After a certain number of years, they’d be eligible to apply for green cards — and after another three or five years, like other green card holders, they would be able to apply for US citizenship.

Legalization wouldn’t just be open to the 690,000 immigrants who were protected under the DACA program when Trump started winding it down in September; it would also include immigrants who qualified for DACA and never applied (or whose protections expired without renewal), or who meet the requirements set forward in the bill, as well as immigrants under 15 who weren’t able to apply for DACA. And unlike DACA, it would be permanent.

Preventing “chain migration” by preventing parents of DREAMers from becoming US citizens: In order to make it impossible for people legalized under this bill to sponsor their parents for citizenship, the bill would make parents of DREAMers ineligible to get green cards, making it impossible for them to naturalize. It would instead provide them with a form of legal status that could be renewed every three years.

By putting the restriction on parents of DREAMers, rather than directly restricting DREAMers’ ability to sponsor relatives after becoming citizens, the bill could avoid a constitutional pitfall. But it could end up locking out immigrant parents who have both a DREAMer and a native-born US citizen in the family — who would currently be eligible for green cards when their citizen children turned 21.

Eliminating the diversity visa lottery and reallocating the 50,000 visas currently used for it: As first reported by Politico’s Seung Min Kim, the proposed DACA deal would kill two birds with one stone. It would eliminate the visa lottery. But instead of just allowing 50,000 fewer immigrants into the US legally each year, it would reallocate those visas. Some of them would go to immigrants from underrepresented countries, just on some non-lottery basis; other visas would go to immigrants whose Temporary Protected Status is about to expire due to the Trump administration’s aggressive moves to end the program. (Right now, people with TPS can’t get green cards; under this deal, they could.)

A few billion dollars for the border: NBC’s Leigh Ann Caldwell reported that the deal as presented to Trump would have included $1.6 billion for physical barriers (which Caldwell called a fence but the White House would probably call a wall), surveillance tech, and agent training — and another $1.2 billion for “other priorities” on border security. Those numbers are roughly in line with what the White House asked for for a single year on the border in its 2017 supplemental funding requests.

Trump appears to have changed his mind since Tuesday about what sort of bill he’d sign

On Tuesday, Trump said he’d be open to a DACA bill with no strings attached (though that admission was struck from the official White House transcript). By Thursday, the hang-ups were multiple.

Legislative director Marc Short outlined several demands:

The bill needs to allocate more money for the border (a potentially easy demand to meet).

It needs to restrict categories of family-based visas for future legal immigrants, not just the families of DREAMers. That’s almost certainly a deal breaker for Democrats — especially if the White House isn’t interested in reallocating those visas elsewhere.

Trump’s own problems with the deal appear to be ... different.

During talks Thursday, Trump said, “Why are we having all these people from shithole countries come here?” He was referencing immigrants from Haiti, El Salvador, and African nations, the Washington Post reported, citing people briefed on the meeting. In the context of the bill, that looks like an objection to giving green cards to immigrants with TPS — even though Trump administration officials have said repeatedly that Congress needs to address TPS holders.

But the worst sign for the deal came when Sens. Lindsey Graham (R-SC) and Dick Durbin (D-IL) walked into the Oval Office expecting to meet the president alone, but instead saw Rep. Bob Goodlatte (R-VA) and Sen. Tom Cotton (R-AR) in the room. At the risk of torpedoing a deal, the White House continues to engage immigration hardliners — who are ideologically closer to the anti-immigration platform Trump ran on in 2016, and the views espoused by his top advisers.

Flake, candidly, said he doesn’t think Cotton will sign on to “anything we can get 60 votes on.”

“We are going to lose some on either side,” Flake said. “I don’t think we are going to get all the Republicans.”

“I’m not sure what the next step will be,” Durbin, who has been working with Flake and Graham, told reporters. “The President invited us to — at his little get-together in the Cabinet room — to come up with proposals, and we did. It’s a bipartisan proposal which we’ve worked on for four months in the Senate, and I don’t know what happens next.”

Who is in charge of negotiations?

If not Flake and Graham’s plan, then whose? The answer to that question is complicated — and why negotiations have been so chaotic. Ever since Trump said he would end the DACA program, the debate on Capitol Hill has become as much a fight over who’s running the show as it is about policy.

In the Senate two important groups have risen to the top:

The Flake-Graham “Gang of Six,” which includes Democratic Sens. Durbin, Michael Bennet (CO), and Bob Menendez (NJ), plus Republican Sen. Cory Gardner (CO). A group of Democratic and Republican leadership deputies that have been dubbed the “No. 2s.” It’s a bipartisan group between top-ranking House and Senate members, and the only one with White House involvement. This group includes Durbin, again, as well as Minority Whip Rep. Steny Hoyer (D-MD), Majority Whip Sen. John Cornyn (R-TX), and Majority Leader Rep. Kevin McCarthy (R-CA).

The latter team came together as a reaction to a splintering landscape.

“We are not going to default to existing groups,” Cornyn told reporters. “There were too many groups to count, and they were basically getting nowhere. So that’s why, I think, the need to move to this level.”

Meanwhile, progressives including Sens. Kamala Harris (D-CA) and Bernie Sanders (I-VT) have banded together in the Senate, as have Congressional Hispanic Caucus and Congressional Black Caucus members in the House, who have raised deep concerns about the bipartisan proposal’s approach to the visa lottery program and family-based immigration.

Among conservatives, Sens. Chuck Grassley (IA), David Perdue (GA), and Cotton have had the president’s ear, as has Rep. Bob Goodlatte (R-VA) in the House. Another bipartisan agreement in the lower chamber between Reps. Will Hurd (R-TX) and Pete Aguilar (D-CA), also reached an accord similar to the “Gang of Six” proposal.

While having the input of the White House, the “No. 2s” have yet to come forward with an agreement.

Ultimately, any deal will have to meet only two conditions: It will have to be bipartisan enough to get 60 votes in the Senate, and it will have to win the president’s approval. Until Congress manages to agree on who is doing the negotiating and writing the bills, we won’t know if it’s managed to meet the first condition.

As long as Trump is relying on the Republicans least interested in an immigration compromise to advise him, like Goodlatte and Cotton, no bill that meets the first condition will be able to meet the second.