//
//  EmptyStateView.swift
//  LotteryTracker
//
//  Created by aaa on 2026/1/22.
//

import SwiftUI

struct EmptyStateView: View {
    var onAddTapped: (() -> Void)? = nil
    
    var body: some View {
        VStack(spacing: 20) {
            // 图标
            Image(systemName: "ticket")
                .font(.system(size: 70))
                .foregroundColor(.gray.opacity(0.5))
            
            // 标题
            Text("暂无购买记录")
                .font(.title2)
                .fontWeight(.semibold)
                .foregroundColor(.primary)
            
            // 描述
            Text("开始记录您的第一张彩票吧")
                .font(.body)
                .foregroundColor(.secondary)
                .multilineTextAlignment(.center)
            
            // 点击添加按钮
            if let onAddTapped = onAddTapped {
                Button(action: onAddTapped) {
                    VStack(spacing: 8) {
                        Image(systemName: "plus.circle.fill")
                            .font(.title2)
                            .foregroundColor(.blue)
                        
                        Text("点击这里添加")
                            .font(.caption)
                            .foregroundColor(.blue)
                    }
                    .padding()
                    .background(Color.blue.opacity(0.1))
                    .cornerRadius(8)
                }
                .padding(.top, 20)
            } else {
                // 如果没有回调，显示静态提示
                VStack(spacing: 8) {
                    Image(systemName: "plus.circle.fill")
                        .font(.title2)
                        .foregroundColor(.blue.opacity(0.5))
                    
                    Text("点击右上角+按钮添加")
                        .font(.caption)
                        .foregroundColor(.blue.opacity(0.5))
                }
                .padding(.top, 20)
            }
        }
        .padding(.horizontal, 40)
        .frame(maxWidth: .infinity, maxHeight: .infinity)
    }
}

// 预览
struct EmptyStateView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            // 预览带按钮的版本
            EmptyStateView(onAddTapped: {
                print("添加按钮被点击")
            })
            .previewLayout(.sizeThatFits)
            .previewDisplayName("带按钮")
            
            // 预览不带按钮的版本
            EmptyStateView()
                .previewLayout(.sizeThatFits)
                .previewDisplayName("不带按钮")
        }
    }
}
