package com.jihe.punchnet.screen

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.Phone
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
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 androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController

@Composable
fun DeviceScreen(navController: NavHostController) {
    val nodeList by com.jihe.punchnet.data.NodeRepository.nodes.collectAsState()

    LazyColumn(
        modifier = Modifier.fillMaxWidth().fillMaxHeight(),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        if (nodeList.isNotEmpty()) {
            item {
                Text(
                    text = "网络节点 (${nodeList.count { it.connectionStatus == "connected" }}/${nodeList.size})",
                    style = MaterialTheme.typography.titleMedium,
                    fontWeight = FontWeight.Bold,
                    modifier = Modifier.padding(bottom = 16.dp, start = 24.dp, top = 24.dp).fillMaxWidth()
                )
            }
            
            items(nodeList) { node ->
                Box(modifier = Modifier.padding(horizontal = 24.dp)) {
                    NodeItemRow(node)
                }
            }
        } else {
            item {
                Box(modifier = Modifier.fillMaxSize().padding(top = 100.dp), contentAlignment = Alignment.Center) {
                    Text("暂无设备，请先连接网络", color = MaterialTheme.colorScheme.onSurfaceVariant)
                }
            }
        }
    }
}
