//
//  ScenicPromotionMetricsGridView.swift
//  suixinkan
//
//  Created by Codex on 2026/7/2.
//

import SwiftUI

/// 宣传页三个排队数据卡片：当前排队人数、预计等待时间、平均等待时长。
struct ScenicPromotionMetricsGridView: View {
    let queue: ScenicPromotionQueueInfo?

    var body: some View {
        let metrics: [(String, String, String, Color)] = [
            ("当前排队人数", queue.map { "\($0.waitingPeople)" } ?? "--", "人", Color(hex: 0x1580FF)),
            ("预计等待时间", queue.map { "\($0.estimatedMinutes)" } ?? "--", "分钟", Color(hex: 0xF28C18)),
            ("平均等待时长", queue.map { "\($0.averageMinutes)" } ?? "--", "分钟", Color(hex: 0x2D8E43))
        ]

        LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 12), count: 3), spacing: 12) {
            ForEach(metrics, id: \.0) { metric in
                VStack(spacing: 8) {
                    Text(metric.0)
                        .font(.system(size: 12, weight: .semibold))
                        .foregroundStyle(Color(hex: 0x113B79))
                        .lineLimit(1)
                        .minimumScaleFactor(0.76)
                    HStack(alignment: .lastTextBaseline, spacing: 2) {
                        Text(metric.1)
                            .font(.system(size: 34, weight: .heavy))
                            .foregroundStyle(metric.3)
                            .minimumScaleFactor(0.55)
                        if metric.1 != "--" {
                            Text(metric.2)
                                .font(.system(size: 13, weight: .medium))
                                .foregroundStyle(metric.3)
                        }
                    }
                    if metric.1 == "--" {
                        Text("暂无数据")
                            .font(.system(size: 11))
                            .foregroundStyle(Color(hex: 0x5272A5))
                    }
                }
                .padding(.horizontal, 6)
                .frame(maxWidth: .infinity)
                .frame(height: 92)
                .background(.white.opacity(0.84), in: RoundedRectangle(cornerRadius: 14))
                .overlay(
                    RoundedRectangle(cornerRadius: 14)
                        .stroke(.white.opacity(0.85), lineWidth: 1)
                )
            }
        }
    }
}

#if DEBUG
#Preview("排队数据") {
    ScenicPromotionMetricsGridView(queue: ScenicPromotionPreviewSupport.sampleQueue)
        .padding(.horizontal, 20)
}

#Preview("排队数据-空") {
    ScenicPromotionMetricsGridView(queue: nil)
        .padding(.horizontal, 20)
}
#endif
