Tunisia has reason to fear a terror attack. The only democracy that emerged from the turmoil of the 2011 Arab Spring has seen more of its young men join the Islamic State group than any other nation, and many have returned, battle-hardened, to spread radical ideologies back home.
Moreover, Tunisia is also a country full of vulnerable targets, with an economy that depends on welcoming European tourists to its warm Mediterranean shore.
Despite having so much at stake, the shocking slayings of 22 tourists at the national museum in March failed to persuade lawmakers to resolve their debate over an anti-terror strategy proposed more than a year earlier. Only now -- after a single jihadi from a gritty Tunisian town was able to kill 38 tourists at a seaside resort -- does the government appear ready to launch a comprehensive response.
"We decided today to pass the counter-terrorism law before Republic Day on July 25," Parliament president Mohamed Ennaceur said while visiting survivors of Friday's attack at a hospital. "We will be after the government to take the necessary measures in all areas to fight against terrorism."
The new anti-terrorism law would increase police powers and provide for harsher penalties, moves that worry human rights activists. It also would create a commission to devise a strategy to tackle the roots of terrorism by addressing terror's economic and social causes, and creating "de-radicalization" centers to change minds through persuasion, not prison.
The law has been stuck in committees since it was first proposed in January 2014 as leaders of the coalition government sought to balance reform and repression. That is a difficult challenge in any democracy, even more so in a country that knew only one-party rule for 50 years before the overthrow of dictator Zine El Abidine Ben Ali.
In the security vacuum that followed the fall of his police state, ultraconservative Islamic groups flourished, and when their demands were denied, they began attacking politicians and police.
With technical help from the US and other countries, Tunisia's security forces have slowly been rebuilt and are becoming more effective in hunting down terror cells and ramping up arrests of alleged extremists. But none of this stopped the 24-year-old Seifeddine Rezgui from pulling an assault rifle and three grenades out of a beach umbrella and hunting down tourists at a resort hotel.
Even before this latest attack, Tunisia's point-man on terrorism, Rafik Chelli, acknowledged that tougher policing alone can't do the job.
"Only the security approach has been really implemented and it has not been sufficient on its own," Chelli told The Associated Press recently.
Immediately afterward, Prime Minister Habib Essid said armed guards would be placed at tourist sites, and that mosques outside control of the government would be closed. Essid also announced financial rewards for information leading to arrests.
The new law promises a more holistic response, but lawmakers have to get it right, Chelli said. The key "is to ensure that these measures respect freedoms and human rights and the security of the country".
Chelli blames much of the situation on the Ennahda, the moderate Islamist party that was elected immediately after the revolution and lost power in the 2014 elections. He said the party was too lenient on security and "actively encouraged youth to leave for the jihad".
Ennahda leader Rachid Ghannouchi counters that his moderate brand of Islam has kept more people from falling under the ideology promoted by Islamic State, also known by its Arabic acronym Daesh. He blames much of the extremism on Ben Ali's draconian secularist rule.
"Ben Ali's repressive policies favored the emergence of extremism among the youth," Ghannouchi told the AP. "Daesh is a wrong and extremist interpretation of Islam. The bad merchandise must be fought with a quality product, and moderate Islam is the alternative to Daesh and al-Qaida."
Tunisia must engage in this battle of ideas and take back the terrain of religion that it surrendered to extremists, said Sami Brahem, a researcher at Tunisia's Center for Economic and Social Studies and Research who advised the government on its strategy. "The dogma of the radical groups is fragile and can't hold up in arguments against the fundamentals of Islam," he said. The new law does have its detractors.
Human Rights Watch says the law's ambiguous definition of terrorism and weakened due process rights are a backward step for Tunisia. It could permit government to repress a wide range of internationally protected freedoms, the group said. For example, public demonstrations that lead to "harming private and public property" or disrupting public services could be prosecuted as terrorist acts and police could hold suspects incommunicado without charges for up to 15 days.
Moncef Kartas, a researcher on Tunisian security issues, said these harsher security measures could even be counterproductive because they do not address deeper cleavages in Tunisian society that have left so many young men marginalised, frustrated and hopeless. The government has to reach out to neglected communities where only radical voices are heard, he said.
Last fall's parliamentary elections were hailed around the world, but just 20% of young people voted. Many feel disillusioned by the country's slow and uneven economic growth, and abandoned by their leaders. Police are often the only government representatives many people see.
Radicalisation of the youth is a problem across the region but especially acute in Tunisia. Some 3,000 of its citizens have left to join extremist groups in Syria, Iraq and Libya, and at least 500 are believed to have returned. Many see police as the enemy.
"Police beat kids up, insult them and arrest them," said Bilal Saadaoui, a 23-year-old breakdancer from Tadamon, the tough neighborhood where police say militants radicalised Rezgui. Police disappeared after the revolution, but then "they came back stronger, with reinforcements. We just have rocks and they have guns and tear gas", he said.
Scaring off the tourist economy will only make it harder for the government to make good on its promises but these people must be shown that "they are not forgotten", Kartas said.