76 lines
2.4 KiB
Swift
76 lines
2.4 KiB
Swift
//
|
||
// OwnersScreen.swift
|
||
// AutoCat
|
||
//
|
||
// Created by Selim Mustafaev on 14.07.2024.
|
||
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
||
//
|
||
|
||
import SwiftUI
|
||
import AutoCatCore
|
||
|
||
struct OwnersScreen: View {
|
||
|
||
let formatter: DateFormatter = {
|
||
let formatter = DateFormatter()
|
||
formatter.dateStyle = .medium
|
||
formatter.timeStyle = .none
|
||
return formatter
|
||
}()
|
||
|
||
let ownerships: [VehicleOwnershipPeriodDto]
|
||
|
||
var body: some View {
|
||
|
||
List(ownerships) { ownership in
|
||
Section(header: Text(makeHeader(for: ownership))) {
|
||
|
||
HStack {
|
||
Text("Owner type")
|
||
Spacer()
|
||
Text(ownership.ownerType)
|
||
.foregroundStyle(.secondary)
|
||
}
|
||
|
||
Text(ownership.lastOperation)
|
||
.foregroundStyle(.secondary)
|
||
.font(.callout)
|
||
}
|
||
}
|
||
.navigationTitle(String.localizedStringWithFormat(NSLocalizedString("owners count", comment: ""), ownerships.count))
|
||
}
|
||
|
||
func makeHeader(for owner: VehicleOwnershipPeriodDto) -> String {
|
||
|
||
let fromDate = Date(timeIntervalSince1970: TimeInterval(owner.from/1000))
|
||
let from = self.formatter.string(from: fromDate)
|
||
var to = NSLocalizedString("now", comment: "")
|
||
if owner.to > 0 {
|
||
let toDate = Date(timeIntervalSince1970: TimeInterval(owner.to/1000))
|
||
to = self.formatter.string(from: toDate)
|
||
}
|
||
|
||
return "\(from) - \(to)"
|
||
}
|
||
}
|
||
|
||
#Preview {
|
||
|
||
let ownerships: [VehicleOwnershipPeriodDto] = [
|
||
.init(lastOperation: "в связи с прекращением права собственности (отчуждение, конфискация ТС)",
|
||
ownerType: "individual",
|
||
from: 1018051200000,
|
||
to: 1094515200000),
|
||
.init(lastOperation: "в связи с прекращением права собственности (отчуждение, конфискация ТС)",
|
||
ownerType: "individual",
|
||
from: 1099440000000,
|
||
to: 1105488000000),
|
||
.init(lastOperation: "регистрация снятых с учета",
|
||
ownerType: "individual",
|
||
from: 1105747200000,
|
||
to: 1323129600000)
|
||
]
|
||
|
||
return OwnersScreen(ownerships: ownerships)
|
||
}
|