DomainDig/BatchSweepSummaryView.swift
71 lines · 2648 bytes
1import SwiftUI
2
3struct BatchSweepSummaryView: View {
4 @Bindable var viewModel: DomainViewModel
5 let summary: BatchSweepSummary
6
7 @State private var showUnchangedDomains = false
8
9 private var visibleResults: [BatchLookupResult] {
10 if showUnchangedDomains {
11 return summary.results
12 }
13
14 return summary.results.filter {
15 $0.quickStatus == "Changed" ||
16 $0.quickStatus == "High" ||
17 $0.certificateWarningLevel != .none ||
18 $0.status == .failed
19 }
20 }
21
22 var body: some View {
23 NavigationStack {
24 List {
25 Section("Overview") {
26 statRow(label: "Checked", value: "\(summary.totalDomains)")
27 statRow(label: "Changed", value: "\(summary.changedDomains)")
28 statRow(label: "Warnings", value: "\(summary.warningDomains)")
29 statRow(label: "Unchanged", value: "\(summary.unchangedDomains)")
30 }
31
32 Section {
33 Toggle("Show unchanged domains", isOn: $showUnchangedDomains)
34 }
35
36 Section(visibleResults.isEmpty ? "Changed Domains" : "Results") {
37 if visibleResults.isEmpty {
38 Text("No domains with changes or warnings")
39 .font(.system(.caption, design: .monospaced))
40 .foregroundStyle(.secondary)
41 } else {
42 ForEach(visibleResults) { result in
43 if let entry = viewModel.historyEntry(for: result) {
44 NavigationLink {
45 HistoryDetailView(viewModel: viewModel, entry: entry)
46 } label: {
47 BatchResultRowView(result: result)
48 }
49 } else {
50 BatchResultRowView(result: result)
51 }
52 }
53 }
54 }
55 }
56 .navigationTitle(summary.source == .watchlistRefresh ? "Sweep Summary" : "Batch Summary")
57 }
58 }
59
60 private func statRow(label: String, value: String) -> some View {
61 HStack {
62 Text(label)
63 .font(.system(.caption, design: .monospaced))
64 .foregroundStyle(.secondary)
65 Spacer()
66 Text(value)
67 .font(.system(.callout, design: .monospaced))
68 .foregroundStyle(.primary)
69 }
70 }
71}