import SwiftUI
import Bedrock
import SwiftData

/// A QR code view using Bedrock's QRCodeImageView.
struct QRCodeView: View {
    let payload: String

    var body: some View {
        QRCodeImageView(payload: payload)
            .accessibilityLabel(String.localized("QR code"))
    }
}

#Preview {
    let container = try! ModelContainer(for: BusinessCard.self, Contact.self)
    let context = container.mainContext
    BusinessCard.createSamples(in: context)
    let cards = try! context.fetch(FetchDescriptor<BusinessCard>())
    
    return QRCodeView(payload: cards.first?.vCardPayload ?? "")
        .environment(AppState(modelContext: context))
        .padding()
}
