QualiNomme/src/main/kotlin/main/nb_occurrence.kt

113 lines
3.4 KiB
Kotlin

package main
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.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import main.component.dropdownButtonComponent
@Composable
fun parsedWordsTable(
parsedWords: Map<String, Int>,
onBackClick: () -> Unit,
onProjectClick: () -> Unit,
onCodeToVerifyClick: () -> Unit,
) {
var isCompareClicked by remember { mutableStateOf(false) }
val noFileSnackbarVisibleState = remember { mutableStateOf(false) }
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Mots parsés", style = MaterialTheme.typography.h3)
Spacer(modifier = Modifier.height(16.dp))
// Tableau des mots parsés
LazyColumn(modifier = Modifier.padding(16.dp)) {
item {
parsedWordsHeaderRow()
}
items(parsedWords.toList()) { (word, count) ->
parsedWordsDataRow(word, count)
}
}
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = { onBackClick() },
colors = androidx.compose.material.ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Text("Retour")
}
}
dropdownButtonComponent(
items = listOf("Glossaire", "Code à vérifier", "Comparer")
) { selectedOption ->
// Handle the selected option
when (selectedOption) {
"Glossaire" -> onProjectClick()
"Code à vérifier" -> onCodeToVerifyClick()
"Comparer" -> {
if (mostUsedWordList.isEmpty()) {
noFileSnackbarVisibleState.value = true
return@dropdownButtonComponent
} else {
isCompareClicked = true
}
}
}
}
}
@Composable
fun parsedWordsHeaderRow() {
Row(
modifier = Modifier
.fillMaxWidth()
.background(customRedColor)
.border(1.dp, Color.Black),
verticalAlignment = Alignment.CenterVertically
) {
listOf("Mot", "Occurrences").forEach { header ->
Text(
text = header,
fontWeight = FontWeight.Bold,
modifier = Modifier.weight(1f).padding(8.dp),
color = Color.White
)
}
}
}
@Composable
fun parsedWordsDataRow(word: String, count: Int) {
Row(
modifier = Modifier
.fillMaxWidth()
.background(Color.White)
.border(1.dp, Color.Black),
verticalAlignment = Alignment.CenterVertically
) {
val modifier = Modifier.weight(1f).padding(8.dp)
cellContent(word, modifier)
cellContent(count.toString(), modifier)
}
}