AutoCat/AutoCat/SwiftUI/VehicleCellView.swift

76 lines
2.4 KiB
Swift

//
// VehicleCellView.swift
// AutoCat
//
// Created by Selim Mustafaev on 16.01.2025.
// Copyright © 2025 Selim Mustafaev. All rights reserved.
//
import SwiftUI
import AutoCatCore
struct VehicleCellView: View {
let vehicle: VehicleDto
var body: some View {
VStack {
HStack(spacing: 4) {
if let name = vehicle.brand?.name?.original {
Text(name)
.font(.headline)
}
Spacer(minLength: 0)
if !vehicle.synchronized && !vehicle.unrecognized {
Image(systemName: "exclamationmark.arrow.triangle.2.circlepath")
.frame(width: 20, height: 20)
.foregroundStyle(.orange)
}
if !vehicle.notes.isEmpty {
Image(systemName: "text.bubble")
.frame(width: 20, height: 20)
.foregroundStyle(.blue)
Text(String(vehicle.notes.count))
.font(.callout)
}
}
HStack(alignment: .bottom, spacing: 8) {
LicensePlateView(number: PlateNumber(vehicle.getNumber()), foreground: getForegroundColor())
.frame(height: 40)
Spacer(minLength: 8)
VStack(alignment: .trailing, spacing: 8) {
if abs(vehicle.updatedDate - vehicle.addedDate) > 10 {
Text(Formatters.short.string(from: Date(timeIntervalSince1970: vehicle.updatedDate)))
.font(.footnote)
.foregroundStyle(.secondary)
}
Text(Formatters.short.string(from: Date(timeIntervalSince1970: vehicle.addedDate)))
.font(.footnote)
.foregroundStyle(.tertiary)
}
}
}
.contentShape(Rectangle())
}
func getForegroundColor() -> Color {
if vehicle.unrecognized {
.red
} else if vehicle.outdated {
Color("PlateForegroundGray")
} else {
Color("PlateForeground")
}
}
}
#Preview {
VehicleCellView(vehicle: .preview)
}