TreatmentMenuView.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import SwiftUI
  2. struct TreatmentMenuView: View {
  3. @Environment(\.dismiss) var dismiss
  4. let deviceType: WatchSize
  5. @Binding var selectedTreatment: TreatmentOption?
  6. var onSelect: () -> Void // Callback to handle selection and dismiss the sheet
  7. // Define in array to achieve custom order of treatment options
  8. let treatments: [TreatmentOption] = [
  9. .meal, // First
  10. .bolus, // Second
  11. .mealBolusCombo // Third
  12. ]
  13. private var iconSize: CGFloat {
  14. switch deviceType {
  15. case .watch40mm,
  16. .watch41mm,
  17. .watch42mm:
  18. return 18
  19. case .unknown,
  20. .watch44mm,
  21. .watch45mm:
  22. return 22
  23. case .watch49mm:
  24. return 24
  25. }
  26. }
  27. private var iconPadding: CGFloat {
  28. switch deviceType {
  29. case .watch40mm,
  30. .watch41mm,
  31. .watch42mm:
  32. return 6
  33. case .unknown,
  34. .watch44mm,
  35. .watch45mm:
  36. return 10
  37. case .watch49mm:
  38. return 12
  39. }
  40. }
  41. var body: some View {
  42. VStack {
  43. List {
  44. ForEach(treatments) { treatment in
  45. Button(action: {
  46. selectedTreatment = treatment
  47. onSelect()
  48. }) {
  49. HStack(spacing: 10) {
  50. switch treatment {
  51. case .meal:
  52. mealIcon
  53. Text(treatment.displayName)
  54. case .bolus:
  55. bolusIcon
  56. Text(treatment.displayName)
  57. case .mealBolusCombo:
  58. mealIcon
  59. bolusIcon
  60. }
  61. }
  62. .foregroundColor(.white)
  63. .frame(maxWidth: .infinity)
  64. }
  65. .buttonStyle(PressableIconButtonStyle())
  66. }
  67. }.navigationTitle("Pick Treatment")
  68. }
  69. }
  70. var mealIcon: some View {
  71. Image(systemName: "fork.knife")
  72. .resizable()
  73. .aspectRatio(contentMode: .fit)
  74. .frame(width: iconSize, height: iconSize)
  75. .padding(iconPadding)
  76. .background(Color.orange)
  77. .clipShape(Circle())
  78. }
  79. var bolusIcon: some View {
  80. Image(systemName: "syringe.fill")
  81. .resizable()
  82. .aspectRatio(contentMode: .fit)
  83. .frame(width: iconSize, height: iconSize)
  84. .padding(iconPadding)
  85. .background(Color.insulin)
  86. .clipShape(Circle())
  87. }
  88. }
  89. enum TreatmentOption: String, CaseIterable, Identifiable {
  90. var id: String { rawValue }
  91. case mealBolusCombo
  92. case meal
  93. case bolus
  94. var displayName: String {
  95. switch self {
  96. case .mealBolusCombo: return String(localized: "Meal & Bolus", comment: "Watch App Treatment Option 'Meal & Bolus'")
  97. case .meal: return String(localized: "Meal", comment: "Watch App Treatment Option 'Meal'")
  98. case .bolus: return String(localized: "Bolus", comment: "Watch App Treatment Option 'Bolus'")
  99. }
  100. }
  101. }