President Recep Tayyip Erdogan: "They are working to destroy our country's morale and create chaos." Credit:STR Just weeks before the New Year's Eve carnage in Istanbul, Russian ambassador Andrei Karlov was assassinated in Ankara, and the preceding months were punctuated by a series of devastating attacks, including a failed military coup in which more than 250 died in July, and a brazen triple suicide-bomb attack on Ataturk International Airport, in which 45 died in June. The upshot is chaos – mostly of Erdogan's making. Aydin Akay, a 66-year-old international jurist, was thrown into an over-crowded prison cell in September 2016 because he downloaded a message app from the internet. The brothers Ahmet and Mehmet Altan, one a novelist and the other an academic, were jailed for "subliminal messaging" in favour of the failed coup while being interviewed on TV; and Senol Buran, cafeteria manager at the opposition Cumhuriyet newspaper, was rounded up because he said he would refuse to serve a cup of tea to Erdogan. These four are merely the tip of a dictatorial iceberg. By one count, lawyers for the absurdly thin-skinned Erdogan have launched almost 3000 actions against Turks accused of insulting him, including a former Miss Turkey and a bunch of school kids.

A man with a Turkish flag walks past a police officer during a memorial outside the Reina club. The killer remains at large four days after the attack. Credit:Emrah Gurel But Erdogan casts a much wider net. In the wake of the failed coup, he has surpassed Iran and China as the world's leading jailers of journalists – about 150 are now believed to languish in Turkish prisons. They are not alone – more than 40,000 from the ranks of the parliament and the military and civilian services are also behind bars. Almost half of the admirals and generals have been axed from the military services and more than 110,000 have been sacked from their government jobs – teachers and cops, prosecutors and judges. The media has been shackled or shuttered and companies with assets valued at as much as $US10 billion have been seized as suspected coup sympathisers. A man adjusts a victim's photograph displayed with floral tributes and Turkish flags outside the Reina night club following the New Year's Day attack in Istanbul. Credit:Emrah Gurel Anyone outside the Turkey cognoscenti might be forgiven for asking a "WTF" question – what transformed Turkey so suddenly from a seemingly westernised, relatively liberal, bucket-list destination for tourists to an authoritarian regime that rules by decree, arresting journalists among tens of thousands of others and imposing media blackouts?

The answer, of course, is that this Turkish transformation has not been sudden. The bloodbath is newish, but the collapse of a country once held up as a model blend of democracy and Islam – but now is destined to be just another basket case in a region that festers with intolerance, repression and autocracy – has been years in the making. A framegrab on Sunday, January 1, 2017 of an attacker carrying a gun in the Reina nightclub in Istanbul. The gunman fired 180 rounds for seven minutes, killing 39 people. Credit:AP By one count, lawyers for the absurdly thin-skinned Erdogan have launched almost 3000 actions against Turks accused of insulting him, including a former Miss Turkey and a bunch of school kids. As the Turkish economy tanks, Erdogan obsesses about absolute power. Displeased by the outcome of one election, he calls another; using each terrorist attack as a building block in a Trump-like barrage of non-sequiturs, he emulates Russian leader Vladimir Putin's lunge at power – shifting from the prime ministership to the titular office of the presidency, into which he then demands that virtually all executive and government powers be vested … for the sake of the nation, of course! A power package that will go before the parliament soon and, if approved, then to a national referendum, will give Erdogan near-absolute power in this country of about 80 million people – he'll be able to appoint and sack deputy presidents, government ministers and a slew of state officials; retain leadership of the ruling party; impose emergency rule unilaterally; and hold office till as late as 2029.

A Turkish special security force member patrols near the scene of the nightclub attack. Credit:AP Farewell Jefferson; hello Saddam. In the aftermath of the nightclub massacre, Erdogan insisted yet again that the fight against terror would unite the country – "we will retain our cool-headedness as a nation, standing more closely together, and we will never give ground to such dirty games." Police have reportedly arrested the man responsible for the attack. Credit:AP Seemingly lost on Erdogan is that despite every crackdown and his claims that each will bring stability, the attacks keep coming – if not from within the ranks of his own military and security services, then internally from Kurdish separatists, and externally from Islamic State forces in neighbouring Syria and Iraq.

Apart from his general hunger for power, Erdogan's crucial recent mistakes were to allow foreign fighters to transit Turkey to join the Syrian civil war, thereby supporting IS which now launches attacks in Turkey; and in triggering a brutal new war with Kurdish militants, in which cities in the Kurdish southeast have been reduced to rubble, there was sufficient chaos in the country for elements in the military to believe it was time for them to invoke their assumed historic right to take corrective action – either by a real or threatened coup. After IS and the Kurdish militants, Erdogan's third security challenge is the movement headed by his former ally turned critic, the Muslim preacher Fethullah Gulen, who lives in self-imposed exile in Pennsylvania. Most recently Erdogan charged that Gulenists were behind the attempted military coup in July 2016 and the assassination of the Russian diplomat. But as the fear of violence mingles with the stark consequences of a collapsing currency and declining tourism and foreign investment, Turkish writer and European Council on Foreign Relations fellow Asli Aydintasbas told The New York Times: "nothing that the government is doing is helping make Turkey more secure – the crackdown on domestic dissidents is further destabilising the country, and when it is not destabilising, it's increasing the dangerous polarisation here." But Turkey is not an island. In the near century since the collapse of the Ottoman Empire, it has sat at a geopolitical crossroads and in the main it has looked westward, both as a member of the North Atlantic Treaty Organisation and as a long-aspiring member of the European Union – and, it should be noted, much frustrated by Europe's decades of inconclusive dawdling on the membership issue. Now that geopolitical construct is in play. In what might prove to be more a deliberate strategy than a feint to win concessions from Europe or Washington, Turkish officials charge that it is Europe that has rejected Turkey, not the reverse.

Somewhat diminished by the failure of his expectations to emerge as a regional powerbroker in the aftermath of the Arab Spring, Erdogan these days seeks the company of those he mimics – just weeks ago, as the EU seemed to be bolting the door against him, he suggested that Ankara might join the Shanghai Cooperation Organisation (SCO), a security and political pact between Russia, China and the smaller, mostly Turkic states of Central Asia. The SCO could give Turkey a new sphere of influence among countries with a shared linguistic and cultural heritage stretching all the way to Xinjiang in China's far west. And in the meantime, Erdogan is cosying up to Moscow in Syria, deferring to Putin despite significant strategic differences. Erdogan does have sticks with which to beat the West. Washington needs access to Turkish defence facilities to prosecute its air campaign against IS in Syria and Iraq – and though Erdogan has tempered his early criticism of Trump, his future relationship with the US will hinge on whether Trump and/or the American legal system will approve the extradition of Gulen from his exile's retreat in Pennsylvania. Though Brussels can't quite find the voice to say explicitly that it doesn't want Turkey as a EU member that does seem to be the message, which poses grave questions about the viability of the multi-billion euro deal by which the EU pays Turkey to check the flow of refugees to Europe.

Worth more than 5 billion Euros over three years, the deal helps Turkey to host nearly 3 million refugees in Turkey rather than have them travel to EU member countries. And for the Europeans, that's a price worth paying – the rate of refugee arrivals in Greece in November was as low as 100 a day, compared with 2000 a day a year earlier. Reacting to the EU rejection, Erdogan threatened Europe with a new migrant flood – "You did not keep your word … if you go further, those border gates will open. You should know that," the president said. Erdogan's domestic opponents watch uneasily. "[His] real aim is to take Turkey out of the Western bloc, out of the civilised world, and to turn Turkey into a Middle Eastern country where he can continue to rule without any obstacle – he wants to turn Turkey into a country where there is no secularism and where people are divided along their ethnic identity and beliefs," according to Kemal Kilicdaroglu, leader of the opposition Republican People's Party (CHP). "It's becoming a nation that faces internal conflict, just as we have seen in Iraq, Syria and Libya," Mr Kilicdaroglu told The Wall Street Journal.

The historic challenge for Turkish leaders has been to effectively manage the country's internal fault lines – be they religious or ethnic. His predecessors followed the secular path of Mustafa Kemal Ataturk, founder of the modern state, who suppressed religion and airbrushed the Kurds out of existence by insisting that all were Turks in his one-party state. But while Erdogan has veered towards his own Islamist leanings, he is driven more by his own autocratic sense of power and a Putin-like chip on his shoulder about big-power respect for his sense of his own importance, on the regional and world stage. Erdogan doesn't quite have the parliamentary numbers he needs and as argued by Soner Cagaptay, of the Washington Institute for Near East Policy: "Herein lies the permanent crisis into which Erdogan's agenda has thrown Turkey. "As Erdogan moves forward to make himself executive-style president, half of the country will never embrace his agenda. Even more worrisome in this crisis, the country is torn, with the pro- and anti-Erdogan blocs' hatred of each other overshadowing their fear of terrorist attacks by the [Islamic State ] or the Kurdistan Workers' Party." Critics were quick to note that the attack on the Istanbul nightclub came in the wake of a recent sermon, distributed to mosques across the country by government-appointed religious leaders, denouncing New Year celebrations as a part of "other cultures and other worlds" and that it was "never suitable for a believer to forget himself … [by exhibiting] illicit manners and behaviours that don't comply with our values."

Professor Howard Eissenstat, a Turkey expert at St Lawrence University in New York, pounced after the attack, tweeting: "Disturbing + not very difficult line to draw between official Turkish anti New Years campaign + tonight's violence. Rhetoric has consequences." Historically, Turkey has been a hotbed of conspiracy theories, a political art form in which Erdogan has proved as adept as incoming US president Donald Trump. Many Turks still insist that Washington was complicit in the Turkish military coups of 1960, 1971 and 1980 – and these days Erdogan's surrogates readily claim the US was complicit in the failed coup of 2016, the rise of IS, and the Istanbul nightclub massacre. Erdogan has made effective political use of conspiracy theories, pulling voters his way with grand claims that his or the country's enemies must be thwarted – and famously retorting when challenged in 2013: "if it's a witch hunt to fire those who engage in treason, then it is a witch hunt." By the reckoning of some observers the notion that modern Turkey had been "westernised" is something of a misnomer. Eastern and central Turkey, where Erdogan draws his most loyal support, have never westernised; and the tourist regions of Istanbul and the Aegean coast were liberalised more from a tourist's or an economist's perspective than they were from a citizen's or a dissident's. These days those tourist regions are suffering blowback from Erdogan's ham-fisted efforts to tame the southeastern Kurdish militants and his meddling elsewhere in the region in the aftermath of the Arab Spring.

Despite his tightening regime of fear, some of Erdogan's former colleagues criticise the president openly. Former AKP parliamentarian and judge Osman Can seemed reckless in this frank assessment to The Wall Street Journal: "The institutions have failed. We have no institutions that can provide rational decisions on policy. Everything now is in the hands of one man, Mr Erdogan, and when just one man is deciding everything, there is no future for Turkey."