import SwiftUI

// MARK: - QR码预览组件
struct QRCodePreviewView: View {
    let qrCodeImage: UIImage?
    let formattedContent: String
    let qrCodeType: QRCodeType
    
    var body: some View {
        VStack(spacing: 16) {
            HStack {
                InputTitleView.required("preview".localized, icon: "eye")
                    .padding(.horizontal, 20)
                
                Spacer()
            }
            
            // 二维码预览卡片
            VStack(spacing: 16) {
                // 二维码图片
                if let qrImage = qrCodeImage {
                    Image(uiImage: qrImage)
                        .interpolation(.none)
                        .resizable()
                        .scaledToFit()
                        .frame(width: 200, height: 200)
                        .background(Color.white)
                        .cornerRadius(12)
                        .shadow(color: .black.opacity(0.1), radius: 8, x: 0, y: 4)
                } else {
                    // 占位符
                    RoundedRectangle(cornerRadius: 12)
                        .fill(Color(.systemGray5))
                        .frame(width: 200, height: 200)
                        .overlay(
                            VStack(spacing: 8) {
                                Image(systemName: "qrcode")
                                    .font(.system(size: 40))
                                    .foregroundColor(.secondary)
                                Text("cannot_generate_qrcode".localized)
                                    .font(.caption)
                                    .foregroundColor(.secondary)
                            }
                        )
                }
                
                // 内容预览卡片
                VStack(alignment: .leading, spacing: 8) {
                    HStack {
                        Text("content".localized)
                            .font(.caption)
                            .foregroundColor(.secondary)
                        
                        Spacer()
                        
                        Text(qrCodeType.displayName)
                            .font(.caption)
                            .padding(.horizontal, 6)
                            .padding(.vertical, 2)
                            .background(Color.orange.opacity(0.1))
                            .foregroundColor(.orange)
                            .cornerRadius(4)
                    }
                    
                    Text(formattedContent)
                        .font(.body)
                        .foregroundColor(.primary)
                        .textSelection(.enabled)
                        .lineLimit(nil)
                }
                .padding()
                .background(Color(.systemGray6))
                .cornerRadius(8)
            }
            .padding()
            .background(Color(.systemBackground))
            .cornerRadius(12)
            .shadow(color: .black.opacity(0.05), radius: 4, x: 0, y: 2)
        }
    }
}

#Preview {
    QRCodePreviewView(
        qrCodeImage: nil,
        formattedContent: "sample_content".localized,
        qrCodeType: .text
    )
} 
