package com.example.ui.screens import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items 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.material.icons.outlined.* 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.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.data.model.AlertSeverity import com.example.data.model.AppLanguage import com.example.data.model.PublicWarning import com.example.ui.theme.* import com.example.ui.util.Localization @Composable fun PublicWarningsScreen( warnings: List, selectedWarningId: String?, lang: AppLanguage, onSelectWarning: (String?) -> Unit, onStartReportForWarning: (String) -> Unit, modifier: Modifier = Modifier ) { var selectedDivisionFilter by remember { mutableStateOf(null) } val divisions = listOf("Nationwide (সারাদেশ)", "Dhaka (ঢাকা)", "Chittagong (চট্টগ্রাম)", "Rajshahi (রাজশাহী)") val filteredWarnings = remember(warnings, selectedDivisionFilter) { if (selectedDivisionFilter == null) warnings else warnings.filter { it.division.contains(selectedDivisionFilter?.substringBefore(" ") ?: "", ignoreCase = true) } } val activeWarning = remember(warnings, selectedWarningId) { if (selectedWarningId != null) warnings.find { it.id == selectedWarningId } else null } if (activeWarning != null) { // Detailed Advisory Screen Scaffold( containerColor = MaterialTheme.colorScheme.background, topBar = { Surface( color = BrandNavyPrimary, modifier = Modifier.fillMaxWidth() ) { Row( modifier = Modifier .fillMaxWidth() .statusBarsPadding() .padding(horizontal = 8.dp, vertical = 8.dp), verticalAlignment = Alignment.CenterVertically ) { IconButton(onClick = { onSelectWarning(null) }) { Icon(Icons.Default.ArrowBack, contentDescription = "Back", tint = Color.White) } Text( text = if (lang == AppLanguage.BN) "সতর্কবার্তা বিস্তারিত" else "Warning Advisory Details", style = MaterialTheme.typography.titleMedium.copy( fontWeight = FontWeight.Bold, color = Color.White ) ) } } }, bottomBar = { Surface( color = MaterialTheme.colorScheme.surface, tonalElevation = 8.dp, border = androidx.compose.foundation.BorderStroke(1.dp, LightOutline), modifier = Modifier.fillMaxWidth() ) { Row( modifier = Modifier .fillMaxWidth() .padding(16.dp) .navigationBarsPadding(), horizontalArrangement = Arrangement.spacedBy(12.dp) ) { OutlinedButton( onClick = { onSelectWarning(null) }, shape = RoundedCornerShape(12.dp), modifier = Modifier.weight(1f) ) { Text(if (lang == AppLanguage.BN) "তালিকায় ফিরুন" else "Close") } Button( onClick = { onStartReportForWarning(activeWarning.targetName) }, colors = ButtonDefaults.buttonColors(containerColor = StatusWarningRed), shape = RoundedCornerShape(12.dp), modifier = Modifier.weight(1.5f) ) { Icon(Icons.Default.AddAlert, contentDescription = null, modifier = Modifier.size(16.dp)) Spacer(modifier = Modifier.width(6.dp)) Text(if (lang == AppLanguage.BN) "ভুক্তভোগী হিসেবে রিপোর্ট" else "I am a Victim") } } } }, modifier = modifier.fillMaxSize() ) { innerPadding -> Column( modifier = Modifier .fillMaxSize() .padding(innerPadding) .verticalScroll(rememberScrollState()) .padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp) ) { // Urgency Header Card Surface( color = StatusWarningRedBg, shape = RoundedCornerShape(14.dp), border = androidx.compose.foundation.BorderStroke(1.dp, StatusWarningRed.copy(alpha = 0.4f)), modifier = Modifier.fillMaxWidth() ) { Column(modifier = Modifier.padding(16.dp)) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Surface( color = StatusWarningRed, shape = RoundedCornerShape(6.dp) ) { Text( text = if (lang == AppLanguage.BN) "জরুরি সতর্কবার্তা" else "PUBLIC CRITICAL ALERT", color = Color.White, style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.Bold), modifier = Modifier.padding(horizontal = 8.dp, vertical = 3.dp) ) } Text( text = activeWarning.date, style = MaterialTheme.typography.labelSmall.copy(color = Color(0xFF7F1D1D)) ) } Spacer(modifier = Modifier.height(10.dp)) Text( text = if (lang == AppLanguage.BN) activeWarning.titleBn else activeWarning.titleEn, style = MaterialTheme.typography.titleLarge.copy( fontWeight = FontWeight.Bold, color = Color(0xFF7F1D1D) ) ) Spacer(modifier = Modifier.height(8.dp)) Text( text = "${if (lang == AppLanguage.BN) "অভিযুক্ত চক্র/প্রতিষ্ঠান:" else "Target Syndicate:"} ${activeWarning.targetName}", style = MaterialTheme.typography.bodyMedium.copy( fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onSurface ) ) } } // Stats on victims and loss Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(10.dp) ) { Surface( color = MaterialTheme.colorScheme.surface, shape = RoundedCornerShape(12.dp), border = androidx.compose.foundation.BorderStroke(1.dp, LightOutline), modifier = Modifier.weight(1f) ) { Column(modifier = Modifier.padding(12.dp)) { Text( text = if (lang == AppLanguage.BN) "ভুক্তভোগী সংখ্যা" else "Reported Victims", style = MaterialTheme.typography.labelSmall.copy(color = LightTextMuted) ) Text( text = "${Localization.formatNumber(activeWarning.victimsCount, lang)}+ জন", style = MaterialTheme.typography.titleMedium.copy( fontWeight = FontWeight.Black, color = StatusWarningRed ) ) } } Surface( color = MaterialTheme.colorScheme.surface, shape = RoundedCornerShape(12.dp), border = androidx.compose.foundation.BorderStroke(1.dp, LightOutline), modifier = Modifier.weight(1f) ) { Column(modifier = Modifier.padding(12.dp)) { Text( text = if (lang == AppLanguage.BN) "আনুমানিক হাতিয়ে নেওয়া অর্থ" else "Estimated Loss", style = MaterialTheme.typography.labelSmall.copy(color = LightTextMuted) ) Text( text = activeWarning.estimatedLossBdt, style = MaterialTheme.typography.titleMedium.copy( fontWeight = FontWeight.Black, color = BrandNavyPrimary ) ) } } } // Modus Operandi & Trap Steps Surface( color = MaterialTheme.colorScheme.surface, shape = RoundedCornerShape(12.dp), border = androidx.compose.foundation.BorderStroke(1.dp, LightOutline), modifier = Modifier.fillMaxWidth() ) { Column(modifier = Modifier.padding(16.dp)) { Row(verticalAlignment = Alignment.CenterVertically) { Icon(Icons.Default.Security, contentDescription = null, tint = BrandNavyPrimary) Spacer(modifier = Modifier.width(8.dp)) Text( text = if (lang == AppLanguage.BN) "প্রতারণার কৌশল ও কীভাবে বাঁচবেন" else "Modus Operandi & Prevention", style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold) ) } Spacer(modifier = Modifier.height(10.dp)) Text( text = if (lang == AppLanguage.BN) activeWarning.modusOperandiBn else activeWarning.modusOperandiEn, style = MaterialTheme.typography.bodyMedium.copy( lineHeight = 22.sp, color = MaterialTheme.colorScheme.onSurface ) ) } } // Official Notice if (activeWarning.officialNoticeRef != null) { Surface( color = LightSurfaceVariant, shape = RoundedCornerShape(10.dp), modifier = Modifier.fillMaxWidth() ) { Row( modifier = Modifier.padding(12.dp), verticalAlignment = Alignment.CenterVertically ) { Icon(Icons.Default.Gavel, contentDescription = null, tint = BrandNavyPrimary) Spacer(modifier = Modifier.width(10.dp)) Column { Text( text = if (lang == AppLanguage.BN) "সরকারি রেফারেন্স ও বিজ্ঞপ্তি" else "Official Regulatory Reference", style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.Bold) ) Text( text = activeWarning.officialNoticeRef, style = MaterialTheme.typography.bodySmall.copy(color = LightTextSecondary) ) } } } } } } return } // LIST VIEW OF PUBLIC WARNINGS Column( modifier = modifier .fillMaxSize() .background(MaterialTheme.colorScheme.background) ) { // Division Filter Chips Surface( color = MaterialTheme.colorScheme.surface, tonalElevation = 2.dp, modifier = Modifier.fillMaxWidth() ) { LazyRow( contentPadding = PaddingValues(horizontal = 16.dp, vertical = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp) ) { item { FilterChip( selected = selectedDivisionFilter == null, onClick = { selectedDivisionFilter = null }, label = { Text(if (lang == AppLanguage.BN) "সকল অঞ্চল" else "All Regions") }, colors = FilterChipDefaults.filterChipColors( selectedContainerColor = BrandNavyPrimary, selectedLabelColor = Color.White ) ) } items(divisions) { div -> FilterChip( selected = selectedDivisionFilter == div, onClick = { selectedDivisionFilter = if (selectedDivisionFilter == div) null else div }, label = { Text(div) }, colors = FilterChipDefaults.filterChipColors( selectedContainerColor = BrandNavyPrimary, selectedLabelColor = Color.White ) ) } } } LazyColumn( modifier = Modifier .fillMaxSize() .padding(horizontal = 16.dp), contentPadding = PaddingValues(top = 12.dp, bottom = 80.dp), verticalArrangement = Arrangement.spacedBy(12.dp) ) { items(filteredWarnings) { warning -> Surface( onClick = { onSelectWarning(warning.id) }, shape = RoundedCornerShape(14.dp), color = MaterialTheme.colorScheme.surface, border = androidx.compose.foundation.BorderStroke( 1.dp, if (warning.severity == AlertSeverity.CRITICAL_RED) StatusWarningRed.copy(alpha = 0.4f) else LightOutline ), shadowElevation = 2.dp, modifier = Modifier .fillMaxWidth() .testTag("public_warning_${warning.id}") ) { Column(modifier = Modifier.padding(16.dp)) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Surface( color = when (warning.severity) { AlertSeverity.CRITICAL_RED -> StatusWarningRedBg AlertSeverity.HIGH_AMBER -> StatusAmberBg AlertSeverity.ADVISORY_BLUE -> StatusReviewBlueBg }, shape = RoundedCornerShape(6.dp) ) { Text( text = if (warning.severity == AlertSeverity.CRITICAL_RED) "🚨 ${if (lang == AppLanguage.BN) "জরুরি সতর্কবার্তা" else "Critical"}" else "⚠️ ${if (lang == AppLanguage.BN) "উচ্চ সতর্কতা" else "High Risk"}", color = when (warning.severity) { AlertSeverity.CRITICAL_RED -> StatusWarningRed AlertSeverity.HIGH_AMBER -> StatusAmber AlertSeverity.ADVISORY_BLUE -> StatusReviewBlue }, style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.Bold), modifier = Modifier.padding(horizontal = 8.dp, vertical = 3.dp) ) } Text( text = warning.division, style = MaterialTheme.typography.labelSmall.copy(color = LightTextMuted) ) } Spacer(modifier = Modifier.height(10.dp)) Text( text = if (lang == AppLanguage.BN) warning.titleBn else warning.titleEn, style = MaterialTheme.typography.titleMedium.copy( fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.onSurface ) ) Spacer(modifier = Modifier.height(6.dp)) Text( text = if (lang == AppLanguage.BN) warning.summaryBn else warning.summaryEn, style = MaterialTheme.typography.bodyMedium.copy( color = LightTextSecondary, lineHeight = 18.sp ), maxLines = 3, overflow = TextOverflow.Ellipsis ) Spacer(modifier = Modifier.height(12.dp)) Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Text( text = "${if (lang == AppLanguage.BN) "ভুক্তভোগী:" else "Victims:"} ${Localization.formatNumber(warning.victimsCount, lang)}+ (${warning.estimatedLossBdt})", style = MaterialTheme.typography.labelSmall.copy( color = StatusWarningRed, fontWeight = FontWeight.Bold ) ) Text( text = if (lang == AppLanguage.BN) "বিস্তারিত ও প্রতিরোধ টিপস ›" else "Prevention Tips ›", style = MaterialTheme.typography.labelSmall.copy( color = BrandNavyPrimary, fontWeight = FontWeight.Bold ) ) } } } } } } }