package com.example.ui.screens import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn 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.unit.dp import androidx.compose.ui.unit.sp import com.example.data.model.* import com.example.ui.components.CustomLabeledTextField import com.example.ui.theme.* import com.example.ui.util.Localization @Composable fun AdminPanelScreen( reports: List, selectedTab: Int, onTabChange: (Int) -> Unit, reviewingReportId: String?, onSelectReportForReview: (String?) -> Unit, adminNotesInput: String, onAdminNotesChange: (String) -> Unit, onApproveReport: (reportId: String, publishWarning: Boolean) -> Unit, onRejectReport: (reportId: String) -> Unit, lang: AppLanguage, onBack: () -> Unit, modifier: Modifier = Modifier ) { val pendingReports = reports.filter { it.status == ReportStatus.PENDING_REVIEW || it.status == ReportStatus.UNDER_INVESTIGATION } val verifiedReports = reports.filter { it.status == ReportStatus.VERIFIED_WARNING_ISSUED || it.status == ReportStatus.LEGAL_ESCALATION } val rejectedReports = reports.filter { it.status == ReportStatus.REJECTED } val activeReportList = when (selectedTab) { 0 -> pendingReports 1 -> verifiedReports else -> rejectedReports } val reviewingReport = remember(reports, reviewingReportId) { if (reviewingReportId != null) reports.find { it.id == reviewingReportId } else null } if (reviewingReport != null) { // DETAILED ADMIN REVIEW DIALOG / 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 = { onSelectReportForReview(null) }) { Icon(Icons.Default.ArrowBack, contentDescription = "Back", tint = Color.White) } Text( text = "${if (lang == AppLanguage.BN) "অভিযোগ পর্যালোচনা:" else "Admin Review:"} ${reviewingReport.id}", 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() ) { Column( modifier = Modifier .fillMaxWidth() .padding(16.dp) .navigationBarsPadding(), verticalArrangement = Arrangement.spacedBy(8.dp) ) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(10.dp) ) { OutlinedButton( onClick = { onRejectReport(reviewingReport.id) }, colors = ButtonDefaults.outlinedButtonColors(contentColor = StatusWarningRed), shape = RoundedCornerShape(10.dp), modifier = Modifier .weight(1f) .height(48.dp) .testTag("btn_admin_reject") ) { Icon(Icons.Default.Close, contentDescription = null, modifier = Modifier.size(16.dp)) Spacer(modifier = Modifier.width(4.dp)) Text(if (lang == AppLanguage.BN) "বাতিল করুন" else "Reject") } Button( onClick = { onApproveReport(reviewingReport.id, true) }, colors = ButtonDefaults.buttonColors(containerColor = StatusWarningRed), shape = RoundedCornerShape(10.dp), modifier = Modifier .weight(1.5f) .height(48.dp) .testTag("btn_admin_approve_warning") ) { Icon(Icons.Default.Campaign, contentDescription = null, modifier = Modifier.size(16.dp)) Spacer(modifier = Modifier.width(4.dp)) Text(if (lang == AppLanguage.BN) "সতর্কতা জারি করুন" else "Publish Warning") } } FilledTonalButton( onClick = { onApproveReport(reviewingReport.id, false) }, colors = ButtonDefaults.filledTonalButtonColors( containerColor = BrandNavyPrimary.copy(alpha = 0.1f), contentColor = BrandNavyPrimary ), shape = RoundedCornerShape(10.dp), modifier = Modifier .fillMaxWidth() .height(44.dp) .testTag("btn_admin_escalate_cid") ) { Icon(Icons.Default.Gavel, contentDescription = null, modifier = Modifier.size(16.dp)) Spacer(modifier = Modifier.width(6.dp)) Text(if (lang == AppLanguage.BN) "আইনগত ব্যবস্থার জন্য CID Cyber এ পাঠান" else "Escalate to CID Cyber Wing") } } } }, modifier = modifier.fillMaxSize() ) { innerPadding -> Column( modifier = Modifier .fillMaxSize() .padding(innerPadding) .verticalScroll(rememberScrollState()) .padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp) ) { // Duplicate Pattern Alert Card if detected if (reviewingReport.duplicateMatchId != null) { Surface( color = StatusAmberBg, shape = RoundedCornerShape(12.dp), border = androidx.compose.foundation.BorderStroke(1.dp, StatusAmber.copy(alpha = 0.4f)), modifier = Modifier.fillMaxWidth() ) { Row( modifier = Modifier.padding(12.dp), verticalAlignment = Alignment.CenterVertically ) { Icon(Icons.Default.ContentCopy, contentDescription = null, tint = StatusAmber) Spacer(modifier = Modifier.width(10.dp)) Column { Text( text = if (lang == AppLanguage.BN) "ডুপ্লিকেট চক্র শনাক্ত হয়েছে!" else "Duplicate Scam Pattern Detected!", style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold, color = StatusAmber) ) Text( text = if (lang == AppLanguage.BN) "একই বিকাশ নম্বর ও পেজ লিংক পূর্বের একাধিক কমপ্লেইনে পাওয়া গেছে।" else "Same bKash wallet matches existing verified fraud cases.", style = MaterialTheme.typography.bodySmall.copy(color = Color(0xFF78350F), fontSize = 11.sp) ) } } } } // Incident Details 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)) { Text( text = reviewingReport.targetEntityName, style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold) ) Text( text = "${reviewingReport.scamCategory} • ${reviewingReport.city}", style = MaterialTheme.typography.bodySmall.copy(color = LightTextMuted) ) Spacer(modifier = Modifier.height(12.dp)) Text( text = if (lang == AppLanguage.BN) "যোগাযোগ ও ওয়ালেট নম্বর:" else "Contact / Payment Info:", style = MaterialTheme.typography.labelSmall.copy(color = LightTextMuted) ) Text( text = reviewingReport.contactInfo, style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold) ) Spacer(modifier = Modifier.height(8.dp)) Text( text = if (lang == AppLanguage.BN) "হাতিয়ে নেওয়া অর্থ:" else "Amount Lost:", style = MaterialTheme.typography.labelSmall.copy(color = LightTextMuted) ) Text( text = Localization.formatCurrency(reviewingReport.moneyLostBdt, lang), style = MaterialTheme.typography.titleMedium.copy(color = StatusWarningRed, fontWeight = FontWeight.Bold) ) Spacer(modifier = Modifier.height(12.dp)) Text( text = if (lang == AppLanguage.BN) "ঘটনার বিবরণ:" else "Description:", style = MaterialTheme.typography.labelSmall.copy(color = LightTextMuted) ) Text( text = reviewingReport.incidentDescription, style = MaterialTheme.typography.bodyMedium.copy(lineHeight = 20.sp) ) Spacer(modifier = Modifier.height(12.dp)) Text( text = "রিপোর্টার: ${reviewingReport.reporterName} (${reviewingReport.reporterPhone})", style = MaterialTheme.typography.labelSmall.copy(color = LightTextSecondary) ) } } // Evidence Attachments Preview 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)) { Text( text = if (lang == AppLanguage.BN) "সংযুক্ত প্রমাণাদি প্রিভিউ" else "Evidence Preview", style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold) ) Spacer(modifier = Modifier.height(8.dp)) listOf( "📱 bKash TrxID SMS receipt verified (Trx: 9J28A4KL91)", "💬 Messenger extortion chat transcript with timestamp", "📄 Forged embassy visa document scan" ).forEach { evidence -> Surface( color = LightSurfaceVariant, shape = RoundedCornerShape(8.dp), modifier = Modifier .fillMaxWidth() .padding(vertical = 4.dp) ) { Row( modifier = Modifier.padding(10.dp), verticalAlignment = Alignment.CenterVertically ) { Icon(Icons.Default.Attachment, contentDescription = null, tint = BrandNavyPrimary, modifier = Modifier.size(18.dp)) Spacer(modifier = Modifier.width(8.dp)) Text(text = evidence, style = MaterialTheme.typography.bodySmall) } } } } } // Admin Investigation Notes Input CustomLabeledTextField( label = if (lang == AppLanguage.BN) "তদন্ত নোট ও রেফারেন্স (Admin Notes)" else "Investigation Notes & Reference", value = adminNotesInput, onValueChange = onAdminNotesChange, placeholder = if (lang == AppLanguage.BN) "যেমন: বিকাশ স্টেটমেন্ট যাচাই করা হয়েছে, সতর্কবার্তা প্রকাশের সুপারিশ।" else "e.g., Verified bKash statement, approved for public warning.", singleLine = false, maxLines = 3, testTag = "input_admin_notes" ) } } return } // MAIN ADMIN PANEL QUEUE LIST Scaffold( containerColor = MaterialTheme.colorScheme.background, modifier = modifier.fillMaxSize() ) { innerPadding -> Column( modifier = Modifier .fillMaxSize() .padding(innerPadding) ) { // Admin Tabs TabRow( selectedTabIndex = selectedTab, containerColor = MaterialTheme.colorScheme.surface, contentColor = BrandNavyPrimary ) { Tab( selected = selectedTab == 0, onClick = { onTabChange(0) }, text = { Text("${if (lang == AppLanguage.BN) "অপেক্ষমাণ" else "Pending"} (${pendingReports.size})") } ) Tab( selected = selectedTab == 1, onClick = { onTabChange(1) }, text = { Text("${if (lang == AppLanguage.BN) "অনুমোদিত" else "Verified"} (${verifiedReports.size})") } ) Tab( selected = selectedTab == 2, onClick = { onTabChange(2) }, text = { Text("${if (lang == AppLanguage.BN) "বাতিল" else "Rejected"} (${rejectedReports.size})") } ) } if (activeReportList.isEmpty()) { Box( modifier = Modifier .fillMaxSize() .padding(32.dp), contentAlignment = Alignment.Center ) { Text( text = if (lang == AppLanguage.BN) "এই ট্যাবে কোনো রিপোর্ট নেই" else "No reports in this queue", color = LightTextMuted ) } } else { LazyColumn( modifier = Modifier .fillMaxSize() .padding(horizontal = 16.dp), contentPadding = PaddingValues(top = 12.dp, bottom = 80.dp), verticalArrangement = Arrangement.spacedBy(12.dp) ) { items(activeReportList) { rep -> Surface( onClick = { onSelectReportForReview(rep.id) }, shape = RoundedCornerShape(12.dp), color = MaterialTheme.colorScheme.surface, border = androidx.compose.foundation.BorderStroke(1.dp, LightOutline), shadowElevation = 2.dp, modifier = Modifier .fillMaxWidth() .testTag("admin_queue_item_${rep.id}") ) { Column(modifier = Modifier.padding(14.dp)) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Text( text = rep.id, style = MaterialTheme.typography.labelMedium.copy( color = BrandBlueAccent, fontWeight = FontWeight.Bold ) ) Text( text = Localization.getReportStatusText(rep.status, lang), style = MaterialTheme.typography.labelSmall.copy( color = when (rep.status) { ReportStatus.VERIFIED_WARNING_ISSUED -> StatusWarningRed ReportStatus.LEGAL_ESCALATION -> Color(0xFF7E22CE) ReportStatus.PENDING_REVIEW -> StatusAmber else -> LightTextMuted }, fontWeight = FontWeight.Bold ) ) } Spacer(modifier = Modifier.height(6.dp)) Text( text = rep.targetEntityName, style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold) ) Text( text = rep.incidentDescription, style = MaterialTheme.typography.bodySmall.copy(color = LightTextSecondary), maxLines = 2 ) Spacer(modifier = Modifier.height(8.dp)) Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Text( text = Localization.formatCurrency(rep.moneyLostBdt, lang), style = MaterialTheme.typography.labelSmall.copy( color = StatusWarningRed, fontWeight = FontWeight.Bold ) ) FilledTonalButton( onClick = { onSelectReportForReview(rep.id) }, shape = RoundedCornerShape(8.dp), contentPadding = PaddingValues(horizontal = 12.dp, vertical = 4.dp) ) { Text( text = if (lang == AppLanguage.BN) "রিভিউ করুন ›" else "Review ›", fontSize = 11.sp, fontWeight = FontWeight.Bold ) } } } } } } } } } }