//package ui
//
//import AutoTradeItem
//import androidx.compose.foundation.background
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.layout.*
//import androidx.compose.foundation.lazy.LazyColumn
//import androidx.compose.foundation.lazy.items  // 반드시 수동 import 확인
//import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.material.*
//import androidx.compose.runtime.*
//import io.ktor.client.engine.cio.CIO
//// 아래 두 import가 'delegate' 에러를 해결합니다.
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.setValue
//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.text.style.TextAlign
//import androidx.compose.ui.text.style.TextOverflow
//import androidx.compose.ui.unit.dp
//import androidx.compose.ui.unit.sp
//import kotlinx.coroutines.delay
//import kotlinx.coroutines.launch
//import model.AppConfig
//import model.BalanceSummary
//import model.CandleData
//import model.RankingStock
//import model.StockHolding
//import network.KisTradeService
//import network.KisWebSocketManager
//import kotlin.collections.isNotEmpty
//
//
//@Composable
//fun AutoTradeSettingCard(
//    stockCode: String,
//    stockName: String, // 종목명 추가
//    currentPrice: String,
//    isDomestic: Boolean = true
//) {
//    var profitRate by remember { mutableStateOf("5.0") }
//    var stopLossRate by remember { mutableStateOf("-3.0") }
//
//    // DB에서 현재 감시 중인지 확인
//    var isEnabled by remember(stockCode) {
//        mutableStateOf(DatabaseFactory.findConfigByCode(stockCode) != null)
//    }
//
//    Card(
//        elevation = 4.dp,
//        shape = RoundedCornerShape(8.dp),
//        backgroundColor = Color(0xFFF8F9FA)
//    ) {
//        Column(modifier = Modifier.padding(12.dp)) {
//            Text("자동 매도 설정 (AI 감시)", fontWeight = FontWeight.Bold, style = MaterialTheme.typography.subtitle2)
//            Spacer(modifier = Modifier.height(8.dp))
//
//            Row(verticalAlignment = Alignment.CenterVertically) {
//                OutlinedTextField(
//                    value = profitRate,
//                    onValueChange = { profitRate = it },
//                    label = { Text("익절 %") },
//                    modifier = Modifier.weight(1f).padding(end = 4.dp),
//                    textStyle = androidx.compose.ui.text.TextStyle(fontSize = 12.sp)
//                )
//                OutlinedTextField(
//                    value = stopLossRate,
//                    onValueChange = { stopLossRate = it },
//                    label = { Text("손절 %") },
//                    modifier = Modifier.weight(1f),
//                    textStyle = androidx.compose.ui.text.TextStyle(fontSize = 12.sp)
//                )
//            }
//
//            Spacer(modifier = Modifier.height(8.dp))
//
//            Button(
//                onClick = {
//                    if (!isEnabled) {
//                        // 자동 매매 시작: DB 저장
//                        val curPriceNum = currentPrice.replace(",", "").toDoubleOrNull() ?: 0.0
//                        val target = curPriceNum * (1 + profitRate.toDouble() / 100.0)
//                        val stopLoss = curPriceNum * (1 + stopLossRate.toDouble() / 100.0)
//
//                        DatabaseFactory.saveAutoTrade(
//                            AutoTradeItem(
//                                code = stockCode,
//                                name = stockName,
//                                targetPrice = target,
//                                stopLossPrice = stopLoss,
//                                status = "MONITORING",
//                                isDomestic = isDomestic
//                            )
//                        )
//                        // [중요] 웹소켓 실시간 감시 등록 로직이 이곳에 호출되어야 함
//                        // KisWebSocketManager.subscribe(stockCode)
//                        isEnabled = true
//                    } else {
//                        // 자동 매매 중단: DB 삭제
//                        DatabaseFactory.deleteAutoTrade(stockCode)
//                        // KisWebSocketManager.unsubscribe(stockCode)
//                        isEnabled = false
//                    }
//                },
//                modifier = Modifier.fillMaxWidth(),
//                colors = ButtonDefaults.buttonColors(
//                    backgroundColor = if (isEnabled) Color(0xFFE03E2D) else Color(0xFF0E62CF)
//                )
//            ) {
//                Text(if (isEnabled) "자동 매매 중단" else "자동 매매 시작", color = Color.White)
//            }
//        }
//    }
//}