import SwiftUI struct MonitorMenuView: View { @ObservedObject var monitor: ServerMonitor @Environment(\.openSettings) private var openSettings var body: some View { VStack(alignment: .leading, spacing: 0) { HStack(spacing: 12) { Image(systemName: "server.rack") .font(.system(size: 26, weight: .semibold)) .foregroundStyle(.tint) VStack(alignment: .leading, spacing: 3) { Text("PEGASUS MONITOR") .font(.headline) Text("192.168.1.2 · Remote server health") .font(.caption) .foregroundStyle(.secondary) } Spacer() if monitor.isRefreshing { ProgressView().controlSize(.small) } } .padding(18) Divider() if let report = monitor.report { ScrollView { VStack(alignment: .leading, spacing: 10) { ForEach(report.groups) { group in HStack(spacing: 8) { Image(systemName: group.status.symbol) .foregroundStyle(group.status.color) .frame(width: 22) Text(group.name) .font(.system(size: 13)) Spacer() } .help(group.missing.isEmpty ? group.status.title : "Missing checks: \(group.missing.joined(separator: ", "))") } } .padding(.horizontal, 18) .padding(.vertical, 14) } .frame(maxHeight: 375) Divider() HStack { Image(systemName: monitor.status.symbol) .foregroundStyle(monitor.status.color) Text("OVERALL: \(monitor.status.title.uppercased())") .font(.system(size: 13, weight: .bold)) Spacer() Text("\(report.counts.ok) OK · \(report.counts.warn) WARN · \(report.counts.fail) FAIL") .font(.caption2.monospacedDigit()) .foregroundStyle(.secondary) } .padding(.horizontal, 18) .padding(.vertical, 12) } else { ContentUnavailableView("No health report", systemImage: "network", description: Text("Check SSH configuration and refresh.")) .frame(height: 220) } if let error = monitor.lastError { Text(error) .font(.caption) .foregroundStyle(.red) .textSelection(.enabled) .padding(.horizontal, 18) .padding(.bottom, 10) } Divider() HStack { Text(monitor.lastChecked.map { "Checked \($0.formatted(date: .omitted, time: .shortened))" } ?? "Not checked yet") .font(.caption) .foregroundStyle(.secondary) Spacer() Button { Task { await monitor.refresh() } } label: { Label("Refresh", systemImage: "arrow.clockwise") } .disabled(monitor.isRefreshing) } .padding(.horizontal, 18) .padding(.vertical, 8) HStack { Button("Full Diagnostics") { monitor.showDiagnostics = true } Spacer() Button("Settings") { monitor.showSettings = true } Button("Quit") { NSApplication.shared.terminate(nil) } } .padding(.horizontal, 18) .padding(.bottom, 12) } .sheet(isPresented: $monitor.showDiagnostics) { DiagnosticsView(monitor: monitor) } .sheet(isPresented: $monitor.showSettings) { SettingsView(monitor: monitor) .frame(width: 480) } } } struct DiagnosticsView: View { @ObservedObject var monitor: ServerMonitor @Environment(\.dismiss) private var dismiss var body: some View { VStack(alignment: .leading, spacing: 12) { HStack { Text("Pegasus Diagnostics").font(.title2.bold()) Spacer() Button("Close") { dismiss() } } Text("Latest remote report — refresh from the menu to update") .foregroundStyle(.secondary) ScrollView { LazyVStack(alignment: .leading, spacing: 10) { ForEach(monitor.report?.checks ?? []) { check in HStack(alignment: .top) { Image(systemName: check.status.symbol).foregroundStyle(check.status.color) VStack(alignment: .leading, spacing: 2) { Text(check.name).fontWeight(.medium) Text(check.detail).font(.caption).foregroundStyle(.secondary) } Spacer() } } } } .textSelection(.enabled) } .padding(20) .frame(width: 650, height: 560) } }