FuelMan/Gas Man/FuelLogs/FuelLogSummaryView.swift

99 lines
2.9 KiB
Swift

//
// FuelLogSummaryView.swift
// Gas Man
//
// Created by Kameron Kenny on 3/17/25.
//
import SwiftUI
private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .short
formatter.timeStyle = .short
return formatter
}()
struct FuelLogSummaryView: View {
var log: FuelLog
var mpg: Double?
var distanceSincePrevious: Double?
var body: some View {
VStack(alignment: .leading, spacing: 2) {
Rectangle()
.fill(Color.gray)
.frame(height: 2)
// Row 1: Date and MPG (if available)
HStack {
Text(log.date ?? Date(), formatter: dateFormatter)
.font(.subheadline)
.foregroundColor(.primary)
Spacer()
if let mpg = mpg {
Text("MPG: \(mpg, specifier: "%.3f")")
.font(.subheadline)
.foregroundColor(.primary)
.bold()
}
}
.padding(2)
// .background(Color.accentColor)
.cornerRadius(4)
Divider()
// Row 2: Distance (instead of odometer) and Fuel Volume
HStack {
HStack() {
Text("Distance")
.font(.caption)
.foregroundColor(.secondary)
if let distance = distanceSincePrevious {
Text("\(distance, specifier: "%.0f") miles")
.bold()
} else {
Text("N/A")
.bold()
}
}
Spacer()
HStack() {
Text("Fuel (Gal)")
.font(.caption)
.foregroundColor(.secondary)
Text("\(log.fuelVolume, specifier: "%.3f")")
.bold()
}
}
// Row 3: Cost and Price per Gallon
HStack {
HStack() {
Text("Cost")
.font(.caption)
.foregroundColor(.secondary)
Text("$\(log.cost, specifier: "%.2f")")
.bold()
}
Spacer()
HStack() {
Text("Price/Gal")
.font(.caption)
.foregroundColor(.secondary)
Text("$\(log.pricePerGalon, specifier: "%.3f")")
.bold()
}
}
Rectangle()
.fill(Color.gray)
.frame(height: 2)
}
.padding(8)
.background(Color(.secondarySystemBackground))
.cornerRadius(8)
}
}