import SwiftUI
import CoreLocation

struct LocationSampleDetailView: View {

    let location: CLLocation

    var body: some View {
        List {
            DetailRow("Timestamp", date: location.timestamp)
            DetailRow("Latitude", 
                      value: location.coordinate.latitude.asDegrees(decimals: 8))
            DetailRow("Longitude", value: location.coordinate.longitude.asDegrees(decimals: 8))
            DetailRow("Hor. accuracy", value: location.horizontalAccuracy.meter)
            DetailRow("Altitude", value: location.altitude.meter)
            DetailRow("Ver. accuracy", value: location.verticalAccuracy.meter)
            DetailRow("Speed", value: location.speed.speedAsMetersPerSecond)
            DetailRow("Speed accuracy", value: location.speedAccuracy.speedAsMetersPerSecond)
            DetailRow("Course", value: location.course.asDegrees())
            DetailRow("Course accuracy", value: location.courseAccuracy.asDegrees())
        }
        .navigationTitle("Location")
    }
}

#Preview {
    NavigationStack {
        LocationSampleDetailView(location: .mock)
    }
}
