FuelMan/Gas Man/FuelLogs/FuelLogDetailView.swift

125 lines
4.0 KiB
Swift

//
// FuelLogDetailView.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 FuelLogDetailView: View {
@ObservedObject var fuelLog: FuelLog
@State private var showingEditFuelLog = false
var body: some View {
Form {
// Vehicle header section
if let vehicle = fuelLog.vehicle {
Section {
Text("\(vehicle.year ?? "") \(vehicle.model ?? "")")
.font(.headline)
.frame(maxWidth: .infinity, alignment: .center)
}
}
Section(header: Text("")) {
HStack {
Text("Date:")
Spacer()
Text(fuelLog.date ?? Date(), formatter: dateFormatter)
}
HStack {
Text("Odometer:")
Spacer()
Text("\(fuelLog.odometer, specifier: "%.0f") miles")
}
}
Section(header: Text("Fuel Information")) {
HStack {
Text("Fuel Volume:")
Spacer()
Text("\(fuelLog.fuelVolume, specifier: "%.3f") gallons")
}
HStack {
Text("Cost:")
Spacer()
Text("$\(fuelLog.cost, specifier: "%.2f")")
}
HStack {
Text("Price per Gallon:")
Spacer()
Text("$\(fuelLog.pricePerGalon, specifier: "%.3f")")
}
}
Section(header: Text("Tank Status")) {
HStack {
Text("Tank:")
Spacer()
if fuelLog.fullTank {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
Text("Full")
} else {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.red)
Text("Not Full")
}
}
}
Section {
HStack {
Text("Previous Fill-Up")
Spacer()
if fuelLog.missedPrevious {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.red)
Text("Missed")
} else {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
Text("Exists")
}
}
}
Section(header: Text("Location")) {
HStack {
Text("Coordinates:")
Spacer()
Text(fuelLog.locationCoordinates ?? "N/A")
}
HStack {
Text("Location Name:")
Spacer()
Text(fuelLog.locationName ?? "N/A")
}
}
Section(header: Text("Fuel Details")) {
HStack {
Text("Octane:")
Spacer()
Text("\(fuelLog.octane)")
}
}
}
.navigationTitle("Fuel Log Detail")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button("Edit") {
showingEditFuelLog = true
}
}
}
.sheet(isPresented: $showingEditFuelLog) {
EditFuelLogView(fuelLog: fuelLog)
.environment(\.managedObjectContext, fuelLog.managedObjectContext!)
}
}
}