DomainDig/ContentView.swift

7b41195620eadd54d25fa98dcd36735cba906ba3
domain-dig/DomainDig/ContentView.swift history · blame · raw

1939 lines · 82408 bytes

   1import MapKit
   2import SwiftUI
   3
   4enum LookupInputMode: String, CaseIterable, Identifiable {
   5    case single
   6    case bulk
   7
   8    var id: String { rawValue }
   9}
  10
  11enum ResultSection: String, Hashable {
  12    case domain
  13    case ownership
  14    case dns
  15    case web
  16    case email
  17    case network
  18    case subdomains
  19}
  20
  21struct ContentView: View {
  22    @Environment(\.appDensity) private var appDensity
  23    @State private var viewModel = DomainViewModel()
  24    @State private var navigationPath = NavigationPath()
  25    @FocusState private var domainFieldFocused: Bool
  26    @State private var customPortInput = ""
  27    @State private var customPortsExpanded = false
  28    @State private var trackingNoteDraft = ""
  29    @State private var editingTrackedDomain: TrackedDomain?
  30    @State private var showTrackLimitAlert = false
  31    @State private var inputMode: LookupInputMode = .single
  32    @State private var collapsedSections: Set<ResultSection> = [.network]
  33
  34    var body: some View {
  35        NavigationStack(path: $navigationPath) {
  36            ScrollView(.vertical) {
  37                VStack(spacing: 0) {
  38                    inputSection
  39                    if !viewModel.batchResults.isEmpty || viewModel.batchLookupRunning {
  40                        batchSection
  41                            .padding(.top, appDensity.metrics.cardSpacing)
  42                    }
  43                    if viewModel.hasRun {
  44                        actionButtons
  45                        if !viewModel.resultsLoaded {
  46                            LookupProgressOverviewView(steps: viewModel.activeLoadingLabels)
  47                                .padding(.top, appDensity.metrics.cardSpacing)
  48                        } else if let statusMessage = resultStatusMessage {
  49                            LookupStatusBannerView(message: statusMessage, resultSource: viewModel.currentResultSource)
  50                                .padding(.top, appDensity.metrics.cardSpacing)
  51                        }
  52                        if viewModel.resultsLoaded {
  53                            SummaryView(fields: viewModel.summaryFields)
  54                                .padding(.top, appDensity.metrics.cardSpacing)
  55                            if let changeSummary = viewModel.currentChangeSummary {
  56                                DomainChangeSummaryView(summary: changeSummary)
  57                                    .padding(.top, appDensity.metrics.cardSpacing)
  58                            }
  59                        }
  60                        DomainSectionView(
  61                            isCollapsed: sectionCollapsedBinding(.domain),
  62                            rows: viewModel.domainRows,
  63                            suggestions: viewModel.suggestionRows,
  64                            showSuggestions: viewModel.availabilityResult?.status == .registered || viewModel.suggestionsLoading,
  65                            availabilityLoading: viewModel.availabilityLoading,
  66                            suggestionsLoading: viewModel.suggestionsLoading,
  67                            provenance: viewModel.currentSnapshot.provenanceBySection[.availability],
  68                            confidence: viewModel.currentSnapshot.availabilityConfidence,
  69                            snapshotNote: viewModel.currentSnapshot.note,
  70                            trackedDomain: viewModel.currentTrackedDomain,
  71                            trackingLimitMessage: viewModel.trackingLimitMessage,
  72                            onTrack: {
  73                                if !viewModel.trackCurrentDomain() {
  74                                    showTrackLimitAlert = true
  75                                }
  76                            },
  77                            onTogglePinned: {
  78                                guard let trackedDomain = viewModel.currentTrackedDomain else { return }
  79                                viewModel.togglePinned(for: trackedDomain)
  80                            },
  81                            onEditNote: {
  82                                guard let trackedDomain = viewModel.currentTrackedDomain else { return }
  83                                trackingNoteDraft = trackedDomain.note ?? ""
  84                                editingTrackedDomain = trackedDomain
  85                            }
  86                        )
  87                            .padding(.top, appDensity.metrics.sectionSpacing)
  88                        OwnershipSectionView(
  89                            isCollapsed: sectionCollapsedBinding(.ownership),
  90                            rows: viewModel.ownershipRows,
  91                            loading: viewModel.ownershipLoading,
  92                            error: viewModel.ownershipError,
  93                            provenance: viewModel.currentSnapshot.provenanceBySection[.ownership],
  94                            confidence: viewModel.currentSnapshot.ownershipConfidence,
  95                            showsHistoryPlaceholder: !DataAccessService.hasAccess(to: .ownershipHistory)
  96                        )
  97                        .padding(.top, appDensity.metrics.sectionSpacing)
  98                        SubdomainsSectionView(
  99                            isCollapsed: sectionCollapsedBinding(.subdomains),
 100                            rows: viewModel.subdomainRows,
 101                            loading: viewModel.subdomainsLoading,
 102                            error: viewModel.subdomainsError,
 103                            provenance: viewModel.currentSnapshot.provenanceBySection[.subdomains],
 104                            confidence: viewModel.currentSnapshot.subdomainConfidence,
 105                            showsExtendedPlaceholder: !DataAccessService.hasAccess(to: .extendedSubdomains)
 106                        )
 107                        .padding(.top, appDensity.metrics.sectionSpacing)
 108                        if !viewModel.currentDiffSections.isEmpty {
 109                            DomainDiffView(
 110                                title: "Latest Changes",
 111                                sections: viewModel.currentDiffSections,
 112                                contextNote: viewModel.currentChangeSummary?.contextNote,
 113                                showsUnchanged: false
 114                            )
 115                            .padding(.top, appDensity.metrics.sectionSpacing)
 116                        }
 117                        DNSSectionView(
 118                            isCollapsed: sectionCollapsedBinding(.dns),
 119                            dnssecLabel: viewModel.dnssecLabel,
 120                            sections: viewModel.dnsRows,
 121                            ptrMessage: viewModel.ptrMessage,
 122                            loading: viewModel.dnsLoading || viewModel.ptrLoading,
 123                            dnsProvenance: viewModel.currentSnapshot.provenanceBySection[.dns],
 124                            ptrProvenance: viewModel.currentSnapshot.provenanceBySection[.ptr],
 125                            sectionError: viewModel.dnsError
 126                        )
 127                        .padding(.top, appDensity.metrics.sectionSpacing)
 128                        WebSectionView(
 129                            isCollapsed: sectionCollapsedBinding(.web),
 130                            certificateRows: viewModel.webCertificateRows,
 131                            sslInfo: viewModel.sslInfo,
 132                            sslLoading: viewModel.sslLoading || viewModel.hstsLoading,
 133                            sslError: viewModel.sslError,
 134                            tlsProvenance: viewModel.currentSnapshot.provenanceBySection[.ssl],
 135                            responseRows: viewModel.webResponseRows,
 136                            headers: viewModel.httpHeaders,
 137                            headersLoading: viewModel.httpHeadersLoading,
 138                            headersError: viewModel.httpHeadersError,
 139                            httpProvenance: viewModel.currentSnapshot.provenanceBySection[.httpHeaders],
 140                            redirects: viewModel.redirectRows,
 141                            redirectLoading: viewModel.redirectChainLoading,
 142                            redirectError: viewModel.redirectChainError,
 143                            redirectProvenance: viewModel.currentSnapshot.provenanceBySection[.redirectChain],
 144                            finalURL: viewModel.currentSnapshot.redirectChain.last?.url
 145                        )
 146                        .padding(.top, appDensity.metrics.sectionSpacing)
 147                        EmailSectionView(
 148                            isCollapsed: sectionCollapsedBinding(.email),
 149                            rows: viewModel.emailRows,
 150                            loading: viewModel.emailSecurityLoading,
 151                            provenance: viewModel.currentSnapshot.provenanceBySection[.emailSecurity],
 152                            confidence: viewModel.currentSnapshot.emailSecurityConfidence,
 153                            error: viewModel.emailSecurityError
 154                        )
 155                        .padding(.top, appDensity.metrics.sectionSpacing)
 156                        NetworkSectionView(
 157                            isCollapsed: sectionCollapsedBinding(.network),
 158                            reachabilityRows: viewModel.reachabilityRows,
 159                            reachabilityLoading: viewModel.reachabilityLoading,
 160                            reachabilityError: viewModel.reachabilityError,
 161                            reachabilityProvenance: viewModel.currentSnapshot.provenanceBySection[.reachability],
 162                            locationRows: viewModel.locationRows,
 163                            geolocation: viewModel.ipGeolocation,
 164                            geolocationLoading: viewModel.ipGeolocationLoading,
 165                            geolocationError: viewModel.ipGeolocationError,
 166                            geolocationProvenance: viewModel.currentSnapshot.provenanceBySection[.ipGeolocation],
 167                            geolocationConfidence: viewModel.currentSnapshot.geolocationConfidence,
 168                            standardPortRows: viewModel.standardPortRows,
 169                            customPortRows: viewModel.customPortRows,
 170                            portScanLoading: viewModel.portScanLoading,
 171                            portScanError: viewModel.portScanError,
 172                            portScanProvenance: viewModel.currentSnapshot.provenanceBySection[.portScan],
 173                            customPortScanLoading: viewModel.customPortScanLoading,
 174                            customPortScanError: viewModel.customPortScanError,
 175                            isCloudflareProxied: viewModel.isCloudflareProxied,
 176                            customPortsExpanded: $customPortsExpanded,
 177                            customPortInput: $customPortInput,
 178                            onScanCustomPorts: runCustomPortScan
 179                        )
 180                        .padding(.top, appDensity.metrics.sectionSpacing)
 181                    } else if !viewModel.recentSearches.isEmpty {
 182                        recentSearchesSection
 183                    }
 184                }
 185                .padding(.horizontal)
 186                .padding(.bottom, 32)
 187            }
 188            .background(
 189                LinearGradient(
 190                    colors: [Color.black, Color(.systemGray6).opacity(0.12)],
 191                    startPoint: .top,
 192                    endPoint: .bottom
 193                )
 194            )
 195            .navigationTitle("DomainDig")
 196            .toolbarColorScheme(.dark, for: .navigationBar)
 197            .preferredColorScheme(.dark)
 198            .toolbar {
 199                ToolbarItemGroup(placement: .topBarTrailing) {
 200                    if viewModel.hasRun {
 201                        Button {
 202                            viewModel.reset()
 203                        } label: {
 204                            Image(systemName: "xmark.circle")
 205                                .foregroundStyle(.secondary)
 206                        }
 207                    }
 208                    NavigationLink {
 209                        WatchlistView(viewModel: viewModel)
 210                    } label: {
 211                        Image(systemName: "eye")
 212                            .foregroundStyle(.secondary)
 213                    }
 214                    Menu {
 215                        NavigationLink {
 216                            HistoryView(viewModel: viewModel)
 217                        } label: {
 218                            Label("History", systemImage: "clock.arrow.trianglehead.counterclockwise.rotate.90")
 219                        }
 220
 221                        NavigationLink {
 222                            SavedDomainsView(viewModel: viewModel)
 223                        } label: {
 224                            Label("Saved Domains", systemImage: "bookmark")
 225                        }
 226
 227                        NavigationLink {
 228                            SettingsView(viewModel: viewModel)
 229                        } label: {
 230                            Label("Settings", systemImage: "gearshape")
 231                        }
 232                    } label: {
 233                        Image(systemName: "ellipsis.circle")
 234                            .foregroundStyle(.secondary)
 235                    }
 236                }
 237            }
 238        }
 239        .onAppear {
 240            domainFieldFocused = true
 241        }
 242        .onChange(of: viewModel.searchedDomain) { _, _ in
 243            collapsedSections = defaultCollapsedSections
 244        }
 245        .onChange(of: viewModel.rerunNavigationToken) { _, _ in
 246            navigationPath = NavigationPath()
 247            domainFieldFocused = false
 248        }
 249        .alert("Tracking limit reached", isPresented: $showTrackLimitAlert) {
 250            Button("OK", role: .cancel) {}
 251        } message: {
 252            Text("Free version supports up to 3 tracked domains. More tracked domains will be available in a future Pro upgrade.")
 253        }
 254        .sheet(item: $editingTrackedDomain) { trackedDomain in
 255            NavigationStack {
 256                Form {
 257                    Section("Tracking Note") {
 258                        TextField("Optional note", text: $trackingNoteDraft, axis: .vertical)
 259                            .lineLimit(3...6)
 260                            .textInputAutocapitalization(.never)
 261                            .autocorrectionDisabled()
 262                    }
 263                }
 264                .navigationTitle(trackedDomain.domain)
 265                .toolbar {
 266                    ToolbarItem(placement: .cancellationAction) {
 267                        Button("Cancel") {
 268                            editingTrackedDomain = nil
 269                        }
 270                    }
 271                    ToolbarItem(placement: .confirmationAction) {
 272                        Button("Save") {
 273                            viewModel.updateNote(trackingNoteDraft, for: trackedDomain)
 274                            editingTrackedDomain = nil
 275                        }
 276                    }
 277                }
 278            }
 279        }
 280    }
 281
 282    private var inputSection: some View {
 283        VStack(spacing: appDensity.metrics.cardSpacing + 2) {
 284            Picker("Mode", selection: $inputMode) {
 285                Text("Single").tag(LookupInputMode.single)
 286                Text("Bulk").tag(LookupInputMode.bulk)
 287            }
 288            .pickerStyle(.segmented)
 289
 290            if inputMode == .single {
 291                TextField("e.g. cleberg.net", text: $viewModel.domain)
 292                    .font(appDensity.font(.title3, design: .monospaced))
 293                    .textInputAutocapitalization(.never)
 294                    .autocorrectionDisabled()
 295                    .keyboardType(.URL)
 296                    .padding(.horizontal, 12)
 297                    .padding(.vertical, appDensity.metrics.controlVerticalPadding)
 298                    .background(Color(.systemGray6))
 299                    .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius))
 300                    .focused($domainFieldFocused)
 301                    .onSubmit { viewModel.run() }
 302
 303                Button {
 304                    domainFieldFocused = false
 305                    viewModel.run()
 306                } label: {
 307                    Text("Run")
 308                        .font(appDensity.font(.headline, design: .default, weight: .semibold))
 309                        .frame(maxWidth: .infinity)
 310                        .frame(minHeight: appDensity.metrics.controlMinHeight)
 311                }
 312                .buttonStyle(.borderedProminent)
 313                .disabled(viewModel.trimmedDomain.isEmpty)
 314            } else {
 315                VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) {
 316                    Text("Paste domains separated by new lines or commas.")
 317                        .font(appDensity.font(.caption))
 318                        .foregroundStyle(.secondary)
 319
 320                    TextField(
 321                        "example.com\napple.com, openai.com",
 322                        text: $viewModel.bulkInput,
 323                        axis: .vertical
 324                    )
 325                    .font(appDensity.font(.body))
 326                    .textInputAutocapitalization(.never)
 327                    .autocorrectionDisabled()
 328                    .keyboardType(.URL)
 329                    .lineLimit(4...10)
 330                    .padding(.horizontal, 12)
 331                    .padding(.vertical, appDensity.metrics.controlVerticalPadding)
 332                    .background(Color(.systemGray6))
 333                    .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius))
 334
 335                    Button {
 336                        domainFieldFocused = false
 337                        viewModel.runBulkLookup()
 338                    } label: {
 339                        Text(viewModel.batchLookupRunning ? "Running Batch…" : "Run Batch")
 340                            .font(appDensity.font(.headline, design: .default, weight: .semibold))
 341                            .frame(maxWidth: .infinity)
 342                            .frame(minHeight: appDensity.metrics.controlMinHeight)
 343                    }
 344                    .buttonStyle(.borderedProminent)
 345                    .disabled(viewModel.bulkInput.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || viewModel.batchLookupRunning)
 346                }
 347            }
 348        }
 349        .padding(.vertical, appDensity.metrics.sectionSpacing)
 350    }
 351
 352    private var actionButtons: some View {
 353        HStack {
 354            Spacer()
 355            if viewModel.resultsLoaded {
 356                Button {
 357                    viewModel.toggleSavedDomain()
 358                } label: {
 359                    Image(systemName: viewModel.isCurrentDomainSaved ? "bookmark.fill" : "bookmark")
 360                        .font(appDensity.font(.body, design: .default))
 361                        .foregroundStyle(viewModel.isCurrentDomainSaved ? .yellow : .secondary)
 362                }
 363                Menu {
 364                    Button("Export TXT") {
 365                        shareSingleResults(format: .text)
 366                    }
 367                    Button("Export CSV") {
 368                        shareSingleResults(format: .csv)
 369                    }
 370                    Button("Export JSON") {
 371                        shareSingleResults(format: .json)
 372                    }
 373                } label: {
 374                    Image(systemName: "square.and.arrow.up")
 375                        .font(appDensity.font(.body, design: .default))
 376                        .foregroundStyle(.secondary)
 377                }
 378            }
 379        }
 380    }
 381
 382    private var batchSection: some View {
 383        VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) {
 384            HStack {
 385                Spacer()
 386                if viewModel.batchLookupRunning {
 387                    Button("Cancel") {
 388                        viewModel.cancelBatchLookup()
 389                    }
 390                    .buttonStyle(.bordered)
 391                    .font(appDensity.font(.caption))
 392                }
 393                if !viewModel.currentBatchResultEntries.isEmpty {
 394                    Menu {
 395                        Button("Export Batch TXT") {
 396                            shareBatchResults(format: .text)
 397                        }
 398                        Button("Export Batch CSV") {
 399                            shareBatchResults(format: .csv)
 400                        }
 401                        Button("Export Batch JSON") {
 402                            shareBatchResults(format: .json)
 403                        }
 404                    } label: {
 405                        Label("Export", systemImage: "square.and.arrow.up")
 406                            .font(appDensity.font(.caption))
 407                    }
 408                    .buttonStyle(.bordered)
 409                }
 410            }
 411
 412            BatchResultsView(
 413                viewModel: viewModel,
 414                title: viewModel.batchLookupSource == .watchlistRefresh ? "Tracked Domain Refresh" : "Batch Results"
 415            )
 416        }
 417    }
 418
 419    private var recentSearchesSection: some View {
 420        VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) {
 421            HStack {
 422                Text("RECENT")
 423                    .font(appDensity.font(.caption2))
 424                    .foregroundStyle(.secondary)
 425                Spacer()
 426                Button("Clear") {
 427                    viewModel.clearRecentSearches()
 428                }
 429                .font(appDensity.font(.caption2))
 430                .foregroundStyle(.secondary)
 431            }
 432
 433            ForEach(viewModel.recentSearches, id: \.self) { domain in
 434                Button {
 435                    viewModel.domain = domain
 436                    domainFieldFocused = false
 437                    viewModel.run()
 438                } label: {
 439                    Text(domain)
 440                        .font(appDensity.font(.callout))
 441                        .foregroundStyle(.primary)
 442                        .frame(maxWidth: .infinity, alignment: .leading)
 443                        .padding(.vertical, 8)
 444                        .padding(.horizontal, 10)
 445                        .background(Color(.systemGray6).opacity(0.5))
 446                        .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius))
 447                }
 448            }
 449        }
 450        .padding(.top, appDensity.metrics.cardSpacing)
 451    }
 452
 453    private func runCustomPortScan() {
 454        let ports = parsedCustomPorts(from: customPortInput)
 455        Task {
 456            await viewModel.runCustomPortScan(ports: ports)
 457        }
 458    }
 459
 460    private func parsedCustomPorts(from input: String) -> [UInt16] {
 461        let parts = input.split(separator: ",", omittingEmptySubsequences: true)
 462        var seen = Set<UInt16>()
 463        var ports: [UInt16] = []
 464
 465        for part in parts {
 466            let trimmed = part.trimmingCharacters(in: .whitespacesAndNewlines)
 467            guard let value = UInt16(trimmed), seen.insert(value).inserted else {
 468                continue
 469            }
 470            ports.append(value)
 471            if ports.count == 20 {
 472                break
 473            }
 474        }
 475
 476        return ports
 477    }
 478
 479    private func shareSingleResults(format: DomainExportFormat) {
 480        let (filename, data) = exportPayload(
 481            prefix: "domaindig_single",
 482            format: format,
 483            text: viewModel.exportText(),
 484            csv: viewModel.exportCSV(),
 485            json: viewModel.exportJSONData()
 486        )
 487        ExportPresenter.share(filename: filename, data: data)
 488    }
 489
 490    private func shareBatchResults(format: DomainExportFormat) {
 491        let (filename, data) = exportPayload(
 492            prefix: "domaindig_batch",
 493            format: format,
 494            text: viewModel.exportBatchText(),
 495            csv: viewModel.exportBatchCSV(),
 496            json: viewModel.exportBatchJSONData()
 497        )
 498        ExportPresenter.share(filename: filename, data: data)
 499    }
 500
 501    private func exportPayload(
 502        prefix: String,
 503        format: DomainExportFormat,
 504        text: String,
 505        csv: String,
 506        json: Data?
 507    ) -> (String, Data) {
 508        let formatter = DateFormatter()
 509        formatter.dateFormat = "yyyyMMdd_HHmmss"
 510        let timestamp = formatter.string(from: Date())
 511        let filename = "\(timestamp)_\(prefix).\(format.fileExtension)"
 512        let data: Data
 513
 514        switch format {
 515        case .text:
 516            data = Data(text.utf8)
 517        case .csv:
 518            data = Data(csv.utf8)
 519        case .json:
 520            data = json ?? Data("[]".utf8)
 521        }
 522
 523        return (filename, data)
 524    }
 525
 526    private var defaultCollapsedSections: Set<ResultSection> {
 527        []
 528    }
 529
 530    private var currentPrimaryIP: String? {
 531        viewModel.currentSnapshot.dnsSections.first(where: { $0.recordType == .A })?.records.first?.value
 532    }
 533
 534    private var resultStatusMessage: String? {
 535        if let currentStatusMessage = viewModel.currentStatusMessage {
 536            return currentStatusMessage
 537        }
 538
 539        if viewModel.currentResultSource != .live {
 540            return viewModel.currentResultSource.label
 541        }
 542
 543        return nil
 544    }
 545
 546    private func sectionCollapsedBinding(_ section: ResultSection) -> Binding<Bool> {
 547        Binding(
 548            get: { collapsedSections.contains(section) },
 549            set: { isCollapsed in
 550                if isCollapsed {
 551                    collapsedSections.insert(section)
 552                } else {
 553                    collapsedSections.remove(section)
 554                }
 555            }
 556        )
 557    }
 558}
 559
 560struct SummaryView: View {
 561    @Environment(\.appDensity) private var appDensity
 562    let fields: [SummaryFieldViewData]
 563
 564    var body: some View {
 565        VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) {
 566            SectionTitleView(title: "Summary")
 567            LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())], spacing: appDensity.metrics.cardSpacing) {
 568                ForEach(fields) { field in
 569                    VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing) {
 570                        Text(field.label)
 571                            .font(appDensity.font(.caption2))
 572                            .foregroundStyle(.secondary)
 573                        Text(field.value)
 574                            .font(appDensity.font(.caption))
 575                            .foregroundStyle(ResultColors.color(for: field.tone))
 576                            .lineLimit(2)
 577                            .textSelection(.enabled)
 578                    }
 579                    .frame(minHeight: appDensity.metrics.rowMinHeight + 12, alignment: .topLeading)
 580                    .frame(maxWidth: .infinity, alignment: .leading)
 581                    .padding(appDensity.metrics.cardPadding)
 582                    .background(Color(.systemGray6).opacity(0.5))
 583                    .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius))
 584                }
 585            }
 586        }
 587    }
 588}
 589
 590struct StickyLookupSummaryView: View {
 591    @Environment(\.appDensity) private var appDensity
 592
 593    let domain: String
 594    let availability: DomainAvailabilityStatus?
 595    let primaryIP: String?
 596    let sslInfo: SSLCertificateInfo?
 597    let sslError: String?
 598    let emailSecurity: EmailSecurityResult?
 599    let emailError: String?
 600    let changeSummary: DomainChangeSummary?
 601
 602    var body: some View {
 603        CardView(allowsHorizontalScroll: false) {
 604            VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) {
 605                HStack(alignment: .center, spacing: 10) {
 606                    Text(domain)
 607                        .font(appDensity.font(.headline, weight: .semibold))
 608                        .foregroundStyle(.primary)
 609                        .lineLimit(1)
 610                    Spacer(minLength: 6)
 611                    AppCopyButton(value: domain, label: "Copy domain")
 612                }
 613
 614                ScrollView(.horizontal, showsIndicators: false) {
 615                    HStack(spacing: 8) {
 616                        AppStatusBadgeView(model: AppStatusFactory.availability(availability))
 617                        AppStatusBadgeView(model: AppStatusFactory.tls(sslInfo: sslInfo, error: sslError))
 618                        AppStatusBadgeView(model: AppStatusFactory.email(emailSecurity, error: emailError))
 619                        AppStatusBadgeView(model: AppStatusFactory.change(changeSummary))
 620                    }
 621                }
 622
 623                if let primaryIP {
 624                    HStack(spacing: 8) {
 625                        Label(primaryIP, systemImage: "network")
 626                            .font(appDensity.font(.caption))
 627                            .foregroundStyle(.secondary)
 628                        Spacer(minLength: 6)
 629                        AppCopyButton(value: primaryIP, label: "Copy IP")
 630                    }
 631                }
 632            }
 633        }
 634        .shadow(color: .black.opacity(0.12), radius: 14, y: 6)
 635    }
 636}
 637
 638struct LookupProgressOverviewView: View {
 639    @Environment(\.appDensity) private var appDensity
 640    let steps: [String]
 641
 642    var body: some View {
 643        CardView(allowsHorizontalScroll: false) {
 644            HStack(spacing: 8) {
 645                ProgressView()
 646                    .controlSize(.small)
 647                VStack(alignment: .leading, spacing: 4) {
 648                    Text("Running lookup…")
 649                        .font(appDensity.font(.caption))
 650                        .foregroundStyle(.primary)
 651                    Text(steps.isEmpty ? "Preparing requests" : steps.joined(separator: " • "))
 652                        .font(appDensity.font(.caption2))
 653                        .foregroundStyle(.secondary)
 654                }
 655                Spacer()
 656            }
 657        }
 658    }
 659}
 660
 661struct LookupStatusBannerView: View {
 662    @Environment(\.appDensity) private var appDensity
 663    let message: String
 664    let resultSource: LookupResultSource
 665
 666    var body: some View {
 667        HStack(spacing: 8) {
 668            Image(systemName: iconName)
 669                .font(.caption)
 670            Text(message)
 671                .font(appDensity.font(.caption))
 672            Spacer()
 673        }
 674        .foregroundStyle(color)
 675        .padding(appDensity.metrics.cardPadding - 2)
 676        .frame(maxWidth: .infinity, alignment: .leading)
 677        .background(color.opacity(0.12))
 678        .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius))
 679    }
 680
 681    private var color: Color {
 682        switch resultSource {
 683        case .live:
 684            return .green
 685        case .cached:
 686            return .secondary
 687        case .mixed:
 688            return .yellow
 689        case .snapshot:
 690            return .orange
 691        }
 692    }
 693
 694    private var iconName: String {
 695        switch resultSource {
 696        case .live:
 697            return "bolt.horizontal"
 698        case .cached:
 699            return "clock.arrow.trianglehead.counterclockwise.rotate.90"
 700        case .mixed:
 701            return "arrow.triangle.branch"
 702        case .snapshot:
 703            return "archivebox"
 704        }
 705    }
 706}
 707
 708struct DomainChangeSummaryView: View {
 709    @Environment(\.appDensity) private var appDensity
 710    let summary: DomainChangeSummary
 711    @State private var showsDetails = false
 712
 713    var body: some View {
 714        CardView(allowsHorizontalScroll: false) {
 715            HStack {
 716                Label(summary.hasChanges ? "Changed" : "Stable", systemImage: summary.hasChanges ? "arrow.triangle.2.circlepath" : "checkmark.circle")
 717                    .font(appDensity.font(.caption))
 718                    .foregroundStyle(summary.hasChanges ? severityColor(summary.severity) : .green)
 719                Spacer()
 720                Text(summary.severity.title.uppercased())
 721                    .font(appDensity.font(.caption2))
 722                    .foregroundStyle(summary.hasChanges ? severityColor(summary.severity) : .secondary)
 723                    .padding(.horizontal, 8)
 724                    .padding(.vertical, 4)
 725                    .background((summary.hasChanges ? severityColor(summary.severity) : .secondary).opacity(0.16))
 726                    .clipShape(Capsule())
 727                Text(summary.generatedAt, style: .time)
 728                    .font(appDensity.font(.caption2))
 729                    .foregroundStyle(.secondary)
 730            }
 731
 732            VStack(alignment: .leading, spacing: 4) {
 733                Text("Inference")
 734                    .font(appDensity.font(.caption2))
 735                    .foregroundStyle(.secondary)
 736                Text(summary.message)
 737                    .font(appDensity.font(.caption))
 738                    .foregroundStyle(.primary)
 739                    .lineLimit(2)
 740            }
 741
 742            if !summary.observedFacts.isEmpty || summary.contextNote != nil {
 743                DisclosureGroup(showsDetails ? "Hide Details" : "Show Details", isExpanded: $showsDetails) {
 744                    VStack(alignment: .leading, spacing: 8) {
 745                        if !summary.observedFacts.isEmpty {
 746                            VStack(alignment: .leading, spacing: 4) {
 747                                Text("Observed")
 748                                    .font(appDensity.font(.caption2))
 749                                    .foregroundStyle(.secondary)
 750                                ForEach(Array(summary.observedFacts.enumerated()), id: \.offset) { _, fact in
 751                                    Text(fact)
 752                                        .font(appDensity.font(.caption))
 753                                        .foregroundStyle(.primary)
 754                                }
 755                            }
 756                        }
 757
 758                        if let contextNote = summary.contextNote {
 759                            Text(contextNote)
 760                                .font(appDensity.font(.caption2))
 761                                .foregroundStyle(.orange)
 762                        }
 763                    }
 764                    .padding(.top, 4)
 765                }
 766                .font(appDensity.font(.caption))
 767                .tint(.secondary)
 768            }
 769        }
 770    }
 771
 772    private func severityColor(_ severity: ChangeSeverity) -> Color {
 773        switch severity {
 774        case .low:
 775            return .secondary
 776        case .medium:
 777            return .yellow
 778        case .high:
 779            return .red
 780        }
 781    }
 782}
 783
 784struct DomainDiffView: View {
 785    let title: String
 786    let sections: [DomainDiffSection]
 787    let contextNote: String?
 788    let showsUnchanged: Bool
 789
 790    @State private var collapsedSections = Set<UUID>()
 791    @State private var showsLowSeverity = false
 792
 793    private var filteredSections: [DomainDiffSection] {
 794        sections
 795            .map { section in
 796                let items = section.items.filter { item in
 797                    if !showsUnchanged, !item.hasChanges {
 798                        return false
 799                    }
 800                    if showsLowSeverity {
 801                        return true
 802                    }
 803                    return item.severity >= .medium || (showsUnchanged && item.changeType == .unchanged)
 804                }
 805                return DomainDiffSection(title: section.title, items: items)
 806            }
 807            .filter { !$0.items.isEmpty }
 808    }
 809
 810    private var hasLowSeverityChanges: Bool {
 811        sections.flatMap(\.items).contains { $0.hasChanges && $0.severity == .low }
 812    }
 813
 814    var body: some View {
 815        VStack(alignment: .leading, spacing: 12) {
 816            HStack {
 817                SectionTitleView(title: title)
 818                Spacer()
 819                if hasLowSeverityChanges {
 820                    Button(showsLowSeverity ? "Hide Low" : "Show Low") {
 821                        showsLowSeverity.toggle()
 822                    }
 823                    .buttonStyle(.bordered)
 824                    .font(.system(.caption, design: .monospaced))
 825                }
 826            }
 827            if let contextNote {
 828                MessageCardView(text: contextNote, isError: false)
 829            }
 830            if filteredSections.isEmpty {
 831                MessageCardView(text: "No comparison data available", isError: false)
 832            } else {
 833                ForEach(filteredSections) { section in
 834                    CardView(allowsHorizontalScroll: false) {
 835                        DisclosureGroup(isExpanded: binding(for: section)) {
 836                            let visibleItems = showsUnchanged ? section.items : section.items.filter(\.hasChanges)
 837
 838                            ForEach(visibleItems) { item in
 839                                VStack(alignment: .leading, spacing: 6) {
 840                                    HStack {
 841                                        Text(item.label)
 842                                            .font(.system(.caption, design: .monospaced))
 843                                            .foregroundStyle(.secondary)
 844                                        Spacer()
 845                                        Text("\(item.severity.title) • \(changeLabel(for: item.changeType))")
 846                                            .font(.system(.caption2, design: .monospaced))
 847                                            .foregroundStyle(changeColor(for: item))
 848                                            .padding(.horizontal, 8)
 849                                            .padding(.vertical, 4)
 850                                            .background(changeColor(for: item).opacity(0.16))
 851                                            .clipShape(Capsule())
 852                                    }
 853
 854                                    if let oldValue = item.oldValue {
 855                                        VStack(alignment: .leading, spacing: 2) {
 856                                            Text("Old")
 857                                                .font(.system(.caption2, design: .monospaced))
 858                                                .foregroundStyle(.secondary)
 859                                            Text(oldValue)
 860                                                .font(.system(.caption2, design: .monospaced))
 861                                                .foregroundStyle(.secondary)
 862                                                .textSelection(.enabled)
 863                                        }
 864                                    }
 865
 866                                    if let newValue = item.newValue {
 867                                        VStack(alignment: .leading, spacing: 2) {
 868                                            Text("New")
 869                                                .font(.system(.caption2, design: .monospaced))
 870                                                .foregroundStyle(.secondary)
 871                                            Text(newValue)
 872                                                .font(.system(.caption, design: .monospaced))
 873                                                .foregroundStyle(item.hasChanges ? .primary : .secondary)
 874                                                .textSelection(.enabled)
 875                                        }
 876                                    }
 877                                }
 878                                .padding(10)
 879                                .background(item.hasChanges ? changeColor(for: item).opacity(0.08) : Color(.systemGray6).opacity(0.25))
 880                                .cornerRadius(8)
 881                            }
 882                        } label: {
 883                            HStack {
 884                                Text(section.title)
 885                                    .font(.system(.subheadline, design: .monospaced))
 886                                    .fontWeight(.semibold)
 887                                    .foregroundStyle(sectionColor(section))
 888                                Spacer()
 889                                Text(section.severity.title)
 890                                    .font(.system(.caption2, design: .monospaced))
 891                                    .foregroundStyle(sectionColor(section))
 892                            }
 893                        }
 894                    }
 895                }
 896            }
 897        }
 898    }
 899
 900    private func changeLabel(for changeType: DiffChangeType) -> String {
 901        switch changeType {
 902        case .added:
 903            return "Added"
 904        case .removed:
 905            return "Removed"
 906        case .changed:
 907            return "Changed"
 908        case .unchanged:
 909            return "Unchanged"
 910        }
 911    }
 912
 913    private func changeColor(for item: DomainDiffItem) -> Color {
 914        if item.changeType == .unchanged {
 915            return .secondary
 916        }
 917
 918        switch item.severity {
 919        case .low:
 920            return .blue
 921        case .medium:
 922            return .yellow
 923        case .high:
 924            return .red
 925        }
 926    }
 927
 928    private func sectionColor(_ section: DomainDiffSection) -> Color {
 929        switch section.severity {
 930        case .low:
 931            return .blue
 932        case .medium:
 933            return .yellow
 934        case .high:
 935            return .red
 936        }
 937    }
 938
 939    private func binding(for section: DomainDiffSection) -> Binding<Bool> {
 940        Binding(
 941            get: { !collapsedSections.contains(section.id) },
 942            set: { isExpanded in
 943                if isExpanded {
 944                    collapsedSections.remove(section.id)
 945                } else {
 946                    collapsedSections.insert(section.id)
 947                }
 948            }
 949        )
 950    }
 951}
 952
 953struct TrackedDomainDetailHeaderView: View {
 954    let trackedDomain: TrackedDomain
 955
 956    var body: some View {
 957        VStack(alignment: .leading, spacing: 4) {
 958            if let note = trackedDomain.note?.nilIfEmpty {
 959                LabeledValueRow(row: InfoRowViewData(label: "Tracking Note", value: note, tone: .secondary))
 960            }
 961            HStack(spacing: 8) {
 962                if trackedDomain.isPinned {
 963                    Label("Pinned", systemImage: "pin.fill")
 964                }
 965                Text("Last refresh \(trackedDomain.updatedAt.formatted(date: .abbreviated, time: .shortened))")
 966            }
 967            .font(.system(.caption2, design: .monospaced))
 968            .foregroundStyle(.secondary)
 969        }
 970    }
 971}
 972
 973struct DomainSectionView: View {
 974    @Environment(\.appDensity) private var appDensity
 975    @Binding var isCollapsed: Bool
 976    let rows: [InfoRowViewData]
 977    let suggestions: [DomainSuggestionViewData]
 978    let showSuggestions: Bool
 979    let availabilityLoading: Bool
 980    let suggestionsLoading: Bool
 981    let provenance: SectionProvenance?
 982    let confidence: ConfidenceLevel?
 983    let snapshotNote: String?
 984    let trackedDomain: TrackedDomain?
 985    let trackingLimitMessage: String?
 986    let onTrack: () -> Void
 987    let onTogglePinned: () -> Void
 988    let onEditNote: (() -> Void)?
 989
 990    var body: some View {
 991        CollapsibleSectionView(title: "Domain", isCollapsed: $isCollapsed) {
 992            if let trackedDomain {
 993                HStack(spacing: 8) {
 994                    AppStatusBadgeView(model: .init(title: "Tracked", systemImage: "eye.fill", foregroundColor: .green, backgroundColor: .green.opacity(0.16)))
 995                    Button {
 996                        onTogglePinned()
 997                    } label: {
 998                        Image(systemName: trackedDomain.isPinned ? "pin.fill" : "pin")
 999                    }
1000                    .buttonStyle(.bordered)
1001                    .font(appDensity.font(.caption))
1002                    if let onEditNote {
1003                        Button("Note") {
1004                            onEditNote()
1005                        }
1006                        .buttonStyle(.bordered)
1007                        .font(appDensity.font(.caption))
1008                    }
1009                }
1010            } else {
1011                Button("Track") {
1012                    AppHaptics.track()
1013                    onTrack()
1014                }
1015                .buttonStyle(.bordered)
1016                .font(appDensity.font(.caption))
1017            }
1018        } content: {
1019            CardView(allowsHorizontalScroll: false) {
1020                SectionTrustMetadataView(
1021                    provenance: provenance,
1022                    confidence: confidence,
1023                    note: snapshotNote == nil ? nil : "Audit note present"
1024                )
1025                ForEach(rows) { row in
1026                    LabeledValueRow(row: row)
1027                }
1028                if let trackedDomain {
1029                    TrackedDomainDetailHeaderView(trackedDomain: trackedDomain)
1030                        .padding(.top, 4)
1031                } else if let trackingLimitMessage {
1032                    MessageRowView(text: trackingLimitMessage, isError: false)
1033                        .padding(.top, 4)
1034                }
1035                if availabilityLoading {
1036                    ProgressView("Checking availability…")
1037                        .appLoadingStyle()
1038                        .padding(.top, 4)
1039                }
1040                if showSuggestions {
1041                    Text("Suggestions")
1042                        .font(appDensity.font(.caption))
1043                        .foregroundStyle(.secondary)
1044                        .padding(.top, 4)
1045                    if suggestionsLoading {
1046                        ProgressView("Checking alternatives…")
1047                            .appLoadingStyle()
1048                    } else if suggestions.isEmpty {
1049                        MessageRowView(text: "No suggestions", isError: false)
1050                    } else {
1051                        ForEach(suggestions) { suggestion in
1052                            HStack {
1053                                Text(suggestion.domain)
1054                                    .font(appDensity.font(.caption))
1055                                    .foregroundStyle(.primary)
1056                                    .textSelection(.enabled)
1057                                Spacer()
1058                                AppStatusBadgeView(model: AppStatusFactory.availability(suggestion.availabilityStatus))
1059                            }
1060                        }
1061                    }
1062                }
1063            }
1064        }
1065    }
1066}
1067
1068struct OwnershipSectionView: View {
1069    @Binding var isCollapsed: Bool
1070    let rows: [InfoRowViewData]
1071    let loading: Bool
1072    let error: String?
1073    let provenance: SectionProvenance?
1074    let confidence: ConfidenceLevel?
1075    let showsHistoryPlaceholder: Bool
1076
1077    var body: some View {
1078        CollapsibleSectionView(title: "Ownership", isCollapsed: $isCollapsed) {
1079            CardView(allowsHorizontalScroll: false) {
1080                SectionTrustMetadataView(provenance: provenance, confidence: confidence)
1081                if loading {
1082                    ProgressView("Fetching RDAP ownership…")
1083                        .appLoadingStyle()
1084                } else {
1085                    ForEach(rows) { row in
1086                        LabeledValueRow(row: row)
1087                    }
1088                    if let error, rows.allSatisfy({ $0.value == "Unavailable" }) {
1089                        MessageRowView(text: error, isError: error != "Unavailable")
1090                            .padding(.top, 4)
1091                    }
1092                    if showsHistoryPlaceholder {
1093                        MessageRowView(text: "Ownership history (coming soon)", isError: false)
1094                            .padding(.top, 4)
1095                    }
1096                }
1097            }
1098        }
1099    }
1100}
1101
1102struct SubdomainsSectionView: View {
1103    @Environment(\.appDensity) private var appDensity
1104    @Binding var isCollapsed: Bool
1105    let rows: [SubdomainRowViewData]
1106    let loading: Bool
1107    let error: String?
1108    let provenance: SectionProvenance?
1109    let confidence: ConfidenceLevel?
1110    let showsExtendedPlaceholder: Bool
1111
1112    var body: some View {
1113        CollapsibleSectionView(title: "Subdomains", isCollapsed: $isCollapsed, subtitle: "\(rows.count) found") {
1114            CardView(allowsHorizontalScroll: false) {
1115                SectionTrustMetadataView(provenance: provenance, confidence: confidence)
1116                if loading {
1117                    ProgressView("Checking certificate transparency…")
1118                        .appLoadingStyle()
1119                } else if rows.isEmpty {
1120                    MessageRowView(text: error ?? "No passive subdomains found", isError: false)
1121                    if showsExtendedPlaceholder {
1122                        MessageRowView(text: "Extended subdomain discovery (Data+)", isError: false)
1123                            .padding(.top, 4)
1124                    }
1125                } else {
1126                    ForEach(rows) { row in
1127                        HStack(spacing: 8) {
1128                            Text(row.hostname)
1129                                .font(appDensity.font(.caption))
1130                                .foregroundStyle(.primary)
1131                                .textSelection(.enabled)
1132                            Spacer()
1133                            if row.isInteresting {
1134                                Text("Interesting")
1135                                    .font(.system(.caption2, design: .monospaced))
1136                                    .foregroundStyle(.yellow)
1137                                    .padding(.horizontal, 8)
1138                                    .padding(.vertical, 4)
1139                                    .background(Color.yellow.opacity(0.14))
1140                                    .clipShape(Capsule())
1141                            }
1142                        }
1143                    }
1144                    if showsExtendedPlaceholder {
1145                        MessageRowView(text: "Extended subdomain discovery (Data+)", isError: false)
1146                            .padding(.top, 4)
1147                    }
1148                }
1149            }
1150        }
1151    }
1152}
1153
1154struct DNSSectionView: View {
1155    @Binding var isCollapsed: Bool
1156    let dnssecLabel: String?
1157    let sections: [DNSRecordSectionViewData]
1158    let ptrMessage: SectionMessageViewData?
1159    let loading: Bool
1160    let dnsProvenance: SectionProvenance?
1161    let ptrProvenance: SectionProvenance?
1162    let sectionError: String?
1163
1164    var body: some View {
1165        CollapsibleSectionView(title: "DNS", isCollapsed: $isCollapsed, subtitle: dnssecLabel) {
1166            if loading {
1167                LoadingCardView(text: "Querying DNS…")
1168            } else if let sectionError, sections.isEmpty {
1169                MessageCardView(text: sectionError, isError: true)
1170            } else {
1171                if dnsProvenance != nil {
1172                    CardView(allowsHorizontalScroll: false) {
1173                        SectionTrustMetadataView(provenance: dnsProvenance, confidence: nil)
1174                    }
1175                }
1176                ForEach(sections) { section in
1177                    CardView {
1178                        Text(section.title)
1179                            .font(.system(.subheadline, design: .monospaced))
1180                            .fontWeight(.semibold)
1181                            .foregroundStyle(.cyan)
1182
1183                        if let message = section.message {
1184                            MessageRowView(text: message.text, isError: message.isError)
1185                        }
1186
1187                        ForEach(section.rows) { row in
1188                            LabeledValueRow(row: row)
1189                        }
1190
1191                        if let wildcardTitle = section.wildcardTitle {
1192                            Text(wildcardTitle)
1193                                .font(.system(.caption, design: .monospaced))
1194                                .foregroundStyle(.secondary)
1195                                .padding(.top, 4)
1196                            ForEach(section.wildcardRows) { row in
1197                                LabeledValueRow(row: row)
1198                            }
1199                        }
1200                    }
1201                }
1202
1203                if let ptrMessage {
1204                    CardView {
1205                        Text("PTR")
1206                            .font(.system(.subheadline, design: .monospaced))
1207                            .fontWeight(.semibold)
1208                            .foregroundStyle(.cyan)
1209                        SectionTrustMetadataView(provenance: ptrProvenance, confidence: nil)
1210                        MessageRowView(text: ptrMessage.text, isError: ptrMessage.isError)
1211                    }
1212                }
1213            }
1214        }
1215    }
1216}
1217
1218struct WebSectionView: View {
1219    @Environment(\.appDensity) private var appDensity
1220    @Binding var isCollapsed: Bool
1221    let certificateRows: [InfoRowViewData]
1222    let sslInfo: SSLCertificateInfo?
1223    let sslLoading: Bool
1224    let sslError: String?
1225    let tlsProvenance: SectionProvenance?
1226    let responseRows: [InfoRowViewData]
1227    let headers: [HTTPHeader]
1228    let headersLoading: Bool
1229    let headersError: String?
1230    let httpProvenance: SectionProvenance?
1231    let redirects: [RedirectHopViewData]
1232    let redirectLoading: Bool
1233    let redirectError: String?
1234    let redirectProvenance: SectionProvenance?
1235    let finalURL: String?
1236
1237    var body: some View {
1238        CollapsibleSectionView(title: "Web", isCollapsed: $isCollapsed) {
1239            CardView {
1240                HStack {
1241                    Text("TLS")
1242                        .font(appDensity.font(.subheadline, weight: .semibold))
1243                        .foregroundStyle(.cyan)
1244                    Spacer()
1245                    AppStatusBadgeView(model: AppStatusFactory.tls(sslInfo: sslInfo, error: sslError))
1246                }
1247                SectionTrustMetadataView(provenance: tlsProvenance, confidence: nil)
1248                if sslLoading {
1249                    ProgressView("Checking certificate…")
1250                        .appLoadingStyle()
1251                } else if let sslError {
1252                    MessageRowView(text: sslError, isError: true)
1253                } else {
1254                    ForEach(certificateRows) { row in
1255                        LabeledValueRow(row: row)
1256                    }
1257                    if let sslInfo, !sslInfo.subjectAltNames.isEmpty {
1258                        Text("SANs")
1259                            .font(appDensity.font(.caption2))
1260                            .foregroundStyle(.secondary)
1261                        ForEach(sslInfo.subjectAltNames, id: \.self) { san in
1262                            HStack(spacing: 8) {
1263                                Text(san)
1264                                    .font(appDensity.font(.caption))
1265                                    .textSelection(.enabled)
1266                                Spacer()
1267                                AppCopyButton(value: san, label: "Copy certificate SAN")
1268                            }
1269                        }
1270                    }
1271                }
1272            }
1273
1274            CardView {
1275                Text("Headers")
1276                    .font(appDensity.font(.subheadline, weight: .semibold))
1277                    .foregroundStyle(.cyan)
1278                SectionTrustMetadataView(provenance: httpProvenance, confidence: nil)
1279                if headersLoading {
1280                    ProgressView("Fetching headers…")
1281                        .appLoadingStyle()
1282                } else if let headersError {
1283                    MessageRowView(text: headersError, isError: true)
1284                } else {
1285                    ForEach(responseRows) { row in
1286                        LabeledValueRow(row: row)
1287                    }
1288                    if headers.isEmpty {
1289                        MessageRowView(text: "No HTTP headers returned", isError: false)
1290                    } else {
1291                        ForEach(headers) { header in
1292                            HStack(alignment: .top, spacing: 4) {
1293                                Text(header.name + ":")
1294                                    .font(appDensity.font(.caption))
1295                                    .foregroundStyle(header.isSecurityHeader ? .yellow : .cyan)
1296                                Text(header.value)
1297                                    .font(appDensity.font(.caption))
1298                                    .foregroundStyle(.primary)
1299                                    .textSelection(.enabled)
1300                            }
1301                        }
1302                    }
1303                }
1304            }
1305
1306            CardView {
1307                HStack {
1308                    Text("Redirects")
1309                        .font(appDensity.font(.subheadline, weight: .semibold))
1310                        .foregroundStyle(.cyan)
1311                    Spacer()
1312                    if let finalURL {
1313                        AppCopyButton(value: finalURL, label: "Copy redirect URL")
1314                    }
1315                }
1316                SectionTrustMetadataView(provenance: redirectProvenance, confidence: nil)
1317                if redirectLoading {
1318                    ProgressView("Tracing redirects…")
1319                        .appLoadingStyle()
1320                } else if let redirectError {
1321                    MessageRowView(text: redirectError, isError: true)
1322                } else if redirects.isEmpty {
1323                    MessageRowView(text: "No redirect data available", isError: false)
1324                } else {
1325                    if let finalURL {
1326                        LabeledValueRow(row: InfoRowViewData(label: "Final URL", value: finalURL, tone: .secondary))
1327                    }
1328                    ForEach(redirects) { redirect in
1329                        HStack(alignment: .top, spacing: 6) {
1330                            Text(redirect.stepLabel)
1331                                .font(appDensity.font(.caption))
1332                                .foregroundStyle(.secondary)
1333                                .frame(width: 16, alignment: .trailing)
1334                            Text(redirect.statusCode)
1335                                .font(appDensity.font(.caption))
1336                                .foregroundStyle(.cyan)
1337                                .frame(width: 36, alignment: .leading)
1338                            Text(redirect.url)
1339                                .font(appDensity.font(.caption))
1340                                .textSelection(.enabled)
1341                            AppCopyButton(value: redirect.url, label: "Copy redirect URL")
1342                            if redirect.isFinal {
1343                                Text("(final)")
1344                                    .font(appDensity.font(.caption2))
1345                                    .foregroundStyle(.secondary)
1346                            }
1347                        }
1348                    }
1349                }
1350            }
1351        }
1352    }
1353}
1354
1355struct EmailSectionView: View {
1356    @Environment(\.appDensity) private var appDensity
1357    @Binding var isCollapsed: Bool
1358    let rows: [EmailRowViewData]
1359    let loading: Bool
1360    let provenance: SectionProvenance?
1361    let confidence: ConfidenceLevel?
1362    let error: String?
1363
1364    var body: some View {
1365        CollapsibleSectionView(title: "Email", isCollapsed: $isCollapsed) {
1366            CardView {
1367                SectionTrustMetadataView(provenance: provenance, confidence: confidence)
1368                HStack {
1369                    Spacer()
1370                    AppStatusBadgeView(model: AppStatusFactory.email(nil, error: error))
1371                        .opacity(loading ? 0 : 1)
1372                }
1373                if loading {
1374                    ProgressView("Checking email records…")
1375                        .appLoadingStyle()
1376                } else if let error {
1377                    MessageRowView(text: error, isError: true)
1378                } else if rows.isEmpty {
1379                    MessageRowView(text: "No email security records found", isError: false)
1380                } else {
1381                    ForEach(rows) { row in
1382                        VStack(alignment: .leading, spacing: 4) {
1383                            HStack(spacing: 8) {
1384                                Text(row.label)
1385                                    .font(appDensity.font(.caption))
1386                                    .foregroundStyle(.cyan)
1387                                    .frame(width: 76, alignment: .leading)
1388                                AppStatusBadgeView(model: emailRowBadge(row))
1389                            }
1390                            Text(row.detail)
1391                                .font(appDensity.font(.caption2))
1392                                .foregroundStyle(.primary)
1393                                .textSelection(.enabled)
1394                            if let auxiliaryDetail = row.auxiliaryDetail {
1395                                Text(auxiliaryDetail)
1396                                    .font(appDensity.font(.caption2))
1397                                    .foregroundStyle(.secondary)
1398                            }
1399                        }
1400                    }
1401                }
1402            }
1403        }
1404    }
1405
1406    private func emailRowBadge(_ row: EmailRowViewData) -> AppStatusBadgeModel {
1407        switch row.statusTone {
1408        case .success:
1409            return .init(title: row.status, systemImage: "checkmark.shield.fill", foregroundColor: .green, backgroundColor: .green.opacity(0.16))
1410        case .warning:
1411            return .init(title: row.status, systemImage: "shield.lefthalf.filled", foregroundColor: .yellow, backgroundColor: .yellow.opacity(0.16))
1412        case .failure:
1413            return .init(title: row.status, systemImage: "minus.circle", foregroundColor: .secondary, backgroundColor: Color(.systemGray5).opacity(0.55))
1414        case .primary, .secondary:
1415            return .init(title: row.status, systemImage: "circle", foregroundColor: .secondary, backgroundColor: Color(.systemGray5).opacity(0.55))
1416        }
1417    }
1418}
1419
1420struct NetworkSectionView: View {
1421    @Environment(\.appDensity) private var appDensity
1422    @Binding var isCollapsed: Bool
1423    let reachabilityRows: [ReachabilityRowViewData]
1424    let reachabilityLoading: Bool
1425    let reachabilityError: String?
1426    let reachabilityProvenance: SectionProvenance?
1427    let locationRows: [InfoRowViewData]
1428    let geolocation: IPGeolocation?
1429    let geolocationLoading: Bool
1430    let geolocationError: String?
1431    let geolocationProvenance: SectionProvenance?
1432    let geolocationConfidence: ConfidenceLevel?
1433    let standardPortRows: [PortScanRowViewData]
1434    let customPortRows: [PortScanRowViewData]
1435    let portScanLoading: Bool
1436    let portScanError: String?
1437    let portScanProvenance: SectionProvenance?
1438    let customPortScanLoading: Bool
1439    let customPortScanError: String?
1440    let isCloudflareProxied: Bool
1441    @Binding var customPortsExpanded: Bool
1442    @Binding var customPortInput: String
1443    let onScanCustomPorts: () -> Void
1444
1445    var body: some View {
1446        CollapsibleSectionView(title: "Network", isCollapsed: $isCollapsed) {
1447            CardView {
1448                Text("Reachability")
1449                    .font(appDensity.font(.subheadline, weight: .semibold))
1450                    .foregroundStyle(.cyan)
1451                SectionTrustMetadataView(provenance: reachabilityProvenance, confidence: nil)
1452                if reachabilityLoading {
1453                    ProgressView("Checking ports…")
1454                        .appLoadingStyle()
1455                } else if let reachabilityError {
1456                    MessageRowView(text: reachabilityError, isError: true)
1457                } else {
1458                    ForEach(reachabilityRows) { row in
1459                        HStack {
1460                            Text(row.portLabel)
1461                                .font(appDensity.font(.caption))
1462                            Spacer()
1463                            Text(row.latencyLabel)
1464                                .font(appDensity.font(.caption2))
1465                                .foregroundStyle(.secondary)
1466                            AppStatusBadgeView(model: reachabilityBadge(row))
1467                        }
1468                    }
1469                }
1470            }
1471
1472            CardView(allowsHorizontalScroll: false) {
1473                Text("Location")
1474                    .font(appDensity.font(.subheadline, weight: .semibold))
1475                    .foregroundStyle(.cyan)
1476                SectionTrustMetadataView(provenance: geolocationProvenance, confidence: geolocationConfidence)
1477                if geolocationLoading {
1478                    ProgressView("Looking up location…")
1479                        .appLoadingStyle()
1480                } else if let geolocationError, geolocation == nil {
1481                    MessageRowView(text: geolocationError, isError: geolocationError != "No A record available")
1482                } else if let geolocation {
1483                    ForEach(locationRows) { row in
1484                        LabeledValueRow(row: row)
1485                    }
1486                    if let latitude = geolocation.latitude, let longitude = geolocation.longitude {
1487                        let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
1488                        Map(initialPosition: .region(MKCoordinateRegion(
1489                            center: coordinate,
1490                            span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1)
1491                        ))) {
1492                            Marker(geolocation.ip, coordinate: coordinate)
1493                        }
1494                        .mapStyle(.standard)
1495                        .frame(maxWidth: .infinity)
1496                        .frame(height: 180)
1497                        .cornerRadius(8)
1498                    }
1499                } else {
1500                    MessageRowView(text: "No location data available", isError: false)
1501                }
1502            }
1503
1504            CardView(allowsHorizontalScroll: false) {
1505                Text("Port Scan")
1506                    .font(appDensity.font(.subheadline, weight: .semibold))
1507                    .foregroundStyle(.cyan)
1508                SectionTrustMetadataView(provenance: portScanProvenance, confidence: nil)
1509
1510                if isCloudflareProxied {
1511                    Text("Domain is behind Cloudflare's proxy. Results reflect the edge, not the origin.")
1512                        .font(appDensity.font(.caption2))
1513                        .foregroundStyle(.orange)
1514                        .fixedSize(horizontal: false, vertical: true)
1515                }
1516
1517                if portScanLoading {
1518                    ProgressView("Scanning ports…")
1519                        .appLoadingStyle()
1520                } else if let portScanError, standardPortRows.isEmpty {
1521                    MessageRowView(text: portScanError, isError: true)
1522                } else {
1523                    Text("Standard Ports")
1524                        .font(.system(.caption, design: .monospaced))
1525                        .foregroundStyle(.secondary)
1526                    PortRowsView(rows: standardPortRows)
1527                }
1528
1529                DisclosureGroup("Custom Ports", isExpanded: $customPortsExpanded) {
1530                    VStack(alignment: .leading, spacing: 10) {
1531                        TextField("8888, 9000, 27017", text: $customPortInput)
1532                            .font(appDensity.font(.caption))
1533                            .textInputAutocapitalization(.never)
1534                            .autocorrectionDisabled()
1535                            .keyboardType(.numberPad)
1536                            .padding(10)
1537                            .background(Color(.systemGray6).opacity(0.5))
1538                            .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius))
1539
1540                        Button("Scan") {
1541                            AppHaptics.refresh()
1542                            onScanCustomPorts()
1543                        }
1544                        .buttonStyle(.borderedProminent)
1545                        .disabled(customPortScanLoading)
1546
1547                        if customPortScanLoading {
1548                            ProgressView("Scanning custom ports…")
1549                                .appLoadingStyle()
1550                        } else if let customPortScanError {
1551                            MessageRowView(text: customPortScanError, isError: true)
1552                        } else {
1553                            PortRowsView(rows: customPortRows)
1554                        }
1555                    }
1556                    .padding(.top, 8)
1557                }
1558                .font(.system(.caption, design: .monospaced))
1559                .tint(.secondary)
1560            }
1561        }
1562    }
1563
1564    private func reachabilityBadge(_ row: ReachabilityRowViewData) -> AppStatusBadgeModel {
1565        switch row.statusTone {
1566        case .success:
1567            return .init(title: row.statusLabel, systemImage: "checkmark.circle.fill", foregroundColor: .green, backgroundColor: .green.opacity(0.16))
1568        case .warning:
1569            return .init(title: row.statusLabel, systemImage: "exclamationmark.triangle.fill", foregroundColor: .yellow, backgroundColor: .yellow.opacity(0.16))
1570        case .failure:
1571            return .init(title: row.statusLabel, systemImage: "xmark.circle.fill", foregroundColor: .red, backgroundColor: .red.opacity(0.16))
1572        case .primary, .secondary:
1573            return .init(title: row.statusLabel, systemImage: "circle", foregroundColor: .secondary, backgroundColor: Color(.systemGray5).opacity(0.55))
1574        }
1575    }
1576}
1577
1578struct PortRowsView: View {
1579    @Environment(\.appDensity) private var appDensity
1580    let rows: [PortScanRowViewData]
1581
1582    var body: some View {
1583        if rows.isEmpty {
1584            MessageRowView(text: "No results", isError: false)
1585        } else {
1586            ForEach(rows) { row in
1587                VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing - 1) {
1588                    HStack {
1589                        Text(row.portLabel)
1590                            .font(appDensity.font(.caption))
1591                            .frame(width: 52, alignment: .leading)
1592                        Text(row.service)
1593                            .font(appDensity.font(.caption))
1594                            .foregroundStyle(.primary)
1595                        Spacer()
1596                        if let durationLabel = row.durationLabel {
1597                            Text(durationLabel)
1598                                .font(appDensity.font(.caption2))
1599                                .foregroundStyle(.secondary)
1600                        }
1601                        AppStatusBadgeView(model: portBadge(row))
1602                    }
1603                    if let banner = row.banner {
1604                        Text(banner)
1605                            .font(appDensity.font(.caption2))
1606                            .foregroundStyle(.secondary)
1607                            .padding(.leading, 8)
1608                    }
1609                }
1610                .frame(minHeight: appDensity.metrics.rowMinHeight, alignment: .topLeading)
1611            }
1612        }
1613    }
1614
1615    private func portBadge(_ row: PortScanRowViewData) -> AppStatusBadgeModel {
1616        switch row.statusTone {
1617        case .success:
1618            return .init(title: row.statusLabel, systemImage: "checkmark.circle.fill", foregroundColor: .green, backgroundColor: .green.opacity(0.16))
1619        case .warning:
1620            return .init(title: row.statusLabel, systemImage: "exclamationmark.triangle.fill", foregroundColor: .yellow, backgroundColor: .yellow.opacity(0.16))
1621        case .failure:
1622            return .init(title: row.statusLabel, systemImage: "xmark.circle.fill", foregroundColor: .red, backgroundColor: .red.opacity(0.16))
1623        case .primary, .secondary:
1624            return .init(title: row.statusLabel, systemImage: "circle", foregroundColor: .secondary, backgroundColor: Color(.systemGray5).opacity(0.55))
1625        }
1626    }
1627}
1628
1629struct SectionTitleView: View {
1630    @Environment(\.appDensity) private var appDensity
1631    let title: String
1632
1633    var body: some View {
1634        Text(title)
1635            .font(appDensity.font(.headline, design: .default, weight: .semibold))
1636            .foregroundStyle(.white)
1637    }
1638}
1639
1640struct CardView<Content: View>: View {
1641    @Environment(\.appDensity) private var appDensity
1642    let allowsHorizontalScroll: Bool
1643    let content: Content
1644
1645    init(allowsHorizontalScroll: Bool = true, @ViewBuilder content: () -> Content) {
1646        self.allowsHorizontalScroll = allowsHorizontalScroll
1647        self.content = content()
1648    }
1649
1650    var body: some View {
1651        Group {
1652            if allowsHorizontalScroll {
1653                ScrollView(.horizontal) {
1654                    cardContent
1655                        .scrollTargetLayout()
1656                }
1657                .scrollBounceBehavior(.basedOnSize, axes: .horizontal)
1658            } else {
1659                cardContent
1660                    .frame(maxWidth: .infinity, alignment: .leading)
1661            }
1662        }
1663        .frame(maxWidth: .infinity, alignment: .leading)
1664        .padding(appDensity.metrics.cardPadding)
1665        .background(Color(.systemGray6).opacity(0.5))
1666        .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius))
1667    }
1668
1669    private var cardContent: some View {
1670        VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) {
1671            content
1672        }
1673    }
1674}
1675
1676struct LoadingCardView: View {
1677    let text: String
1678
1679    var body: some View {
1680        CardView {
1681            ProgressView(text)
1682                .appLoadingStyle()
1683                .frame(maxWidth: .infinity, alignment: .center)
1684        }
1685    }
1686}
1687
1688struct MessageCardView: View {
1689    let text: String
1690    let isError: Bool
1691
1692    var body: some View {
1693        CardView {
1694            MessageRowView(text: text, isError: isError)
1695        }
1696    }
1697}
1698
1699struct MessageRowView: View {
1700    @Environment(\.appDensity) private var appDensity
1701    let text: String
1702    let isError: Bool
1703
1704    var body: some View {
1705        Label(text, systemImage: isError ? "exclamationmark.triangle.fill" : "info.circle")
1706            .font(appDensity.font(.caption))
1707            .foregroundStyle(isError ? .red : .secondary)
1708    }
1709}
1710
1711struct SectionTrustMetadataView: View {
1712    @Environment(\.appDensity) private var appDensity
1713    let provenance: SectionProvenance?
1714    let confidence: ConfidenceLevel?
1715    let note: String?
1716
1717    init(provenance: SectionProvenance?, confidence: ConfidenceLevel?, note: String? = nil) {
1718        self.provenance = provenance
1719        self.confidence = confidence
1720        self.note = note
1721    }
1722
1723    var body: some View {
1724        if provenance != nil || confidence != nil || note != nil {
1725            VStack(alignment: .leading, spacing: 6) {
1726                HStack(spacing: 8) {
1727                    if let confidence {
1728                        Text("Confidence \(confidence.title)")
1729                            .font(appDensity.font(.caption2))
1730                            .foregroundStyle(.secondary)
1731                    }
1732                    if let provenance {
1733                        Text(provenance.provider ?? provenance.source)
1734                            .font(appDensity.font(.caption2))
1735                            .foregroundStyle(.secondary)
1736                        Text(provenance.resultSource.label)
1737                            .font(appDensity.font(.caption2))
1738                            .foregroundStyle(.secondary)
1739                    }
1740                }
1741                DisclosureGroup("Details") {
1742                    VStack(alignment: .leading, spacing: 4) {
1743                        if let provenance {
1744                            LabeledValueRow(row: .init(label: "Method", value: provenance.source, tone: .secondary))
1745                            if let provider = provenance.provider {
1746                                LabeledValueRow(row: .init(label: "Provider", value: provider, tone: .secondary))
1747                            }
1748                            if let resolver = provenance.resolver {
1749                                LabeledValueRow(row: .init(label: "Resolver", value: resolver, tone: .secondary))
1750                            }
1751                            LabeledValueRow(row: .init(label: "Collected", value: provenance.collectedAt.formatted(date: .abbreviated, time: .shortened), tone: .secondary))
1752                            LabeledValueRow(row: .init(label: "Mode", value: provenance.resultSource.label, tone: .secondary))
1753                        }
1754                        if let note {
1755                            LabeledValueRow(row: .init(label: "Note", value: note, tone: .secondary))
1756                        }
1757                    }
1758                    .padding(.top, 4)
1759                }
1760                .font(appDensity.font(.caption))
1761                .tint(.secondary)
1762            }
1763        }
1764    }
1765}
1766
1767struct LabeledValueRow: View {
1768    @Environment(\.appDensity) private var appDensity
1769    let row: InfoRowViewData
1770
1771    var body: some View {
1772        VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing - 1) {
1773            HStack(alignment: .top, spacing: 8) {
1774                VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing - 1) {
1775                    Text(row.label)
1776                        .font(appDensity.font(.caption2))
1777                        .foregroundStyle(.secondary)
1778                    Text(row.value)
1779                        .font(appDensity.font(.caption))
1780                        .foregroundStyle(ResultColors.color(for: row.tone))
1781                        .textSelection(.enabled)
1782                }
1783                Spacer(minLength: 6)
1784                if !row.value.isEmpty, row.value != "Unavailable" {
1785                    AppCopyButton(value: row.value, label: "Copy \(row.label)")
1786                }
1787            }
1788        }
1789        .frame(minHeight: appDensity.metrics.rowMinHeight, alignment: .topLeading)
1790    }
1791}
1792
1793enum ResultColors {
1794    static func color(for tone: ResultTone) -> Color {
1795        switch tone {
1796        case .primary:
1797            return .primary
1798        case .secondary:
1799            return .secondary
1800        case .success:
1801            return .green
1802        case .warning:
1803            return .yellow
1804        case .failure:
1805            return .red
1806        }
1807    }
1808}
1809
1810extension DateFormatter {
1811    static let certDate: DateFormatter = {
1812        let formatter = DateFormatter()
1813        formatter.dateStyle = .medium
1814        formatter.timeStyle = .short
1815        return formatter
1816    }()
1817}
1818
1819private extension View {
1820    func appLoadingStyle() -> some View {
1821        font(.system(.caption, design: .monospaced))
1822    }
1823}
1824
1825private extension String {
1826    var nilIfEmpty: String? {
1827        isEmpty ? nil : self
1828    }
1829}
1830
1831private struct SettingsView: View {
1832    @Environment(\.appDensity) private var appDensity
1833    @Bindable var viewModel: DomainViewModel
1834    @AppStorage(DNSResolverOption.userDefaultsKey)
1835    private var storedResolverURL = DNSResolverOption.defaultURLString
1836    @AppStorage(AppDensity.userDefaultsKey)
1837    private var storedDensity = AppDensity.compact.rawValue
1838
1839    @State private var resolverOption: DNSResolverOption = .cloudflare
1840    @State private var customResolverURL = DNSResolverOption.defaultURLString
1841    @State private var showClearHistoryConfirmation = false
1842    @State private var showClearCacheConfirmation = false
1843
1844    private var customResolverError: String? {
1845        guard resolverOption == .custom else {
1846            return nil
1847        }
1848        return DNSResolverOption.isValidCustomURL(customResolverURL) ? nil : "Resolver URL must start with https://"
1849    }
1850
1851    var body: some View {
1852        Form {
1853            Section("Display") {
1854                Picker("Density", selection: $storedDensity) {
1855                    ForEach(AppDensity.allCases) { density in
1856                        Text(density.title).tag(density.rawValue)
1857                    }
1858                }
1859            }
1860
1861            Section("Network") {
1862                Picker("Resolver", selection: $resolverOption) {
1863                    ForEach(DNSResolverOption.allCases) { option in
1864                        Text(option.title).tag(option)
1865                    }
1866                }
1867
1868                if resolverOption == .custom {
1869                    TextField("https://resolver.example/dns-query", text: $customResolverURL)
1870                        .textInputAutocapitalization(.never)
1871                        .autocorrectionDisabled()
1872                        .keyboardType(.URL)
1873
1874                    if let customResolverError {
1875                        Text(customResolverError)
1876                            .font(appDensity.font(.caption, design: .default))
1877                            .foregroundStyle(.red)
1878                    }
1879                }
1880            }
1881
1882            Section("Data") {
1883                Button("Clear History", role: .destructive) {
1884                    showClearHistoryConfirmation = true
1885                }
1886
1887                Button("Clear Cache", role: .destructive) {
1888                    showClearCacheConfirmation = true
1889                }
1890            }
1891
1892            Section("About") {
1893                LabeledContent("Version", value: appVersion)
1894                LabeledContent("Storage", value: "Local-only")
1895            }
1896        }
1897        .navigationTitle("Settings")
1898        .alert("Clear history?", isPresented: $showClearHistoryConfirmation) {
1899            Button("Clear", role: .destructive) {
1900                viewModel.clearHistory()
1901            }
1902            Button("Cancel", role: .cancel) {}
1903        } message: {
1904            Text("This removes saved lookup snapshots from this device.")
1905        }
1906        .alert("Clear cache?", isPresented: $showClearCacheConfirmation) {
1907            Button("Clear", role: .destructive) {
1908                viewModel.clearLookupCache()
1909            }
1910            Button("Cancel", role: .cancel) {}
1911        } message: {
1912            Text("This clears the in-memory lookup cache and cancels any cached in-flight work.")
1913        }
1914        .onAppear {
1915            let currentResolverURL = storedResolverURL.trimmingCharacters(in: .whitespacesAndNewlines)
1916            resolverOption = DNSResolverOption.option(for: currentResolverURL)
1917            customResolverURL = resolverOption == .custom ? currentResolverURL : DNSResolverOption.defaultURLString
1918        }
1919        .onChange(of: resolverOption) { _, newValue in
1920            guard let presetURL = newValue.urlString else {
1921                storedResolverURL = customResolverURL.trimmingCharacters(in: .whitespacesAndNewlines)
1922                return
1923            }
1924            storedResolverURL = presetURL
1925        }
1926        .onChange(of: customResolverURL) { _, newValue in
1927            guard resolverOption == .custom else { return }
1928            storedResolverURL = newValue.trimmingCharacters(in: .whitespacesAndNewlines)
1929        }
1930    }
1931
1932    private var appVersion: String {
1933        AppVersion.current
1934    }
1935}
1936
1937#Preview {
1938    ContentView()
1939}