import 'package:flutter/material.dart';
import '../../../../app/theme/app_colors.dart';
import '../../../../app/theme/app_typography.dart';
import '../../../../app/theme/app_spacing.dart';

/// 商户端 AI 助手页面
///
/// 核销辅助：异常券识别、核销建议
/// 客流预测：基于历史数据的每日/每周客流预测
/// 营销建议：促销活动建议、热门券品类推荐
/// 异常预警：可疑券检测、高频核销预警
class MerchantAiAssistantPage extends StatefulWidget {
  const MerchantAiAssistantPage({super.key});

  @override
  State<MerchantAiAssistantPage> createState() =>
      _MerchantAiAssistantPageState();
}

class _MerchantAiAssistantPageState extends State<MerchantAiAssistantPage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 3, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('AI 助手'),
        bottom: TabBar(
          controller: _tabController,
          tabs: const [
            Tab(text: '核销辅助'),
            Tab(text: '客流预测'),
            Tab(text: '异常预警'),
          ],
          labelColor: AppColors.primary,
          unselectedLabelColor: AppColors.textTertiary,
          indicatorColor: AppColors.primary,
          labelStyle: AppTypography.labelMedium,
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: [
          _buildRedeemAssistTab(),
          _buildTrafficPredictionTab(),
          _buildAnomalyAlertTab(),
        ],
      ),
    );
  }

  // ========================================
  // Tab 1: 核销辅助
  // ========================================
  Widget _buildRedeemAssistTab() {
    return SingleChildScrollView(
      padding: const EdgeInsets.all(20),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // AI Quick Actions
          _buildAiQuickActions(),
          const SizedBox(height: 20),

          // Redeem Tips
          _buildRedeemTips(),
          const SizedBox(height: 20),

          // Hot Coupons Today
          _buildHotCouponsToday(),
          const SizedBox(height: 20),

          // Marketing Suggestions
          _buildMarketingSuggestions(),
        ],
      ),
    );
  }

  Widget _buildAiQuickActions() {
    final actions = [
      ('验券真伪', Icons.verified_user_rounded, AppColors.success),
      ('查券状态', Icons.search_rounded, AppColors.info),
      ('批量核销', Icons.playlist_add_check_rounded, AppColors.primary),
      ('问题反馈', Icons.feedback_rounded, AppColors.warning),
    ];

    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        gradient: AppColors.primaryGradient,
        borderRadius: AppSpacing.borderRadiusMd,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Container(
                width: 28,
                height: 28,
                decoration: BoxDecoration(
                  color: Colors.white.withValues(alpha: 0.2),
                  borderRadius: AppSpacing.borderRadiusSm,
                ),
                child:
                    const Center(child: Text('✨', style: TextStyle(fontSize: 16))),
              ),
              const SizedBox(width: 10),
              const Text(
                'AI 快捷操作',
                style: TextStyle(
                    fontSize: 15,
                    fontWeight: FontWeight.w600,
                    color: Colors.white),
              ),
            ],
          ),
          const SizedBox(height: 16),
          Row(
            children: actions.map((a) {
              final (label, icon, _) = a;
              return Expanded(
                child: GestureDetector(
                  onTap: () {},
                  child: Column(
                    children: [
                      Container(
                        width: 44,
                        height: 44,
                        decoration: BoxDecoration(
                          color: Colors.white.withValues(alpha: 0.15),
                          borderRadius: AppSpacing.borderRadiusSm,
                        ),
                        child: Icon(icon, color: Colors.white, size: 22),
                      ),
                      const SizedBox(height: 6),
                      Text(
                        label,
                        style: TextStyle(
                          fontSize: 11,
                          color: Colors.white.withValues(alpha: 0.9),
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                    ],
                  ),
                ),
              );
            }).toList(),
          ),
        ],
      ),
    );
  }

  Widget _buildRedeemTips() {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.surface,
        borderRadius: AppSpacing.borderRadiusMd,
        border: Border.all(color: AppColors.borderLight),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              const Icon(Icons.lightbulb_outline_rounded,
                  color: AppColors.warning, size: 20),
              const SizedBox(width: 8),
              Text('核销提示', style: AppTypography.labelLarge),
            ],
          ),
          const SizedBox(height: 12),
          _buildTipItem(
            '星巴克 \$25 礼品卡有批次更新',
            '新批次(#B2026-03)已上线，请注意核验二维码格式',
            AppColors.info,
          ),
          _buildTipItem(
            '午间高峰期即将到来',
            '预计 11:30-13:00 核销量将达峰值 ~15笔/小时',
            AppColors.warning,
          ),
          _buildTipItem(
            '本店暂不支持 Nike 体验券',
            '该券仅限旗舰店核销，请引导顾客至正确门店',
            AppColors.error,
          ),
        ],
      ),
    );
  }

  Widget _buildTipItem(String title, String desc, Color color) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            width: 6,
            height: 6,
            margin: const EdgeInsets.only(top: 6),
            decoration: BoxDecoration(color: color, shape: BoxShape.circle),
          ),
          const SizedBox(width: 10),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(title,
                    style: AppTypography.labelMedium
                        .copyWith(fontSize: 13)),
                const SizedBox(height: 2),
                Text(desc,
                    style: AppTypography.bodySmall
                        .copyWith(color: AppColors.textSecondary)),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildHotCouponsToday() {
    final hotCoupons = [
      ('星巴克 \$25 礼品卡', 12, AppColors.couponDining),
      ('Amazon \$50 购物券', 8, AppColors.couponShopping),
      ('电影票 \$12', 5, AppColors.couponEntertainment),
    ];

    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.surface,
        borderRadius: AppSpacing.borderRadiusMd,
        border: Border.all(color: AppColors.borderLight),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              const Icon(Icons.local_fire_department_rounded,
                  color: AppColors.error, size: 20),
              const SizedBox(width: 8),
              Text('今日热门核销', style: AppTypography.labelLarge),
            ],
          ),
          const SizedBox(height: 12),
          ...hotCoupons.map((c) {
            final (name, count, color) = c;
            return Padding(
              padding: const EdgeInsets.symmetric(vertical: 6),
              child: Row(
                children: [
                  Container(
                    width: 32,
                    height: 32,
                    decoration: BoxDecoration(
                      color: color.withValues(alpha: 0.1),
                      borderRadius: AppSpacing.borderRadiusSm,
                    ),
                    child: Icon(Icons.confirmation_number_rounded,
                        color: color, size: 18),
                  ),
                  const SizedBox(width: 10),
                  Expanded(
                      child: Text(name, style: AppTypography.bodyMedium)),
                  Container(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
                    decoration: BoxDecoration(
                      color: AppColors.primarySurface,
                      borderRadius: AppSpacing.borderRadiusFull,
                    ),
                    child: Text(
                      '$count笔',
                      style: AppTypography.labelSmall
                          .copyWith(color: AppColors.primary),
                    ),
                  ),
                ],
              ),
            );
          }),
        ],
      ),
    );
  }

  Widget _buildMarketingSuggestions() {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.primarySurface,
        borderRadius: AppSpacing.borderRadiusMd,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              const Icon(Icons.auto_awesome_rounded,
                  color: AppColors.primary, size: 20),
              const SizedBox(width: 8),
              Text('AI 营销建议', style: AppTypography.labelLarge),
            ],
          ),
          const SizedBox(height: 12),
          _buildSuggestionItem(
            '推荐搭配销售',
            '购买咖啡券的顾客同时对糕点券感兴趣，建议推荐组合',
            Icons.restaurant_rounded,
          ),
          _buildSuggestionItem(
            '周末促销建议',
            '历史数据显示周六核销量+30%，建议推出周末限时活动',
            Icons.campaign_rounded,
          ),
        ],
      ),
    );
  }

  Widget _buildSuggestionItem(String title, String desc, IconData icon) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 6),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Icon(icon, color: AppColors.primary, size: 18),
          const SizedBox(width: 10),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(title,
                    style: const TextStyle(
                        fontSize: 13, fontWeight: FontWeight.w600)),
                const SizedBox(height: 2),
                Text(desc,
                    style: AppTypography.bodySmall
                        .copyWith(color: AppColors.textSecondary)),
              ],
            ),
          ),
        ],
      ),
    );
  }

  // ========================================
  // Tab 2: 客流预测
  // ========================================
  Widget _buildTrafficPredictionTab() {
    return SingleChildScrollView(
      padding: const EdgeInsets.all(20),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // Today's Prediction
          _buildTodayPrediction(),
          const SizedBox(height: 20),

          // Hourly Breakdown
          _buildHourlyBreakdown(),
          const SizedBox(height: 20),

          // Weekly Forecast
          _buildWeeklyForecast(),
          const SizedBox(height: 20),

          // Staffing Suggestion
          _buildStaffingSuggestion(),
        ],
      ),
    );
  }

  Widget _buildTodayPrediction() {
    return Container(
      padding: const EdgeInsets.all(20),
      decoration: BoxDecoration(
        gradient: AppColors.cardGradient,
        borderRadius: AppSpacing.borderRadiusLg,
      ),
      child: Column(
        children: [
          const Row(
            children: [
              Icon(Icons.insights_rounded, color: Colors.white, size: 22),
              SizedBox(width: 10),
              Text(
                '今日客流预测',
                style: TextStyle(
                    fontSize: 17,
                    fontWeight: FontWeight.w700,
                    color: Colors.white),
              ),
            ],
          ),
          const SizedBox(height: 20),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              _predictionStat('预计核销', '45笔'),
              _predictionStat('高峰时段', '11:30-13:00'),
              _predictionStat('预计收入', '\$892'),
            ],
          ),
          const SizedBox(height: 16),
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
            decoration: BoxDecoration(
              color: Colors.white.withValues(alpha: 0.15),
              borderRadius: AppSpacing.borderRadiusSm,
            ),
            child: Row(
              children: [
                const Text('✨',
                    style: TextStyle(fontSize: 14)),
                const SizedBox(width: 8),
                Expanded(
                  child: Text(
                    '较上周同期增长12%，建议午间增加1名收银员',
                    style: TextStyle(
                      fontSize: 12,
                      color: Colors.white.withValues(alpha: 0.9),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _predictionStat(String label, String value) {
    return Column(
      children: [
        Text(
          value,
          style: const TextStyle(
              fontSize: 18, fontWeight: FontWeight.w700, color: Colors.white),
        ),
        const SizedBox(height: 2),
        Text(
          label,
          style: TextStyle(
              fontSize: 11, color: Colors.white.withValues(alpha: 0.7)),
        ),
      ],
    );
  }

  Widget _buildHourlyBreakdown() {
    final hours = [
      ('9:00', 3),
      ('10:00', 5),
      ('11:00', 8),
      ('12:00', 12),
      ('13:00', 9),
      ('14:00', 4),
      ('15:00', 3),
      ('16:00', 2),
      ('17:00', 5),
      ('18:00', 7),
    ];
    final maxCount = 12;

    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.surface,
        borderRadius: AppSpacing.borderRadiusMd,
        border: Border.all(color: AppColors.borderLight),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('分时段预测', style: AppTypography.labelLarge),
          const SizedBox(height: 16),
          ...hours.map((h) {
            final (time, count) = h;
            final pct = count / maxCount;
            final isPeak = count >= 8;
            return Padding(
              padding: const EdgeInsets.symmetric(vertical: 4),
              child: Row(
                children: [
                  SizedBox(
                    width: 44,
                    child: Text(time,
                        style: AppTypography.caption
                            .copyWith(fontFamily: 'monospace')),
                  ),
                  Expanded(
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(3),
                      child: LinearProgressIndicator(
                        value: pct,
                        backgroundColor: AppColors.gray100,
                        valueColor: AlwaysStoppedAnimation(
                          isPeak ? AppColors.primary : AppColors.primaryLight,
                        ),
                        minHeight: 16,
                      ),
                    ),
                  ),
                  const SizedBox(width: 8),
                  SizedBox(
                    width: 30,
                    child: Text(
                      '$count笔',
                      style: TextStyle(
                        fontSize: 11,
                        fontWeight: isPeak ? FontWeight.w600 : FontWeight.w400,
                        color: isPeak ? AppColors.primary : AppColors.textSecondary,
                      ),
                    ),
                  ),
                ],
              ),
            );
          }),
        ],
      ),
    );
  }

  Widget _buildWeeklyForecast() {
    final days = [
      ('周一', 38, false),
      ('周二', 42, false),
      ('周三', 45, true),
      ('周四', 40, false),
      ('周五', 52, false),
      ('周六', 68, false),
      ('周日', 55, false),
    ];

    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.surface,
        borderRadius: AppSpacing.borderRadiusMd,
        border: Border.all(color: AppColors.borderLight),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('本周预测', style: AppTypography.labelLarge),
          const SizedBox(height: 16),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.end,
            children: days.map((d) {
              final (day, count, isToday) = d;
              final heightPct = count / 68;
              return Column(
                children: [
                  Text(
                    '$count',
                    style: TextStyle(
                      fontSize: 10,
                      fontWeight: FontWeight.w600,
                      color: isToday ? AppColors.primary : AppColors.textTertiary,
                    ),
                  ),
                  const SizedBox(height: 4),
                  Container(
                    width: 28,
                    height: 80 * heightPct,
                    decoration: BoxDecoration(
                      color: isToday ? AppColors.primary : AppColors.primarySurface,
                      borderRadius:
                          const BorderRadius.vertical(top: Radius.circular(4)),
                    ),
                  ),
                  const SizedBox(height: 4),
                  Text(
                    day,
                    style: TextStyle(
                      fontSize: 11,
                      fontWeight: isToday ? FontWeight.w600 : FontWeight.w400,
                      color: isToday ? AppColors.primary : AppColors.textSecondary,
                    ),
                  ),
                ],
              );
            }).toList(),
          ),
        ],
      ),
    );
  }

  Widget _buildStaffingSuggestion() {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.primarySurface,
        borderRadius: AppSpacing.borderRadiusMd,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              const Icon(Icons.people_alt_rounded,
                  color: AppColors.primary, size: 20),
              const SizedBox(width: 8),
              Text('排班建议', style: AppTypography.labelLarge),
            ],
          ),
          const SizedBox(height: 12),
          _staffRow('上午 (9:00-13:00)', '建议 2 人', '含午间高峰'),
          _staffRow('下午 (13:00-17:00)', '建议 1 人', '客流较少'),
          _staffRow('傍晚 (17:00-21:00)', '建议 2 人', '下班高峰'),
        ],
      ),
    );
  }

  Widget _staffRow(String period, String suggestion, String reason) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 6),
      child: Row(
        children: [
          Expanded(
            flex: 3,
            child: Text(period, style: AppTypography.bodySmall),
          ),
          Expanded(
            flex: 2,
            child: Text(suggestion,
                style: AppTypography.labelSmall
                    .copyWith(color: AppColors.primary)),
          ),
          Expanded(
            flex: 2,
            child: Text(reason, style: AppTypography.caption),
          ),
        ],
      ),
    );
  }

  // ========================================
  // Tab 3: 异常预警
  // ========================================
  Widget _buildAnomalyAlertTab() {
    return SingleChildScrollView(
      padding: const EdgeInsets.all(20),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // Alert Summary
          _buildAlertSummary(),
          const SizedBox(height: 20),

          // Active Alerts
          _buildActiveAlerts(),
          const SizedBox(height: 20),

          // Suspicious Patterns
          _buildSuspiciousPatterns(),
          const SizedBox(height: 20),

          // Recent Resolved
          _buildResolvedAlerts(),
        ],
      ),
    );
  }

  Widget _buildAlertSummary() {
    return Row(
      children: [
        _alertStatCard('待处理', '2', AppColors.error),
        const SizedBox(width: 12),
        _alertStatCard('今日已处理', '5', AppColors.success),
        const SizedBox(width: 12),
        _alertStatCard('风险指数', '低', AppColors.info),
      ],
    );
  }

  Widget _alertStatCard(String label, String value, Color color) {
    return Expanded(
      child: Container(
        padding: const EdgeInsets.all(14),
        decoration: BoxDecoration(
          color: color.withValues(alpha: 0.08),
          borderRadius: AppSpacing.borderRadiusMd,
          border: Border.all(color: color.withValues(alpha: 0.2)),
        ),
        child: Column(
          children: [
            Text(value,
                style: TextStyle(
                    fontSize: 22, fontWeight: FontWeight.w700, color: color)),
            const SizedBox(height: 2),
            Text(label, style: AppTypography.caption.copyWith(color: color)),
          ],
        ),
      ),
    );
  }

  Widget _buildActiveAlerts() {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.surface,
        borderRadius: AppSpacing.borderRadiusMd,
        border: Border.all(color: AppColors.error.withValues(alpha: 0.3)),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              const Icon(Icons.warning_amber_rounded,
                  color: AppColors.error, size: 20),
              const SizedBox(width: 8),
              Text('活跃预警',
                  style:
                      AppTypography.labelLarge.copyWith(color: AppColors.error)),
            ],
          ),
          const SizedBox(height: 12),
          _alertItem(
            '高频核销检测',
            '用户#78901 在 5 分钟内尝试核销 3 张同品牌券',
            '2 分钟前',
            AppColors.error,
            Icons.speed_rounded,
          ),
          const Divider(height: 20),
          _alertItem(
            '疑似伪造券码',
            '券码 GNX-FAKE-001 格式异常，不在系统记录中',
            '15 分钟前',
            AppColors.warning,
            Icons.gpp_bad_rounded,
          ),
        ],
      ),
    );
  }

  Widget _alertItem(
      String title, String desc, String time, Color color, IconData icon) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            width: 36,
            height: 36,
            decoration: BoxDecoration(
              color: color.withValues(alpha: 0.1),
              borderRadius: AppSpacing.borderRadiusSm,
            ),
            child: Icon(icon, color: color, size: 18),
          ),
          const SizedBox(width: 10),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(title, style: AppTypography.labelMedium),
                const SizedBox(height: 2),
                Text(desc, style: AppTypography.bodySmall),
                const SizedBox(height: 4),
                Text(time, style: AppTypography.caption),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildSuspiciousPatterns() {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.surface,
        borderRadius: AppSpacing.borderRadiusMd,
        border: Border.all(color: AppColors.borderLight),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              const Icon(Icons.pattern_rounded,
                  color: AppColors.warning, size: 20),
              const SizedBox(width: 8),
              Text('可疑模式检测', style: AppTypography.labelLarge),
            ],
          ),
          const SizedBox(height: 12),
          _patternItem(
              '同一用户连续核销', '3次/5分钟 (阈值: 2次/5分钟)', 0.8, AppColors.error),
          const SizedBox(height: 10),
          _patternItem(
              '非营业时间核销尝试', '0次/本周', 0.0, AppColors.success),
          const SizedBox(height: 10),
          _patternItem(
              '过期券核销尝试', '2次/今日', 0.4, AppColors.warning),
        ],
      ),
    );
  }

  Widget _patternItem(
      String label, String detail, double severity, Color color) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(label, style: AppTypography.labelMedium.copyWith(fontSize: 13)),
            Container(
              padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
              decoration: BoxDecoration(
                color: color.withValues(alpha: 0.1),
                borderRadius: AppSpacing.borderRadiusFull,
              ),
              child: Text(
                severity > 0.6
                    ? '异常'
                    : severity > 0.2
                        ? '注意'
                        : '正常',
                style: TextStyle(
                    fontSize: 10, fontWeight: FontWeight.w600, color: color),
              ),
            ),
          ],
        ),
        const SizedBox(height: 4),
        Text(detail, style: AppTypography.caption),
        const SizedBox(height: 6),
        ClipRRect(
          borderRadius: BorderRadius.circular(3),
          child: LinearProgressIndicator(
            value: severity,
            backgroundColor: AppColors.gray100,
            valueColor: AlwaysStoppedAnimation(color),
            minHeight: 4,
          ),
        ),
      ],
    );
  }

  Widget _buildResolvedAlerts() {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.surface,
        borderRadius: AppSpacing.borderRadiusMd,
        border: Border.all(color: AppColors.borderLight),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('今日已处理', style: AppTypography.labelLarge),
          const SizedBox(height: 12),
          _resolvedItem('过期券核销拦截', '系统自动拦截', '10:24'),
          _resolvedItem('重复核销拦截', '同一券码二次扫描', '11:05'),
          _resolvedItem('非本店券提醒', '引导至正确门店', '12:30'),
          _resolvedItem('余额不足核销', '告知顾客充值', '13:15'),
          _resolvedItem('系统超时重试', '网络恢复后自动完成', '14:02'),
        ],
      ),
    );
  }

  Widget _resolvedItem(String title, String desc, String time) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 6),
      child: Row(
        children: [
          const Icon(Icons.check_circle_rounded,
              color: AppColors.success, size: 16),
          const SizedBox(width: 10),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(title, style: AppTypography.bodyMedium),
                Text(desc, style: AppTypography.caption),
              ],
            ),
          ),
          Text(time,
              style: AppTypography.caption
                  .copyWith(fontFamily: 'monospace')),
        ],
      ),
    );
  }
}
