import SwiftUI
import HealthKit
import HealthKitExtensions
import HealthDB

struct EventDetailView: View {
    
    let event: HKWorkoutEvent

    var metadata: [(key: String, value: Any)] {
        event.metadata?.sorted { $0.key < $1.key } ?? []
    }

    var body: some View {
        List {
            DetailRow("Date", date: event.dateInterval.start)
            DetailRow("Type", value: event.type)
            DetailRow("Duration", duration: event.dateInterval.duration)
            //DetailRow("Session UUID", value: event.sessionUUID)
            //DetailRow("Error", value: event.error)
            Section("Metadata") {
                ForEach(metadata, id: \.key) { (key, value) in
                    DetailRow(MetadataKeyName(key), value: "\(value)")
                }
            }
        }
        .navigationTitle("Event")
    }
}

#Preview {
    NavigationStack {
        EventDetailView(event: .mock1.first!)
    }
}
