DomainDig/IntelligenceSectionView.swift
126 lines · 6839 bytes
3 symbols in this file
1import SwiftUI
2
3// One inspection section: the derived risk and timeline card. Pure
4// presentation over the view model's report data; the shared primitives it
5// builds on (CardView, SectionTitleView, LabeledValueRow, ResultColors,
6// appLoadingStyle) live in ResultPrimitives.swift.
7
8struct IntelligenceSectionView: View {
9 @Environment(\.appDensity) private var appDensity
10 @Binding var isCollapsed: Bool
11 let report: DomainReport
12 let showsPlaceholder: Bool
13
14 var body: some View {
15 CollapsibleSectionView(title: "Data+ Intelligence", isCollapsed: $isCollapsed) {
16 CardView(allowsHorizontalScroll: false) {
17 if showsPlaceholder {
18 MessageRowView(text: "Richer intelligence history, hosting analysis, and risk signals are available in Pro+", isError: false)
19 } else {
20 if let provider = report.inferredProvider {
21 intelligenceBlock(title: "Infrastructure") {
22 LabeledValueRow(row: .init(label: "Provider", value: provider.name, tone: .primary))
23 if !provider.evidence.isEmpty {
24 MessageRowView(text: provider.evidence.joined(separator: " • "), isError: false)
25 }
26 if !report.priorProviders.isEmpty {
27 LabeledValueRow(row: .init(label: "Prior", value: report.priorProviders.joined(separator: ", "), tone: .secondary))
28 }
29 }
30 }
31 if let classification = report.domainClassification {
32 intelligenceBlock(title: "Classification") {
33 LabeledValueRow(row: .init(label: "Purpose", value: classification.kind.title, tone: .primary))
34 MessageRowView(text: classification.reasons.joined(separator: " • "), isError: false)
35 }
36 }
37 intelligenceBlock(title: "Risk Signals") {
38 if report.riskSignals.isEmpty {
39 MessageRowView(text: "No material historical risk signals detected", isError: false)
40 } else {
41 ForEach(report.riskSignals.prefix(4)) { signal in
42 VStack(alignment: .leading, spacing: 3) {
43 Text(signal.title)
44 .font(appDensity.font(.caption, weight: .semibold))
45 Text(signal.detail)
46 .font(appDensity.font(.caption2))
47 .foregroundStyle(ThemeToken.textSecondary)
48 }
49 }
50 }
51 }
52 intelligenceBlock(title: "Ownership History") {
53 if report.ownershipTransitions.isEmpty {
54 MessageRowView(text: "No ownership transitions observed locally", isError: false)
55 } else {
56 ForEach(report.ownershipTransitions.prefix(4)) { event in
57 intelligenceEventRow(date: event.date, title: event.summary)
58 }
59 }
60 }
61 intelligenceBlock(title: "Hosting History") {
62 if report.hostingTransitions.isEmpty {
63 MessageRowView(text: "No hosting transitions observed locally", isError: false)
64 } else {
65 ForEach(report.hostingTransitions.prefix(4)) { event in
66 intelligenceEventRow(date: event.date, title: event.summary)
67 }
68 }
69 }
70 intelligenceBlock(title: "Subdomain Intelligence") {
71 if report.subdomainHistory.isEmpty {
72 MessageRowView(text: "No subdomain history available", isError: false)
73 } else {
74 ForEach(report.subdomainHistory.prefix(5)) { item in
75 VStack(alignment: .leading, spacing: 3) {
76 HStack {
77 Text(item.hostname)
78 .font(appDensity.font(.caption))
79 Spacer()
80 if item.isEphemeral {
81 Text("Ephemeral")
82 .font(appDensity.font(.caption2))
83 .foregroundStyle(ThemeToken.warning)
84 }
85 }
86 Text("First \(item.firstSeen.formatted(date: .abbreviated, time: .omitted)) • Last \(item.lastSeen.formatted(date: .abbreviated, time: .omitted)) • Seen \(item.recurrenceCount)x")
87 .font(appDensity.font(.caption2))
88 .foregroundStyle(ThemeToken.textSecondary)
89 }
90 }
91 }
92 }
93 intelligenceBlock(title: "Timeline") {
94 if report.intelligenceTimeline.isEmpty {
95 MessageRowView(text: "No inferred intelligence events yet", isError: false)
96 } else {
97 ForEach(report.intelligenceTimeline.prefix(5)) { event in
98 intelligenceEventRow(date: event.date, title: "\(event.title): \(event.detail)")
99 }
100 }
101 }
102 }
103 }
104 }
105 }
106
107 @ViewBuilder
108 private func intelligenceBlock<Content: View>(title: String, @ViewBuilder content: () -> Content) -> some View {
109 VStack(alignment: .leading, spacing: 8) {
110 Text(title)
111 .font(appDensity.font(.subheadline, weight: .semibold))
112 .foregroundStyle(ThemeToken.info)
113 content()
114 }
115 }
116
117 private func intelligenceEventRow(date: Date, title: String) -> some View {
118 VStack(alignment: .leading, spacing: 3) {
119 Text(date.formatted(date: .abbreviated, time: .omitted))
120 .font(appDensity.font(.caption2))
121 .foregroundStyle(ThemeToken.textSecondary)
122 Text(title)
123 .font(appDensity.font(.caption))
124 }
125 }
126}