import SwiftUI
import HealthDB
import HealthKit
import HealthKitExtensions

struct CategoryEnumSampleList<T>: View where T: HKCategoryEnumSample {

    let database: HealthDatabase

    @State
    private var samples: [T] = []

    var body: some View {
        GenericSampleList(sampleView: { sample in
            HStack {
                Text("\(sample.value)")
                Spacer()
                Text(sample.endDate.formatted())
            }
        }, search: { start, end, _ -> [T] in
            try database.samples(from: start, to: end)
        })
        .navigationTitle(T.categoryTypeIdentifier.description)
    }
}

#Preview {
    NavigationStack {
        CategoryEnumSampleList<AbdominalCramps>(database: .empty)
    }
}
