package com.suno.android.ui.screens.onboarding.phone.validate import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.suno.android.common_ui.components.loading.SunoSpinner import com.suno.android.common_ui.components.omni.CircleIconButton import com.suno.android.common_ui.theme.ExtendedTheme import com.suno.android.common_ui.theme.NavBarSelection import com.suno.android.common_res.R as CommonResR @Composable fun LoginValidatePhoneNumberScreen( vm: LoginValidatePhoneNumberScreenVM, onPhoneCodeValidated: (isSignUpFlow: Boolean) -> Unit, onBackPressed: () -> Unit, ) { LaunchedEffect(Unit) { vm.effects.collect { effect -> when (effect) { is LoginValidatePhoneNumberScreenEffect.OnPhoneCodeValidated -> { onPhoneCodeValidated.invoke(effect.isSignUpFlow) } } } } var phoneValidationCodeInput by remember { mutableStateOf("") } val viewState = vm.state.collectAsStateWithLifecycle().value Column( modifier = Modifier .fillMaxSize() .imePadding() .background(ExtendedTheme.colors.backgroundPrimary), horizontalAlignment = Alignment.CenterHorizontally, ) { Row( modifier = Modifier .navigationBarsPadding() .systemBarsPadding() .fillMaxWidth() .height(64.dp) .padding(8.dp), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically, ) { CircleIconButton( vectorDrawableResId = com.suno.android.common_ui.R.drawable.arrow_left, contentDescription = "Back", onClick = { onBackPressed() }, ) Text( text = stringResource(CommonResR.string.enter_confirmation_code), style = ExtendedTheme.typography.largeBody, color = ExtendedTheme.colors.textPrimary, ) CircleIconButton( modifier = Modifier.alpha(0f), vectorDrawableResId = com.suno.android.common_ui.R.drawable.close, contentDescription = "Close", ) } Column( modifier = Modifier.fillMaxHeight(), verticalArrangement = Arrangement.Center, ) { Box( modifier = Modifier .weight(1f) .fillMaxWidth(), contentAlignment = Alignment.Center, ) { TextField( modifier = Modifier.fillMaxWidth(), value = viewState.smsCode ?: "", onValueChange = { textInput -> phoneValidationCodeInput = textInput vm.sendEvent( LoginValidatePhoneNumberScreenEvent.OnVerificationCodeEnteredEvent( verificationCode = textInput, ), ) }, keyboardOptions = KeyboardOptions.Default.copy( keyboardType = KeyboardType.Phone, imeAction = ImeAction.Done, ), placeholder = { Text( modifier = Modifier.fillMaxWidth(), text = "XXXXXX", style = ExtendedTheme.typography.largeBody.copy( textAlign = TextAlign.Center, fontSize = 32.sp, ), color = Color.Gray, ) }, textStyle = ExtendedTheme.typography.largeBody.copy( textAlign = TextAlign.Center, fontSize = 32.sp, color = ExtendedTheme.colors.textPrimary, ), colors = TextFieldDefaults.colors( unfocusedContainerColor = Color.Transparent, focusedContainerColor = Color.Transparent, unfocusedIndicatorColor = Color.Transparent, focusedIndicatorColor = Color.Transparent, focusedTextColor = ExtendedTheme.colors.textPrimary, unfocusedTextColor = ExtendedTheme.colors.textPrimary, cursorColor = NavBarSelection, ), singleLine = true, ) } Button( modifier = Modifier .fillMaxWidth() .padding(8.dp) .navigationBarsPadding(), shape = RoundedCornerShape(8.dp), colors = ButtonDefaults.buttonColors( ExtendedTheme.colors.backgroundInvert, ), enabled = phoneValidationCodeInput.isNotBlank() && !viewState.loading, onClick = { vm.sendEvent( LoginValidatePhoneNumberScreenEvent.OnVerificationCodeSubmitted( verificationCode = phoneValidationCodeInput, ), ) }, ) { if (viewState.loading) { SunoSpinner( modifier = Modifier .alpha(0.5f) .padding(horizontal = 8.dp) .size(32.dp), ) } Text( modifier = Modifier.padding(8.dp), text = if (viewState.loading) { stringResource(CommonResR.string.loading) } else { stringResource(CommonResR.string.confirm) }, color = ExtendedTheme.colors.backgroundPrimary, ) } } } }