Image copyright Getty Images

For months we've been heading toward this moment, a political conflagration on the border over immigrant policy. But what is Donald Trump's endgame - and why?

In May the New York Times reported that Donald Trump had berated Homeland Security Secretary Kristjen Nielsen over what he viewed as her failure to aggressively enforce border security and urged her to begin the process that would result in undocumented children being taken away from their parents.

"One persistent issue has been Mr Trump's belief that Ms Nielsen and other officials in the department were resisting his direction that parents be separated from their children when families cross illegally into the United States, several officials said," the Times reported. "The president and his aides in the White House had been pushing a family separation policy for weeks as a way of deterring families from trying to cross the border illegally."

Attorney General Jeff Sessions' 7 May announcement of a "zero tolerance" policy for illegal crossings simply cemented the decision.

Administration officials have offered conflicting explanations for the harrowing details of crying children kept in fenced-in rooms and despondent parents, but Mr Trump's dual goals appear clear:

Leverage - he wants to force Democrats in Congress to negotiate a legislative package that keeps migrant families intact in exchange for full funding for his much-touted border wall, speedier deportation of undocumented aliens and sweeping changes to legal immigration policy.

- he wants to force Democrats in Congress to negotiate a legislative package that keeps migrant families intact in exchange for full funding for his much-touted border wall, speedier deportation of undocumented aliens and sweeping changes to legal immigration policy. Red meat - if he fails to get a deal, he sees this as a winning mid-term election issue, motivating his base to turn out in support of Republicans across the country.

Let's break those down.

1) A dark art of the deal?

If a presidential decision to create a situation that is intolerable for Democrats in order to gain the upper hand in immigration negotiations seems familiar, that's because it is.

Mr Trump pursued a similar strategy when he ended the Obama-era Daca programme that provided normalised status for the children of undocumented immigrants - often referred to as "Dreamers" - last October. Mr Trump repeatedly blamed congressional Democrats for inaction and said deportation of these long-time US residents who had only recently emerged from the legal shadows would be their fault.

"Any deal on DACA that does not include STRONG border security and the desperately needed WALL is a total waste of time," he tweeted in February. "Dems seem not to care about DACA. Make a deal!"

Attempts to pass a comprehensive bill were derailed, however, as early suggestions by the president that he was open to a bipartisan compromise were replaced by more sweeping demands by members of Mr Trump's negotiating team.

Eventually courts eased the pressure to reach an agreement before the Trump-imposed March deadline by ordering the administration to continue processing Dreamer applications while legal challenges were considered.

Now the pressure is on again - and the president's comments and tweets are eerily similar to those of a few months ago.

"The Democrats are forcing the breakup of families at the Border with their horrible and cruel legislative agenda," the president tweeted. "Any Immigration Bill MUST HAVE full funding for the Wall, end Catch & Release, Visa Lottery and Chain, and go to Merit Based Immigration."

Media playback is unsupported on your device Media caption Zero-tolerance: The US policy dividing families and opinion

The family separation policy is the result of Mr Trump's decision to charge all undocumented migrants as criminals, just as the Daca repeal was initiated by presidential order. In both cases, the president wants the same thing in exchange - a full implementation of the hard-line immigration and border security policies on which he campaigned.

Will this latest effort end up in a bill on the president's desk?

On Tuesday evening, Mr Trump met privately with congressional Republicans. One representative in attendance said the president was not "comfortable" with the optics of crying children or the separation policy itself.

The president told the Republicans that his daughter Ivanka, who has positioned herself as a White House adviser on family policies - had told him the issue needs to be dealt with. Mr Trump, however, reportedly did little to provide direction to the legislators.

And while the House of Representatives may pass something later this week, there's still little evidence of the 60 votes (out of 100) in the Senate needed for any kind of immigration bill.

That may not matter for Mr Trump, however, because of his second goal.

2) Feeding the base

A strange thing happened on the way to a predicted universal condemnation of Mr Trump's policy of separating children from parents who cross the US-Mexico border without documentation. It turns out Republican voters like it.

According to a recent Quinnipiac poll, while 91% of Democrats and 68% of independents oppose separating asylum-seekers and others in the US illegally from their children, 55% of Republicans support it.

An Ipsos poll found similar numbers, with a plurality of Republicans agreeing that the Trump policy is appropriate "in order to discourage others from crossing the border illegally".

There's precedent for these sort of numbers as well. Back in December 2015, candidate Trump unveiled his proposed ban on the entry of all members of the Muslim faith into the US - and was roundly denounced by political commentators and top members of his own party.

Recall the surprise when the policy, while more broadly unpopular, was backed by majorities of Republican primary voters. Mr Trump's views on immigration were, in fact, in line with the base of the Republican Party. It was the leadership and analysts who were out of step.

"Turns out I was 100% right," he told a meeting of the National Federation of Independent Business on Tuesday. "That's how I got elected."

Media playback is unsupported on your device Media caption The sound of migrant children separated from parents

Mr Trump was right about the political appeal of the Muslim ban, and he appears to be betting that he's right about this immigration policy, as well.

"Democrats can fix their forced family breakup at the Border by working with Republicans on new legislation, for a change!" the president tweeted on Saturday. "This is why we need more Republicans elected in November. Democrats are good at only three things, High Taxes, High Crime and Obstruction. Sad!"

Polls and results from recent special-election and off-year state-level contests in Virginia and New Jersey offer evidence that Democratic voters are politically engaged and heading to the voting booths in large numbers. As Texas Republican Senator Ted Cruz quipped in February, liberals would "crawl over broken glass" to vote in November.

To counteract this, Mr Trump is reportedly seeking "unexpected cultural flashpoints" to get his base equally enthusiastic about voting - particularly in the Trump-friendly states that are 2018's Senate battlegrounds.

In a recent tweet, Mr Trump promised that if Democrats fight with him on this issue in the mid-terms, they will lose. That is, of course, exactly what he wants - and exactly the reason he's not likely to back down on his immigration policies.

In just over four months, the president will find out just how right - or wrong - he is.