//
//  RecordsView.swift
//  LeCountdown
//
//  Created by Laurent Morvillier on 17/02/2023.
//

import SwiftUI

struct RecordsView: View {
    
    var activity: Activity
    
    var body: some View {
        
        List {
            
            if let records = self.activity.records as? Set<Record> {
                
                let array: [Record] = Array(records)
                
                ForEach(array) { record in
                    HStack {
                        Text(record.details)
                        Spacer()
                        if let duration = record.duration {
                            Text(duration.minuteSecond)
                        }
                    }
                }
            }
        }
        
    }
    
}

struct RecordsView_Previews: PreviewProvider {
    static var previews: some View {
        RecordsView(activity:
                        Activity.fake(context: PersistenceController.preview.container.viewContext))
    }
}
