ANKARA—Before Jim Mattis, the U.S. defense secretary, set off on a trip to strengthen ties with America’s allies in the Middle East and Europe, the Pentagon released a statement saying he would “look for ways to help Turkey address its legitimate security concerns,” including the fight against the Kurdistan Workers' Party (PKK), an outlawed terrorist organization that Turkish officials view as their number one threat.

In Mattis’s meetings with Turkish government officials in Ankara today, he will have to acknowledge Turkish interests while serving as the de facto face of America’s ongoing support for Kurdish groups in northern Syria in the fight against the Islamic State. Following the battle for Mosul, the U.S. military has been leading the operation to retake Raqqa. It has done this from bases in Turkey, where it provides weapons and logistical support to the Syrian Democratic Forces (SDF), which are largely composed of Kurdish militants from the People's Protection Units (YPG), a group that Turkish officials have deemed indistinguishable from the PKK. The collaboration between American and Kurdish forces has, unsurprisingly, been deeply disturbing for Turkey’s leadership.

Mattis, then, will seek to override such discord—no easy task, as the U.S. strategy against ISIS has already done long-term damage to U.S.-Turkey relations. To pull it off, he’ll have to turn a blind eye to the increasingly authoritarian governing style of Recep Tayyip Erdogan, the president of Turkey. Since last year’s failed coup, U.S. officials have remained largely silent amid his massive crackdown on dissent, in which Turkish authorities have jailed and dismissed more than 150,000 people, including members of parliament, journalists, and international humanitarian workers, for alleged links to terror organizations.

Yet while staying quiet on Erdogan’s purges may ensure continued U.S.-led operations against ISIS in the short-term, the trade off could hasten greater instability within Turkey, where opposition parties and democratic institutions have been dramatically weakened. Left unchecked, Erdogan’s rule-by-decree governance under the yearlong state of emergency could lead to a collapse of civil society.

According to Asli Aydintasbas, senior policy fellow with the European Council of Foreign Relations and columnist for Turkey’s Cumhuriyet newspaper, America’s regional policy errs in trying to “compartmentalize” Turkey’s Kurdish issues through borders. “There’s no great wall between Kurds in Syria and Kurds in Turkey,” Aydintasbas said. “They are part of the same problem for Turkey and need to be dealt with accordingly.” Aydintasbas said America could act as an intermediary between Turks and Kurds, but has so far ignored the task by choosing to arm YPG militants without taking steps to ensure a lasting peace after ISIS militants are defeated. Still, talks of a Turkish invasion of Kurdish-held areas in Syria make daily headlines in the Turkish press as the prospects of a new Kurdish statelet remain a top concern for Erdogan.

For the time being, the main priority for Mattis and U.S. officials is to keep Ankara from interfering with U.S.-backed forces in Syria as the Raqqa offensive proceeds. Turkish forces have occasionally bombed Kurdish militants across the border; state-run media also revealed the location of U.S. special forces in Syria, putting American lives at risk and compromising covert operations. While Washington and Ankara have never been especially close, the two are critical NATO allies as several-dozen U.S. nuclear warheads are positioned in Incirlik air base in Turkey’s southern city of Adana.

A major point of friction has been the Agreement for Cooperation on Defense and Economy (DECA), which was signed in 1980 and governs U.S. military operations in Turkey, as Aaron Stein, a Turkey analyst at the Washington-based Atlantic Council, explained. The agreement gives the United States access to NATO bases for NATO-specific missions, but all non-NATO missions require approval from the Turkish parliament. Since most post-9/11 operations in the Middle East have been launched from Turkey, America’s uncompromising regional agenda has often forced Turkish officials to co-sign on missions that may or may not be in their nation’s best interest. “This was [the case with] Libya, Iraq, Iraq again, Syria … this complicates U.S. planning and drives down trust between CENTCOM and the Turkish government,” Stein said.

After decades of U.S. intervention in the Middle East, much of the Turkish population has taken an increasingly hostile stance towards Western powers. Erdogan has tapped into the sentiments, ramping up his anti-Western rhetoric, much to the liking of his supporters. He has accused U.S. officials of harboring cleric Fethullah Gulen, who he blames for masterminding the coup attempt, and compared German officials to Nazis for refusing to allow Turkish deputies to campaign in Europe. Last week, he told Turkish citizens in Germany not to vote for Chancellor Angela Merkel in upcoming elections.

Perhaps the tough talk shouldn’t be read as a deterioration of relations with the West, but as part of Erdogan’s political strategy to help him win re-election in 2019. “In Turkey, there is a tradition where you score points if you tease allies,” Marc Pierini, a visiting scholar at Carnegie Europe and a former head of the EU diplomatic mission in Ankara, told me. “In my view, it’s the wrong assumption, but never mind that.”

To date, Turkey’s main economic partners remain the United States and European nations; viable alternatives have yet to materialize, Pierini noted. “[Turkish] leaders dream of being the independent power with equal distance from the U.S., the West, the EU, Russia, Iran and so on, and playing their own power games,” Pierini said. “That’s fine in principle, except that it’s very difficult to achieve in the sense that Turkey’s security is dependent on the West and NATO.”

Despite the rhetoric and despite America’s arming of Turkey’s adversaries, the two parties will likely “muddle along,” Pierini said. Turkey’s NATO membership is not at risk, and U.S. operations in Incirlik remain intact, though German soldiers were recently moved to Jordan after Berlin officials were repeatedly denied visiting rights.

To avoid further tensions, Mattis may play to Erdogan’s ego. A running theme in his speeches is the desire to make Turkey a world power and to be respected as a first-tier leader. President Donald Trump accommodated such ambitions by inviting Erdogan to Washington directly after he consolidated governing power through a referendum marred by irregularities.

“That’s the kind of soft diplomacy that makes up for our cooperation with the YPG,” Nick Danforth, senior analyst for the Bipartisan Policy Center's National Security Program, told me.At a strategic level, it’s bad for Turkey, but it gives Erdogan the prestige, it gives him the sense of being a major player that, with the [domestic] media under his control, he can pretty much spin however he wants.”

Meanwhile, Danforth said U.S. officials will probably keep quiet on Turkey’s deteriorating democracy and human rights abuses, as former Vice President Joe Biden and current Secretary of State Rex Tillerson both did during visits to Ankara.

Selim Koru, an analyst with the Economic Policy Research Foundation of Turkey, an Ankara-based think tank, said one way to radically ease tensions with Turkey might be to take measures against Gulen, who is currently living in exile in Pennsylvania. “Turks generally assume that there are wide margins for action here that the Obama and Trump administrations have chosen not to explore,” Koru said. “Even a few statements, at this point, would go a long way.”

During a stop in Baghdad on Tuesday, Mattis boasted that ISIS militants are “on the run” in Iraq. In Ankara, he will have to look beyond a victory in Raqqa to foster stability in the region. To a large extent, this will require some form of mediation between Turkey and Kurdish militants. Regardless of the difficulties involved in such a process, the two groups will be reshaping the region for years to come.