package com.peachpasswords.ui.pairing import androidx.activity.compose.BackHandler import androidx.compose.material3.AlertDialog import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.text.font.FontWeight import com.peachpasswords.ui.theme.LocalPeachAccent import com.peachpasswords.ui.theme.PeachType enum class BackgroundSyncAction { ALLOW, MANUAL_ONLY, DISMISS } internal fun shouldPromptForBackgroundSync(pairingSucceeded: Boolean): Boolean = pairingSucceeded internal fun backgroundSyncChoice(action: BackgroundSyncAction): Boolean = action != BackgroundSyncAction.MANUAL_ONLY @Composable fun BackgroundSyncDialog( onChoice: (Boolean) -> Unit, ) { // Dismissal takes the recommended default so pairing cannot fall back into the broken unreachable state. BackHandler { onChoice(backgroundSyncChoice(BackgroundSyncAction.DISMISS)) } AlertDialog( onDismissRequest = { onChoice(backgroundSyncChoice(BackgroundSyncAction.DISMISS)) }, title = { Text("Sync in the background?", fontFamily = PeachType.Display) }, text = { Text( "Allow Peach to keep your devices in step in the background, even when the app isn't open. " + "This keeps a small notification visible while sync is active and uses a tiny bit of battery.", fontFamily = PeachType.Body, ) }, confirmButton = { TextButton(onClick = { onChoice(backgroundSyncChoice(BackgroundSyncAction.ALLOW)) }) { Text( "Allow background sync", color = LocalPeachAccent.current, fontWeight = FontWeight.Bold, ) } }, dismissButton = { TextButton(onClick = { onChoice(backgroundSyncChoice(BackgroundSyncAction.MANUAL_ONLY)) }) { Text("Sync manually only") } }, ) }