DomainDig/EmailSectionView.swift

80 lines · 3812 bytes

 1import SwiftUI
 2
 3// One inspection section: the email security card. Pure presentation over the
 4// view model's report data; the shared primitives it builds on (CardView,
 5// SectionTitleView, LabeledValueRow, ResultColors, appLoadingStyle) live in
 6// ResultPrimitives.swift.
 7
 8struct EmailSectionView: View {
 9    @Environment(\.appDensity) private var appDensity
10    @Binding var isCollapsed: Bool
11    let rows: [EmailRowViewData]
12    let assessment: EmailSecuritySummary?
13    let loading: Bool
14    let provenance: SectionProvenance?
15    let confidence: ConfidenceLevel?
16    let error: String?
17
18    var body: some View {
19        CollapsibleSectionView(title: "Email", isCollapsed: $isCollapsed) {
20            CardView {
21                SectionTrustMetadataView(provenance: provenance, confidence: confidence)
22                HStack {
23                    Spacer()
24                    AppStatusBadgeView(model: AppStatusFactory.email(nil, error: error))
25                        .opacity(loading ? 0 : 1)
26                }
27                if let assessment, let grade = assessment.grade {
28                    LabeledValueRow(row: InfoRowViewData(label: "Grade", value: grade.rawValue, tone: grade.tone))
29                    if !assessment.reasons.isEmpty {
30                        Text(assessment.reasons.joined(separator: " | "))
31                            .font(appDensity.font(.caption2))
32                            .foregroundStyle(ThemeToken.textSecondary)
33                    }
34                }
35                if loading {
36                    ProgressView("Checking email records…")
37                        .appLoadingStyle()
38                } else if let error {
39                    MessageRowView(text: error, isError: true)
40                } else if rows.isEmpty {
41                    MessageRowView(text: "No email security records found", isError: false)
42                } else {
43                    ForEach(rows) { row in
44                        VStack(alignment: .leading, spacing: 4) {
45                            HStack(spacing: 8) {
46                                Text(row.label)
47                                    .font(appDensity.font(.caption))
48                                    .foregroundStyle(ThemeToken.info)
49                                    .frame(width: 76, alignment: .leading)
50                                AppStatusBadgeView(model: emailRowBadge(row))
51                            }
52                            Text(row.detail)
53                                .font(appDensity.font(.caption2))
54                                .foregroundStyle(.primary)
55                                .textSelection(.enabled)
56                            if let auxiliaryDetail = row.auxiliaryDetail {
57                                Text(auxiliaryDetail)
58                                    .font(appDensity.font(.caption2))
59                                    .foregroundStyle(ThemeToken.textSecondary)
60                            }
61                        }
62                    }
63                }
64            }
65        }
66    }
67
68    private func emailRowBadge(_ row: EmailRowViewData) -> AppStatusBadgeModel {
69        switch row.statusTone {
70        case .success:
71            return .init(title: row.status, systemImage: "checkmark.shield.fill", foreground: .positive, background: .positiveSurface)
72        case .warning:
73            return .init(title: row.status, systemImage: "shield.lefthalf.filled", foreground: .warning, background: .warningSurface)
74        case .failure:
75            return .init(title: row.status, systemImage: "minus.circle", foreground: .textSecondary, background: .surfaceElevated)
76        case .primary, .secondary:
77            return .init(title: row.status, systemImage: "circle", foreground: .textSecondary, background: .surfaceElevated)
78        }
79    }
80}