package com.durian.tssparty.presentation.components

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.Composable
import androidx.compose.ui.graphics.vector.ImageVector

/**
 * Navigation destinations for bottom tabs
 */
sealed class BottomNavItem(
    val route: String,
    val title: String,
    val selectedIcon: ImageVector,
    val unselectedIcon: ImageVector
) {
    data object Wallets : BottomNavItem(
        route = "wallets",
        title = "我的钱包",
        selectedIcon = Icons.Filled.Lock,
        unselectedIcon = Icons.Outlined.Lock
    )

    data object Create : BottomNavItem(
        route = "create",
        title = "创建钱包",
        selectedIcon = Icons.Filled.Add,
        unselectedIcon = Icons.Outlined.Add
    )

    data object JoinKeygen : BottomNavItem(
        route = "join_keygen",
        title = "加入创建",
        selectedIcon = Icons.Filled.Handshake,
        unselectedIcon = Icons.Outlined.Handshake
    )

    data object CoSign : BottomNavItem(
        route = "cosign",
        title = "参与签名",
        selectedIcon = Icons.Filled.Create,
        unselectedIcon = Icons.Outlined.Create
    )

    data object Settings : BottomNavItem(
        route = "settings",
        title = "设置",
        selectedIcon = Icons.Filled.Settings,
        unselectedIcon = Icons.Outlined.Settings
    )
}

val bottomNavItems = listOf(
    BottomNavItem.Wallets,
    BottomNavItem.JoinKeygen,
    BottomNavItem.CoSign,
    BottomNavItem.Settings
)

@Composable
fun TssBottomNavigation(
    currentRoute: String,
    onNavigate: (BottomNavItem) -> Unit
) {
    NavigationBar {
        bottomNavItems.forEach { item ->
            val selected = currentRoute == item.route ||
                    (item == BottomNavItem.Wallets && currentRoute.startsWith("wallet_detail"))

            NavigationBarItem(
                icon = {
                    Icon(
                        imageVector = if (selected) item.selectedIcon else item.unselectedIcon,
                        contentDescription = item.title
                    )
                },
                label = { Text(item.title) },
                selected = selected,
                onClick = { onNavigate(item) }
            )
        }
    }
}
