package com.example.ui.screens import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.* import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.font.FontWeight 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 com.example.data.model.AppLanguage import com.example.ui.components.CustomLabeledTextField import com.example.ui.theme.* @Composable fun AuthScreen( lang: AppLanguage, onAuthSuccess: (name: String, phone: String, isNidVerified: Boolean) -> Unit, modifier: Modifier = Modifier ) { var isRegisterTab by remember { mutableStateOf(false) } var phoneInput by remember { mutableStateOf("1712345678") } var nameInput by remember { mutableStateOf("Mohammad Shakib") } var otpOrPassword by remember { mutableStateOf("123456") } var nidInput by remember { mutableStateOf("19952691234567890") } var verifyNidChecked by remember { mutableStateOf(true) } var errorMessage by remember { mutableStateOf(null) } var isLoading by remember { mutableStateOf(false) } Scaffold( containerColor = MaterialTheme.colorScheme.background, modifier = modifier.fillMaxSize() ) { innerPadding -> Column( modifier = Modifier .fillMaxSize() .padding(innerPadding) .statusBarsPadding() .navigationBarsPadding() .verticalScroll(rememberScrollState()) .padding(24.dp), horizontalAlignment = Alignment.CenterHorizontally ) { Spacer(modifier = Modifier.height(16.dp)) // Logo & Title Box( modifier = Modifier .size(64.dp) .clip(RoundedCornerShape(18.dp)) .background(BrandNavyPrimary), contentAlignment = Alignment.Center ) { Icon( imageVector = Icons.Default.Shield, contentDescription = null, tint = Color.White, modifier = Modifier.size(36.dp) ) } Spacer(modifier = Modifier.height(16.dp)) Text( text = if (lang == AppLanguage.BN) "সতর্ক বিডি অ্যাকাউন্ট" else "Satark BD Account", style = MaterialTheme.typography.headlineSmall.copy( fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.onBackground ) ) Text( text = if (lang == AppLanguage.BN) "সুরক্ষিতভাবে লগইন করে অভিযোগ জমা ও কোম্পানি যাচাই করুন" else "Log in securely to verify entities and submit fraud reports", style = MaterialTheme.typography.bodySmall.copy( color = LightTextSecondary, textAlign = TextAlign.Center ), modifier = Modifier.padding(top = 4.dp) ) Spacer(modifier = Modifier.height(24.dp)) // Segmented Tab for Login / Register Surface( color = LightSurfaceVariant, shape = RoundedCornerShape(12.dp), modifier = Modifier.fillMaxWidth() ) { Row( modifier = Modifier.padding(4.dp) ) { Surface( onClick = { isRegisterTab = false; errorMessage = null }, color = if (!isRegisterTab) BrandNavyPrimary else Color.Transparent, shape = RoundedCornerShape(8.dp), modifier = Modifier .weight(1f) .height(44.dp) .testTag("tab_login") ) { Box(contentAlignment = Alignment.Center) { Text( text = if (lang == AppLanguage.BN) "লগইন (Login)" else "Login", style = MaterialTheme.typography.labelLarge.copy( fontWeight = FontWeight.Bold, color = if (!isRegisterTab) Color.White else LightTextSecondary ) ) } } Surface( onClick = { isRegisterTab = true; errorMessage = null }, color = if (isRegisterTab) BrandNavyPrimary else Color.Transparent, shape = RoundedCornerShape(8.dp), modifier = Modifier .weight(1f) .height(44.dp) .testTag("tab_register") ) { Box(contentAlignment = Alignment.Center) { Text( text = if (lang == AppLanguage.BN) "নিবন্ধন (Register)" else "Register", style = MaterialTheme.typography.labelLarge.copy( fontWeight = FontWeight.Bold, color = if (isRegisterTab) Color.White else LightTextSecondary ) ) } } } } Spacer(modifier = Modifier.height(20.dp)) // Fields if (isRegisterTab) { CustomLabeledTextField( label = if (lang == AppLanguage.BN) "আপনার পূর্ণ নাম (Full Name)" else "Full Name", value = nameInput, onValueChange = { nameInput = it }, placeholder = if (lang == AppLanguage.BN) "যেমন: মোহাম্মদ সাকিব" else "e.g., Mohammad Shakib", isRequired = true, leadingIcon = Icons.Default.Person, testTag = "input_auth_name" ) Spacer(modifier = Modifier.height(16.dp)) } // Phone Number Input with BD flag / prefix Column(modifier = Modifier.fillMaxWidth()) { Text( text = if (lang == AppLanguage.BN) "বাংলাদেশি মোবাইল নম্বর" else "Bangladeshi Mobile Number", style = MaterialTheme.typography.labelLarge.copy( fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onSurface ), modifier = Modifier.padding(bottom = 6.dp) ) Row( modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically ) { Surface( color = LightSurfaceVariant, shape = RoundedCornerShape(10.dp), border = androidx.compose.foundation.BorderStroke(1.dp, LightOutline), modifier = Modifier.height(56.dp) ) { Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(horizontal = 12.dp) ) { Text(text = "🇧🇩 +880", style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.Bold)) } } Spacer(modifier = Modifier.width(8.dp)) OutlinedTextField( value = phoneInput, onValueChange = { phoneInput = it }, placeholder = { Text("17XXXXXXXX") }, singleLine = true, keyboardOptions = androidx.compose.foundation.text.KeyboardOptions(keyboardType = KeyboardType.Phone), shape = RoundedCornerShape(10.dp), colors = OutlinedTextFieldDefaults.colors( focusedBorderColor = BrandBlueAccent, unfocusedBorderColor = LightOutline, focusedContainerColor = MaterialTheme.colorScheme.surface, unfocusedContainerColor = MaterialTheme.colorScheme.surface ), modifier = Modifier .weight(1f) .testTag("input_auth_phone") ) } } Spacer(modifier = Modifier.height(16.dp)) CustomLabeledTextField( label = if (isRegisterTab) { if (lang == AppLanguage.BN) "পাসওয়ার্ড অথবা ওটিপি পিন" else "Password or OTP PIN" } else { if (lang == AppLanguage.BN) "পাসওয়ার্ড" else "Password" }, value = otpOrPassword, onValueChange = { otpOrPassword = it }, placeholder = "••••••••", isRequired = true, leadingIcon = Icons.Default.Lock, keyboardType = KeyboardType.Password, testTag = "input_auth_password" ) if (isRegisterTab) { Spacer(modifier = Modifier.height(16.dp)) CustomLabeledTextField( label = if (lang == AppLanguage.BN) "জাতীয় পরিচয়পত্র নম্বর (ঐচ্ছিক NID)" else "National ID No (Optional NID)", value = nidInput, onValueChange = { nidInput = it }, placeholder = "10 or 17 digit NID", isRequired = false, leadingIcon = Icons.Default.Badge, keyboardType = KeyboardType.Number, testTag = "input_auth_nid" ) Spacer(modifier = Modifier.height(12.dp)) Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth() ) { Checkbox( checked = verifyNidChecked, onCheckedChange = { verifyNidChecked = it }, colors = CheckboxDefaults.colors(checkedColor = BrandNavyPrimary) ) Spacer(modifier = Modifier.width(4.dp)) Text( text = if (lang == AppLanguage.BN) "নাগরিক নিরাপত্তা যাচাই ও বিশ্বস্ত রিপোর্টার ব্যাজ অনুমোদন করুন" else "Request Verified Citizen Reporter status", style = MaterialTheme.typography.bodySmall.copy(color = LightTextSecondary) ) } } if (errorMessage != null) { Spacer(modifier = Modifier.height(8.dp)) Surface( color = StatusWarningRedBg, shape = RoundedCornerShape(8.dp), modifier = Modifier.fillMaxWidth() ) { Text( text = errorMessage ?: "", color = StatusWarningRed, style = MaterialTheme.typography.bodySmall.copy(fontWeight = FontWeight.Medium), modifier = Modifier.padding(10.dp) ) } } Spacer(modifier = Modifier.height(24.dp)) // Primary Action Button Button( onClick = { if (phoneInput.length < 9) { errorMessage = if (lang == AppLanguage.BN) "সঠিক মোবাইল নম্বর দিন" else "Please enter a valid mobile number" } else { errorMessage = null onAuthSuccess( if (isRegisterTab) nameInput else "Mohammad Shakib", "+880 $phoneInput", verifyNidChecked ) } }, colors = ButtonDefaults.buttonColors(containerColor = BrandNavyPrimary), shape = RoundedCornerShape(12.dp), modifier = Modifier .fillMaxWidth() .height(52.dp) .testTag("btn_auth_submit") ) { Text( text = if (isRegisterTab) { if (lang == AppLanguage.BN) "নিবন্ধন সম্পন্ন করুন" else "Complete Registration" } else { if (lang == AppLanguage.BN) "লগইন করুন" else "Log In" }, style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold) ) } Spacer(modifier = Modifier.height(14.dp)) // Continue as Guest Option OutlinedButton( onClick = { onAuthSuccess("Guest Citizen", "+880 1700-000000", false) }, shape = RoundedCornerShape(12.dp), border = androidx.compose.foundation.BorderStroke(1.dp, LightOutline), modifier = Modifier .fillMaxWidth() .height(50.dp) .testTag("btn_auth_guest") ) { Icon( imageVector = Icons.Default.Visibility, contentDescription = null, tint = LightTextSecondary, modifier = Modifier.size(18.dp) ) Spacer(modifier = Modifier.width(8.dp)) Text( text = if (lang == AppLanguage.BN) "অতিথি হিসেবে ব্রাউজ করুন (Guest Mode)" else "Continue as Guest", style = MaterialTheme.typography.bodyMedium.copy( color = LightTextSecondary, fontWeight = FontWeight.SemiBold ) ) } Spacer(modifier = Modifier.height(24.dp)) // Trust info notice Surface( color = Color(0xFFF1F5F9), shape = RoundedCornerShape(10.dp), modifier = Modifier.fillMaxWidth() ) { Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(12.dp) ) { Icon( imageVector = Icons.Default.Lock, contentDescription = null, tint = BrandCyan, modifier = Modifier.size(18.dp) ) Spacer(modifier = Modifier.width(10.dp)) Text( text = if (lang == AppLanguage.BN) "আপনার তথ্য ডিজিটাল নিরাপত্তা ও ব্যক্তিগত গোপনীয়তা আইন অনুযায়ী সুরক্ষিত।" else "Your personal data is encrypted & protected under BD Data Privacy Standards.", style = MaterialTheme.typography.bodySmall.copy( color = LightTextMuted, fontSize = 11.sp ) ) } } } } }