import SwiftUI
import HealthDB
import HealthKit
import HealthKitExtensions

struct CategoryEmptySampleList<T>: View where T: HKCategoryEmptySample {

    let database: HealthDatabase

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

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

#Preview {
    NavigationStack {
        CategoryEmptySampleList<MindfulSession>(database: .empty)
    }
}
