EVEN in a year of extraordinary reversals, few would have expected it. In July China reacted with fury when an international tribunal upheld a complaint from the Philippines and rubbished China’s territorial claims in the South China Sea. This week it is rolling out the red carpet for the mercurial Philippine president, Rodrigo Duterte. He is being feted in a four-day state visit, with 400-odd businessmen in tow. Rub your eyes: America’s strongest ally in South-East Asia appears to be plopping like a ripe mango into China’s hands.

Consider what Mr Duterte, in power since June, has said in recent weeks. He has branded Barack Obama a “son of a whore” for criticising his “kill them all” war on drug dealers and addicts, which has claimed thousands of lives, many of them innocent. He has demanded an end to joint naval patrols and to America’s assistance in the southern jungles of Mindanao, where American special forces advise Filipino troops fighting against Abu Sayyaf, a violent group linked to al-Qaeda. And he has questioned whether America would honour its treaty obligation to come to the Philippines’ aid if the archipelago were attacked.

What that means for the American “pivot” to Asia scarcely bears thinking about. But do the eyes deceive? American officials—from Admiral Harry Harris, commander in the Pacific, down—insist that all is dandy. Joint naval patrols continue, as does co-operation in Mindanao; and America still has five bases on Philippine soil. The close working relationship with Filipino counterparts, the Americans insist, is as strong as ever. The Filipinos, for their part, report no change of orders from the new chief.

Yet Mr Duterte talks of China like a moonstruck lover. On the eve of his visit he told Xinhua, the Chinese news agency, that China’s generosity to poor countries was without reproach. China “deserves the kind of respect that [it] now enjoys...It’s only China that can help us.” He has been at pains to point out that one of his own grandfathers was Chinese. Thrilled, the Chinese ambassador in Manila talks of “clouds fading away” and the sun rising to “shine beautifully on the new chapter of bilateral relations”.

What is Mr Duterte up to? Bear in mind that development and growth are his priority—one reason for his sky-high popularity in a country with an entrenched plutocracy lording it over legions of urban and rural poor. But development needs capital, and the Philippines has been excluded from recent Chinese largesse showered around the rest of the region. Relations suffered in 2012 after China dislodged the Philippine navy from the Scarborough Shoal, which is just over 200km from the Philippines proper, within its exclusive economic zone, and almost 900km from China. Filipino businesses have struggled in China, while little Chinese investment has come to the Philippines. The tribunal’s ruling only made matters worse: afterwards, China told even its tourists to stay away.

The Philippines had been plucky in standing up to China. But it has paid a price. Now, the goodies that China is dangling look irresistible. Mr Duterte wants lots of infrastructure, particularly railways. China is offering cheap loans. He wants the country to export more. China is offering to reopen its markets to Philippine fruit. He wants help with the war on drugs. A Chinese businessman is building a big rehab centre. And he wants Filipino fishermen to be able to return to their traditional fishing grounds around the Scarborough Shoal. China has told Philippine officials that it is open to an accommodation.

Perhaps America, in banking so much on its plucky ally, should have been more clear-eyed about the cost to the Philippines of standing up to Chinese aggression in the South China Sea. Perhaps, too, it should not have assumed that all Filipino politicians have an instinctive allegiance to America.

Although Filipinos are overwhelmingly pro-American, they are also patriotic. The American colonial period saw its share of atrocities, especially in Mindanao. One colonial general mused that it might be necessary “to kill half the Filipinos in order that the remaining half of the population may be advanced to a higher plane of life”. Mr Duterte himself says he was molested by an American priest as a child. The landed elite that he claims to be displacing achieved its ascendancy under American rule. And standing up for the little guy is part of his shtick. The insistence of his foreign secretary, Perfecto Yasay, that Filipinos will not be America’s “little brown brothers” does not go down too badly.

Yet it is not only Americans who lament the impetuousness of Mr Duterte’s tilt to China: many Filipinos, including senior officials, are worried sick. Jay Batongbacal of the University of the Philippines fears Mr Duterte “is squandering all the practical leverage that comes from being in alliance with the United States”—without knowing what assurances, in terms of sovereignty in the contested South China Sea, the Philippines will get in return.

Bide your time

It is a reckless approach, but not necessarily a lasting one. For the time being, China wishes to draw the Philippines into its camp. That is why it has not yet attempted to build the kind of military facilities on Scarborough Shoal that it has constructed on other reefs in the South China Sea and that many Western analysts had assumed were imminent.

But China will have to offer more than fishing rights to make any deal acceptable to Filipinos. Even the China-loving Mr Duterte has talked about leaping onto a jet ski to defend the Philippines’ interests in person if need be. So the Chinese idea of a “package deal” in which Chinese sovereignty over the Scarborough Shoal is acknowledged in return for fishing rights which Filipinos had anyway long enjoyed will be greeted as an insult back in the Philippines.

America, in short, can be patient. The Philippines may yet return to its camp. If so, both sides will claim it never left.