DomainDig/BatchSweepSummaryView.swift

1f58092dcb67cded75a850db364f3b46d86181f3
domain-dig/DomainDig/BatchSweepSummaryView.swift history · blame · raw

68 lines · 2583 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.changeSeverity ?? .low) >= .medium || $0.certificateWarningLevel != .none || $0.status == .failed
16        }
17    }
18
19    var body: some View {
20        NavigationStack {
21            List {
22                Section("Overview") {
23                    statRow(label: "Checked", value: "\(summary.totalDomains)")
24                    statRow(label: "Changed", value: "\(summary.changedDomains)")
25                    statRow(label: "Warnings", value: "\(summary.warningDomains)")
26                    statRow(label: "Unchanged", value: "\(summary.unchangedDomains)")
27                }
28
29                Section {
30                    Toggle("Show unchanged domains", isOn: $showUnchangedDomains)
31                }
32
33                Section(visibleResults.isEmpty ? "Changed Domains" : "Results") {
34                    if visibleResults.isEmpty {
35                        Text("No domains with changes or warnings")
36                            .font(.system(.caption, design: .monospaced))
37                            .foregroundStyle(.secondary)
38                    } else {
39                        ForEach(visibleResults) { result in
40                            if let entry = viewModel.historyEntry(for: result) {
41                                NavigationLink {
42                                    HistoryDetailView(viewModel: viewModel, entry: entry)
43                                } label: {
44                                    BatchResultRowView(result: result)
45                                }
46                            } else {
47                                BatchResultRowView(result: result)
48                            }
49                        }
50                    }
51                }
52            }
53            .navigationTitle(summary.source == .watchlistRefresh ? "Sweep Summary" : "Batch Summary")
54        }
55    }
56
57    private func statRow(label: String, value: String) -> some View {
58        HStack {
59            Text(label)
60                .font(.system(.caption, design: .monospaced))
61                .foregroundStyle(.secondary)
62            Spacer()
63            Text(value)
64                .font(.system(.callout, design: .monospaced))
65                .foregroundStyle(.primary)
66        }
67    }
68}