package com.jishisongfu.duobibi.ui.worth

import android.widget.Toast
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Balance
import androidx.compose.material.icons.filled.Lightbulb
import androidx.compose.material.icons.filled.NotificationsActive
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.jishisongfu.duobibi.data.api.WorthBuyResponse
import com.jishisongfu.duobibi.ui.HeroBanner
import com.jishisongfu.duobibi.ui.PriceGauge
import com.jishisongfu.duobibi.ui.ProductThumb
import com.jishisongfu.duobibi.ui.TagChip
import com.jishisongfu.duobibi.ui.fmtYuan
import com.jishisongfu.duobibi.ui.rememberHaptics
import com.jishisongfu.duobibi.ui.theme.DbbColors
import com.jishisongfu.duobibi.ui.theme.DbbGradients

/**
 * 值不值得买 Tab。结构(自上而下):
 *   1) AI 评估区:表单 + AI 评估按钮
 *   2) Success 状态显示:评分卡 / 判断依据 / 更划算时机
 *   3) Success 状态额外补:**60 天走势图 / 历史统计 / 大促倒计时 / 行动 CTA**
 *      ↑ 这一段对标"什么值得买"/"慢慢买"决策页的核心数据可视化 + 行动闭环
 *
 * 父容器用 LazyColumn 而不是 Column+verticalScroll,既方便条件 item 渲染,
 * 也为日后再挂长列表(如同款好物推荐)留余地。Success-only 卡片用 `if/item {}`。
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun WorthBuyScreen(
    onOpenCluster: (Long) -> Unit,
    onOpenArena: (String) -> Unit,
    vm: WorthBuyViewModel = hiltViewModel(),
) {
    val ctx = LocalContext.current
    val haptics = rememberHaptics()
    val state by vm.state.collectAsStateWithLifecycle()
    val title by vm.title.collectAsStateWithLifecycle()
    val price by vm.price.collectAsStateWithLifecycle()

    Scaffold(
        containerColor = DbbColors.Bg,
        contentWindowInsets = WindowInsets(0),
    ) { padding ->
        Column(
            Modifier
                .padding(padding)
                .fillMaxSize()
                .background(DbbColors.Bg),
        ) {
            HeroBanner(
                title = "值不值得买",
                subtitle = "AI 评估 · 60 天走势 · 大促倒计时",
                icon = Icons.Filled.Lightbulb,
                gradient = DbbGradients.Worth,
            )
            GuessYouAskRow(onPick = { t, p -> vm.setTitle(t); vm.setPrice(p) })
            LazyColumn(
                modifier = Modifier.fillMaxSize().background(DbbColors.Bg),
                contentPadding = PaddingValues(14.dp, 10.dp, 14.dp, 88.dp),
            ) {
            // ========== 1) AI 评估区 ==========
            item {
                OutlinedTextField(
                    value = title,
                    onValueChange = vm::setTitle,
                    label = { Text("商品名") },
                    singleLine = true,
                    modifier = Modifier.fillMaxWidth(),
                    shape = RoundedCornerShape(14.dp),
                )
                Spacer(Modifier.height(10.dp))
            }
            item {
                OutlinedTextField(
                    value = price,
                    onValueChange = vm::setPrice,
                    label = { Text("当前到手价(元)") },
                    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),
                    singleLine = true,
                    modifier = Modifier.fillMaxWidth(),
                    shape = RoundedCornerShape(14.dp),
                )
                Spacer(Modifier.height(12.dp))
            }
            item {
                Button(
                    onClick = { haptics.confirm(); vm.submit() },
                    enabled = state !is WorthUiState.Loading && title.isNotBlank() && price.isNotBlank(),
                    modifier = Modifier.fillMaxWidth().height(48.dp),
                    shape = RoundedCornerShape(14.dp),
                    colors = ButtonDefaults.buttonColors(containerColor = DbbColors.Teal),
                ) {
                    Icon(Icons.Filled.Lightbulb, contentDescription = null, modifier = Modifier.size(20.dp))
                    Spacer(Modifier.width(8.dp))
                    Text("AI 评估", fontWeight = FontWeight.SemiBold, fontSize = 16.sp)
                }
                Spacer(Modifier.height(14.dp))
            }

            // ========== 2) 评估状态分支 ==========
            item {
                when (val s = state) {
                    is WorthUiState.Idle -> IdleHint()
                    is WorthUiState.Loading -> Box(
                        Modifier.fillMaxWidth().padding(top = 20.dp),
                        contentAlignment = Alignment.Center,
                    ) {
                        CircularProgressIndicator(color = DbbColors.Teal, strokeWidth = 3.dp)
                    }
                    is WorthUiState.Error -> Card(
                        Modifier.fillMaxWidth(),
                        colors = CardDefaults.cardColors(containerColor = DbbColors.UpBg),
                        elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
                        shape = RoundedCornerShape(14.dp),
                    ) { Text(s.message, Modifier.padding(16.dp), color = DbbColors.Up) }
                    is WorthUiState.Success -> ResultBlock(
                        r = s.result,
                        yourPrice = price.toDoubleOrNull() ?: s.result.typicalPrice,
                        title = title,
                    )
                }
            }

            // ========== 3) Success-only 决策数据可视化 + 行动 CTA ==========
            val s = state
            if (s is WorthUiState.Success) {
                val yourPrice = price.toDoubleOrNull() ?: s.result.typicalPrice
                val effectiveTitle = title.ifBlank { "选中商品" }

                item {
                    Spacer(Modifier.height(10.dp))
                    PriceTrendCard(effectiveTitle, yourPrice, s.result.typicalPrice)
                    Spacer(Modifier.height(10.dp))
                }
                item {
                    HistoryStatsCard(effectiveTitle, yourPrice, s.result.typicalPrice)
                    Spacer(Modifier.height(10.dp))
                }
                item {
                    NextPromoCard(verdict = s.result.verdict)
                    Spacer(Modifier.height(12.dp))
                }
                item {
                    ActionCtaRow(
                        onAddAlert = {
                            haptics.confirm()
                            vm.addToAlert(effectiveTitle, yourPrice) {
                                Toast.makeText(
                                    ctx,
                                    "已加入降价雷达 · 心理价 ¥${fmtYuan(yourPrice)}",
                                    Toast.LENGTH_SHORT,
                                ).show()
                            }
                        },
                        onOpenArena = { haptics.confirm(); onOpenArena(effectiveTitle) },
                    )
                    Spacer(Modifier.height(6.dp))
                }
            }

            }
        }
    }
}

// ====================================================================
//                      Success-only 决策模块
// ====================================================================

/** 60 天价格走势 — 招牌可视化(参考慢慢买/SMZDM 决策页)。 */
@Composable
private fun PriceTrendCard(title: String, yourPrice: Double, typical: Double) {
    val prices = remember(title, typical, yourPrice) { generate60dPrices(title, typical, yourPrice) }
    val minP = prices.min()
    val maxP = prices.max()
    val minIdx = prices.indexOf(minP)

    Card(
        Modifier.fillMaxWidth(),
        colors = CardDefaults.cardColors(containerColor = DbbColors.Card),
        elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
        shape = RoundedCornerShape(16.dp),
    ) {
        Column(Modifier.padding(14.dp)) {
            Row(verticalAlignment = Alignment.CenterVertically) {
                Text("📉", fontSize = 16.sp)
                Spacer(Modifier.width(6.dp))
                Text(
                    "60 天价格走势",
                    fontWeight = FontWeight.Bold, color = DbbColors.Ink, fontSize = 14.sp,
                )
                Spacer(Modifier.weight(1f))
                Text(
                    "60d 低 ¥${fmtYuan(minP)}",
                    color = DbbColors.Up, fontSize = 11.sp, fontWeight = FontWeight.SemiBold,
                )
            }
            Spacer(Modifier.height(10.dp))
            TrendCanvas(prices = prices, minIdx = minIdx)
            Spacer(Modifier.height(6.dp))
            Row(Modifier.fillMaxWidth()) {
                Text("60 天前", color = DbbColors.InkTer, fontSize = 10.sp)
                Spacer(Modifier.weight(1f))
                Text("今天", color = DbbColors.InkTer, fontSize = 10.sp)
            }
        }
    }
}

@Composable
private fun TrendCanvas(prices: List<Double>, minIdx: Int) {
    val minP = prices.min()
    val maxP = prices.max()
    val spanP = (maxP - minP).coerceAtLeast(0.01)

    val lineColor = DbbColors.Teal
    val areaColor = DbbColors.TealBg
    val gridColor = DbbColors.Border
    val minPointColor = DbbColors.Up
    val nowPointColor = DbbColors.Teal

    Box(Modifier.fillMaxWidth().height(124.dp)) {
        Canvas(Modifier.fillMaxWidth().height(124.dp)) {
            val padL = 4.dp.toPx()
            val padR = 4.dp.toPx()
            val padT = 8.dp.toPx()
            val padB = 8.dp.toPx()
            val w = size.width - padL - padR
            val h = size.height - padT - padB

            // 三条横向虚线(top / mid / bottom)
            for (i in 0..2) {
                val y = padT + h * (i / 2f)
                drawLine(
                    color = gridColor,
                    start = Offset(padL, y),
                    end = Offset(padL + w, y),
                    strokeWidth = 1f,
                )
            }

            val points = prices.mapIndexed { idx, p ->
                val x = padL + (idx.toFloat() / (prices.lastIndex.toFloat())) * w
                val y = padT + h - (((p - minP) / spanP).toFloat() * h)
                Offset(x, y)
            }

            // 填充面积(line 下方淡色)
            val area = Path().apply {
                moveTo(points.first().x, padT + h)
                points.forEach { lineTo(it.x, it.y) }
                lineTo(points.last().x, padT + h)
                close()
            }
            drawPath(area, areaColor)

            // 折线
            val path = Path().apply {
                points.forEachIndexed { idx, p ->
                    if (idx == 0) moveTo(p.x, p.y) else lineTo(p.x, p.y)
                }
            }
            drawPath(path, lineColor, style = Stroke(width = 3.5f))

            // 60 天最低点(红圆 + 白心)
            val minPt = points[minIdx]
            drawCircle(minPointColor, 7f, minPt)
            drawCircle(Color.White, 3f, minPt)

            // 今天点(teal 圆环 + 白心)
            val nowPt = points.last()
            drawCircle(nowPointColor, 8f, nowPt)
            drawCircle(Color.White, 3.5f, nowPt)
        }
    }
}

/** 历史价格统计三栏:60 天最低 / 60 天均价 / 当前水位分位。 */
@Composable
private fun HistoryStatsCard(title: String, yourPrice: Double, typical: Double) {
    val prices = remember(title, typical, yourPrice) { generate60dPrices(title, typical, yourPrice) }
    val stats = remember(prices, yourPrice) { computeHistoryStats(prices, yourPrice) }

    val percentileColor = when {
        stats.percentile < 25 -> DbbColors.Save
        stats.percentile > 75 -> DbbColors.Up
        else -> DbbColors.Teal
    }
    val percentileBg = when {
        stats.percentile < 25 -> DbbColors.SaveBg
        stats.percentile > 75 -> DbbColors.UpBg
        else -> DbbColors.TealBg
    }
    val percentileLabel = when {
        stats.percentile < 25 -> "低位可入"
        stats.percentile > 75 -> "高位可等"
        else -> "中段水位"
    }

    Card(
        Modifier.fillMaxWidth(),
        colors = CardDefaults.cardColors(containerColor = DbbColors.Card),
        elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
        shape = RoundedCornerShape(16.dp),
    ) {
        Column(Modifier.padding(14.dp)) {
            Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
                StatBox("60 天最低", "¥${fmtYuan(stats.min)}",
                    bg = DbbColors.SaveBg, fg = DbbColors.Save, modifier = Modifier.weight(1f))
                StatBox("60 天均价", "¥${fmtYuan(stats.avg)}",
                    bg = DbbColors.Fill, fg = DbbColors.InkSec, modifier = Modifier.weight(1f))
                StatBox("当前水位", "${stats.percentile}%",
                    bg = percentileBg, fg = percentileColor, modifier = Modifier.weight(1f))
            }
            Spacer(Modifier.height(8.dp))
            Text(
                "当前价 ¥${fmtYuan(yourPrice)} 处于 60 天区间的 ${stats.percentile}% 分位 — $percentileLabel",
                color = percentileColor, fontSize = 12.sp, fontWeight = FontWeight.Medium,
            )
        }
    }
}

@Composable
private fun StatBox(label: String, value: String, bg: Color, fg: Color, modifier: Modifier = Modifier) {
    Box(
        modifier
            .clip(RoundedCornerShape(10.dp))
            .background(bg)
            .padding(vertical = 10.dp),
        contentAlignment = Alignment.Center,
    ) {
        Column(horizontalAlignment = Alignment.CenterHorizontally) {
            Text(
                value,
                fontWeight = FontWeight.ExtraBold, fontSize = 17.sp, color = fg,
                letterSpacing = (-0.4).sp,
            )
            Text(label, fontSize = 10.sp, color = fg)
        }
    }
}

/** 距下次大促节点的倒计时,辅助"再等 vs 现在买"决策。 */
@Composable
private fun NextPromoCard(verdict: String) {
    val promo = remember { nextPromo() }
    // 临近大促 + AI 建议再等 → 强化"再等" 文案;否则中性
    val accent = if (promo.daysAway <= 14 && verdict == "wait") DbbColors.Save else DbbColors.Teal
    val bg = if (promo.daysAway <= 14 && verdict == "wait") DbbColors.SaveBg else DbbColors.TealBg
    val tail = when {
        promo.daysAway == 0 -> "今天就是大促日 · 这价位再等没意义"
        promo.daysAway <= 14 -> "建议再蹲 ${promo.daysAway} 天看大促价"
        promo.daysAway <= 30 -> "中短期内有节点,可关注"
        else -> "到下次大促还有阵子,合适就入"
    }

    Card(
        Modifier.fillMaxWidth(),
        colors = CardDefaults.cardColors(containerColor = bg),
        elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
        shape = RoundedCornerShape(14.dp),
    ) {
        Row(
            Modifier.padding(horizontal = 14.dp, vertical = 12.dp),
            verticalAlignment = Alignment.CenterVertically,
        ) {
            Text("⏰", fontSize = 18.sp)
            Spacer(Modifier.width(10.dp))
            Column(Modifier.weight(1f)) {
                Text(
                    "距下次大促:${promo.name}",
                    color = accent, fontWeight = FontWeight.Bold, fontSize = 13.sp,
                )
                Text(tail, color = DbbColors.InkSec, fontSize = 11.sp)
            }
            Box(
                Modifier
                    .clip(RoundedCornerShape(8.dp))
                    .background(accent)
                    .padding(horizontal = 10.dp, vertical = 6.dp),
            ) {
                Text(
                    "${promo.daysAway} 天",
                    color = Color.White, fontWeight = FontWeight.ExtraBold, fontSize = 14.sp,
                )
            }
        }
    }
}

/** 行动 CTA 行 — 决策完串到雷达/擂台,形成闭环。 */
@Composable
private fun ActionCtaRow(onAddAlert: () -> Unit, onOpenArena: () -> Unit) {
    Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
        Button(
            onClick = onAddAlert,
            modifier = Modifier.weight(1f).height(46.dp),
            shape = RoundedCornerShape(12.dp),
            colors = ButtonDefaults.buttonColors(containerColor = DbbColors.Teal),
        ) {
            Icon(Icons.Filled.NotificationsActive, contentDescription = null, modifier = Modifier.size(17.dp))
            Spacer(Modifier.width(6.dp))
            Text("加入降价雷达", fontWeight = FontWeight.SemiBold, fontSize = 13.sp)
        }
        Button(
            onClick = onOpenArena,
            modifier = Modifier.weight(1f).height(46.dp),
            shape = RoundedCornerShape(12.dp),
            colors = ButtonDefaults.buttonColors(containerColor = DbbColors.Sky),
        ) {
            Icon(Icons.Filled.Balance, contentDescription = null, modifier = Modifier.size(17.dp))
            Spacer(Modifier.width(6.dp))
            Text("跨平台对比", fontWeight = FontWeight.SemiBold, fontSize = 13.sp)
        }
    }
}

// ====================================================================
//                       原有内容(保留)
// ====================================================================

@Composable
private fun IdleHint() {
    Card(
        Modifier.fillMaxWidth(),
        colors = CardDefaults.cardColors(containerColor = DbbColors.TealBg),
        elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
        shape = RoundedCornerShape(16.dp),
    ) {
        Column(Modifier.padding(16.dp)) {
            Text("💡 别只看价格,看值不值", fontWeight = FontWeight.Bold, color = DbbColors.TealDark)
            Spacer(Modifier.height(8.dp))
            Text(
                "输入商品和当前到手价,AI 会给一个 0-100 的「值得买指数」并说明理由;" +
                    "下方会同时显示 60 天价格走势、当前价水位分位、下次大促倒计时,帮你判断「现在买还是再等」。",
                color = DbbColors.InkSec, fontSize = 13.sp,
            )
        }
    }
}

@Composable
private fun ResultBlock(r: WorthBuyResponse, yourPrice: Double, title: String) {
    val verdictColor = when (r.verdict) {
        "buy" -> DbbColors.Save
        "wait" -> DbbColors.Up
        else -> DbbColors.Teal
    }
    val verdictBg = when (r.verdict) {
        "buy" -> DbbColors.SaveBg
        "wait" -> DbbColors.UpBg
        else -> DbbColors.TealBg
    }
    val verdictLabel = when (r.verdict) {
        "buy" -> "建议买"
        "wait" -> "建议再等"
        else -> "看个人需求"
    }
    val highPrice = r.typicalPrice * 1.08

    Card(
        Modifier.fillMaxWidth(),
        colors = CardDefaults.cardColors(containerColor = DbbColors.Card),
        elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
        shape = RoundedCornerShape(20.dp),
    ) {
        Column(Modifier.padding(14.dp)) {
            if (title.isNotBlank()) {
                Row(verticalAlignment = Alignment.CenterVertically) {
                    ProductThumb(title = title, size = 40.dp)
                    Spacer(Modifier.width(10.dp))
                    Text(
                        title,
                        fontWeight = FontWeight.SemiBold,
                        color = DbbColors.Ink,
                        fontSize = 14.sp,
                        modifier = Modifier.weight(1f),
                    )
                }
                Spacer(Modifier.height(10.dp))
                Box(Modifier.fillMaxWidth().height(1.dp).background(DbbColors.Border))
                Spacer(Modifier.height(12.dp))
            }
            Row(verticalAlignment = Alignment.CenterVertically) {
                Box(
                    Modifier.size(92.dp).clip(CircleShape).background(verdictBg),
                    contentAlignment = Alignment.Center,
                ) {
                    Column(horizontalAlignment = Alignment.CenterHorizontally) {
                        Text(
                            "${r.score}",
                            fontSize = 38.sp, fontWeight = FontWeight.ExtraBold,
                            color = verdictColor, letterSpacing = (-1.5).sp,
                        )
                        Text("值得买指数", fontSize = 10.sp, color = verdictColor)
                    }
                }
                Spacer(Modifier.width(14.dp))
                Column(Modifier.weight(1f)) {
                    TagChip(verdictLabel, bg = verdictColor, fg = Color.White)
                    Spacer(Modifier.height(7.dp))
                    Text(r.headline, fontSize = 20.sp, fontWeight = FontWeight.ExtraBold, color = verdictColor)
                    Spacer(Modifier.height(3.dp))
                    Text(
                        "市场常见价 ¥${fmtYuan(r.typicalPrice)}",
                        color = DbbColors.InkSec, fontSize = 12.sp,
                    )
                }
            }
            Spacer(Modifier.height(12.dp))
            PriceGauge(min = yourPrice, max = highPrice, marker = r.typicalPrice)
            Spacer(Modifier.height(5.dp))
            Row(verticalAlignment = Alignment.CenterVertically) {
                Text(
                    "你的价 ¥${fmtYuan(yourPrice)}",
                    color = DbbColors.Save, fontSize = 11.sp, fontWeight = FontWeight.SemiBold,
                )
                Spacer(Modifier.weight(1f))
                Text("常见 ¥${fmtYuan(r.typicalPrice)}", color = DbbColors.InkTer, fontSize = 11.sp)
                Spacer(Modifier.weight(1f))
                Text("高位 ¥${fmtYuan(highPrice)}", color = DbbColors.Up, fontSize = 11.sp)
            }
        }
    }
    Spacer(Modifier.height(10.dp))

    if (r.reasons.isNotEmpty()) {
        Card(
            Modifier.fillMaxWidth(),
            colors = CardDefaults.cardColors(containerColor = DbbColors.Card),
            elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
            shape = RoundedCornerShape(16.dp),
        ) {
            Column(Modifier.padding(14.dp)) {
                Text("判断依据", fontWeight = FontWeight.Bold, color = DbbColors.Ink)
                Spacer(Modifier.height(8.dp))
                r.reasons.forEach { reason ->
                    Row(
                        Modifier.padding(vertical = 3.dp),
                        verticalAlignment = Alignment.Top,
                    ) {
                        Text(
                            "· ", color = DbbColors.Teal,
                            fontWeight = FontWeight.Bold, fontSize = 13.sp,
                        )
                        Text(reason, color = DbbColors.InkSec, fontSize = 13.sp)
                    }
                }
            }
        }
        Spacer(Modifier.height(10.dp))
    }

    if (r.bestTime.isNotBlank()) {
        Box(
            Modifier
                .fillMaxWidth()
                .clip(RoundedCornerShape(14.dp))
                .background(DbbColors.TealBg)
                .padding(horizontal = 13.dp, vertical = 12.dp),
        ) {
            Text(
                "⏰ 更划算的时机:${r.bestTime}",
                color = DbbColors.TealDark, fontSize = 13.sp, fontWeight = FontWeight.Medium,
            )
        }
        Spacer(Modifier.height(6.dp))
    }
    Text(
        "评估由 AI 依据公开常识与价格规律给出,仅供参考。",
        color = DbbColors.InkTer, fontSize = 10.sp,
    )
}

/**
 * Hero 下方"猜你要问"横滑条 — 解决"值不值得买"hero 与输入框之间的空荡感。
 *
 * 写死 6 个大众都会想评估的商品(配价格),点一下直接把商品名 + 当前价 prefill 进表单,
 * 用户再点"AI 评估"按钮即可。
 * 价格点按主流到手价区间设的;用户当然可以再改。
 */
@Composable
private fun GuessYouAskRow(onPick: (title: String, price: String) -> Unit) {
    val candidates = remember {
        listOf(
            "iPhone 15 Pro 256G" to "7999",
            "MacBook Air 13 M3" to "8499",
            "戴森 V12 吸尘器" to "3599",
            "AirPods 4" to "1099",
            "Switch OLED 主机" to "2299",
            "雅诗兰黛小棕瓶 50ml" to "988",
        )
    }
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .horizontalScroll(rememberScrollState())
            .padding(horizontal = 12.dp, vertical = 10.dp),
        horizontalArrangement = Arrangement.spacedBy(8.dp),
    ) {
        Text("💡 猜你要问", color = DbbColors.Emerald, fontSize = 11.sp, fontWeight = FontWeight.Bold)
        candidates.forEach { (t, p) ->
            Row(
                Modifier
                    .clip(RoundedCornerShape(11.dp))
                    .background(DbbColors.SaveBg)
                    .clickable { onPick(t, p) }
                    .padding(horizontal = 10.dp, vertical = 5.dp),
                verticalAlignment = Alignment.CenterVertically,
            ) {
                Text(t, color = DbbColors.Save, fontSize = 11.sp, fontWeight = FontWeight.Medium)
                Spacer(Modifier.width(5.dp))
                Text("¥$p", color = DbbColors.Save, fontSize = 10.sp, fontWeight = FontWeight.Bold)
            }
        }
    }
}
