package eu.friedcutlet.yokan.ui.screens.activity import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.pager.PagerState import androidx.compose.material3.Badge import androidx.compose.material3.MaterialTheme import androidx.compose.material3.SecondaryTabRow import androidx.compose.material3.Tab import androidx.compose.material3.TabRowDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import eu.friedcutlet.yokan.domain.ItemType import eu.friedcutlet.yokan.util.nowMillis import eu.friedcutlet.yokan.ui.navigation.NavSection import eu.friedcutlet.yokan.ui.navigation.librarySection // ───────────────────────────────────────────────────────────────────────────── // HistoryScreen + UpdatesScreen // // Both screens follow the same chrome from the Dart source (BaseLibraryTabScreen): // a TopAppBar whose title swaps into an inline search field, a ScrollableTabRow // of visible ItemTypes (filtered by dbSettings.hideItems), and a LazyColumn of // rows grouped by date with sticky headers. internal fun visibleItemTypes(hidden: Set): List = ItemType.entries.filterNot { it.librarySection() in hidden } // ───────────────────────────────────────────────────────────────────────────── // Rows + helpers @Composable internal fun DateGroupHeader(label: String) { Text( text = label, style = MaterialTheme.typography.bodyMedium, modifier = Modifier .fillMaxWidth() .padding(start = 12.dp, bottom = 8.dp), ) } @Composable internal fun ItemTypePagerTabRow( types: List, pagerState: PagerState, unreadCounts: Map = emptyMap(), onSelect: (Int) -> Unit, ) { val selectedIndex = pagerState.currentPage.coerceIn(types.indices) SecondaryTabRow( selectedTabIndex = selectedIndex, modifier = Modifier.fillMaxWidth(), containerColor = Color.Transparent, indicator = { TabRowDefaults.SecondaryIndicator( modifier = Modifier .tabIndicatorOffset( selectedTabIndex = selectedIndex, matchContentSize = false, ) .offset(y = 1.dp), height = 4.dp, ) }, ) { types.forEachIndexed { index, type -> val count = unreadCounts[type] ?: 0 Tab( selected = index == selectedIndex, onClick = { onSelect(index) }, text = { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), ) { Text(type.label) if (count > 0) { Badge( containerColor = MaterialTheme.colorScheme.surfaceVariant, contentColor = MaterialTheme.colorScheme.onSurface, ) { Text(count.toString()) } } } }, ) } } } /** Groups entries into Today / Yesterday / Earlier this week / Earlier this month / Older, in that order. */ internal fun groupByDayBucket(entries: List, updatedAt: (T) -> Long): List>> { if (entries.isEmpty()) return emptyList() val now = nowMillis() val dayMillis = 24L * 60L * 60L * 1000L return entries.groupBy { entry -> val deltaDays = ((now / dayMillis) - (updatedAt(entry) / dayMillis)).toInt() when { deltaDays <= 0 -> "Today" deltaDays == 1 -> "Yesterday" deltaDays in 2..6 -> "Earlier this week" deltaDays in 7..29 -> "Earlier this month" else -> "Older" } }.toList().sortedBy { (label, _) -> dayBucketOrder(label) } } private fun dayBucketOrder(label: String): Int = when (label) { "Today" -> 0 "Yesterday" -> 1 "Earlier this week" -> 2 "Earlier this month" -> 3 else -> 4 }