DataAvailabilityView.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // LoopFollow
  2. // DataAvailabilityView.swift
  3. import SwiftUI
  4. struct DataAvailabilityView: View {
  5. let availability: DataAvailabilityInfo
  6. var compact: Bool = false
  7. var body: some View {
  8. if compact {
  9. compactView
  10. } else {
  11. fullView
  12. }
  13. }
  14. private var compactView: some View {
  15. HStack(spacing: 8) {
  16. Image(systemName: statusIcon)
  17. .font(.caption)
  18. .foregroundColor(statusColor)
  19. Text(availability.displayText)
  20. .font(.caption)
  21. .foregroundColor(.secondary)
  22. Text(availability.dataQuality.description)
  23. .font(.caption)
  24. .fontWeight(.medium)
  25. .foregroundColor(statusColor)
  26. }
  27. .padding(.horizontal, 12)
  28. .padding(.vertical, 6)
  29. .background(backgroundColor.opacity(0.5))
  30. .cornerRadius(8)
  31. }
  32. private var fullView: some View {
  33. VStack(alignment: .leading, spacing: 8) {
  34. HStack {
  35. Image(systemName: statusIcon)
  36. .foregroundColor(statusColor)
  37. VStack(alignment: .leading, spacing: 2) {
  38. Text("Data Availability")
  39. .font(.caption)
  40. .foregroundColor(.secondary)
  41. Text(availability.displayText)
  42. .font(.subheadline)
  43. .fontWeight(.medium)
  44. }
  45. Spacer()
  46. VStack(alignment: .trailing, spacing: 2) {
  47. Text(availability.dataQuality.description)
  48. .font(.caption)
  49. .fontWeight(.semibold)
  50. .foregroundColor(statusColor)
  51. if availability.missingIntervals > 0 {
  52. Text("\(availability.missingIntervals) gaps")
  53. .font(.caption2)
  54. .foregroundColor(.secondary)
  55. }
  56. }
  57. }
  58. .padding()
  59. .background(backgroundColor)
  60. .cornerRadius(12)
  61. }
  62. }
  63. private var statusIcon: String {
  64. switch availability.dataQuality {
  65. case .excellent:
  66. return "checkmark.circle.fill"
  67. case .good:
  68. return "checkmark.circle"
  69. case .fair:
  70. return "exclamationmark.triangle"
  71. case .poor:
  72. return "xmark.circle"
  73. }
  74. }
  75. private var statusColor: Color {
  76. switch availability.dataQuality {
  77. case .excellent:
  78. return .green
  79. case .good:
  80. return .blue
  81. case .fair:
  82. return .orange
  83. case .poor:
  84. return .red
  85. }
  86. }
  87. private var backgroundColor: Color {
  88. switch availability.dataQuality {
  89. case .excellent:
  90. return Color.green.opacity(0.1)
  91. case .good:
  92. return Color.blue.opacity(0.1)
  93. case .fair:
  94. return Color.orange.opacity(0.1)
  95. case .poor:
  96. return Color.red.opacity(0.1)
  97. }
  98. }
  99. }