TreatmentMenuView.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import SwiftUI
  2. struct TreatmentMenuView: View {
  3. @Environment(\.dismiss) var dismiss
  4. @Binding var selectedTreatment: TreatmentOption?
  5. var onSelect: () -> Void // Callback to handle selection and dismiss the sheet
  6. // Define in array to achieve custom order of treatment options
  7. let treatments: [TreatmentOption] = [
  8. .meal, // First
  9. .bolus, // Second
  10. .mealBolusCombo // Third
  11. ]
  12. private var is40mm: Bool {
  13. let size = WKInterfaceDevice.current().screenBounds.size
  14. return size.height < 225 && size.width < 185
  15. }
  16. private var iconSize: CGFloat {
  17. is40mm ? 18 : 22
  18. }
  19. var body: some View {
  20. VStack {
  21. List {
  22. ForEach(treatments) { treatment in
  23. Button(action: {
  24. selectedTreatment = treatment
  25. onSelect()
  26. }) {
  27. HStack(spacing: 10) {
  28. switch treatment {
  29. case .meal:
  30. mealIcon
  31. Text(treatment.displayName)
  32. case .bolus:
  33. bolusIcon
  34. Text(treatment.displayName)
  35. case .mealBolusCombo:
  36. mealIcon
  37. bolusIcon
  38. }
  39. }
  40. .foregroundColor(.white)
  41. .frame(maxWidth: .infinity)
  42. }
  43. .buttonStyle(PressableIconButtonStyle())
  44. }
  45. }.navigationTitle("Pick Treatment")
  46. }
  47. }
  48. var mealIcon: some View {
  49. Image(systemName: "fork.knife")
  50. .resizable()
  51. .aspectRatio(contentMode: .fit)
  52. .frame(width: iconSize, height: iconSize)
  53. .padding(is40mm ? 6 : 10)
  54. .background(Color.orange)
  55. .clipShape(Circle())
  56. }
  57. var bolusIcon: some View {
  58. Image(systemName: "syringe.fill")
  59. .resizable()
  60. .aspectRatio(contentMode: .fit)
  61. .frame(width: iconSize, height: iconSize)
  62. .padding(is40mm ? 6 : 10)
  63. .background(Color.blue)
  64. .clipShape(Circle())
  65. }
  66. }
  67. enum TreatmentOption: String, CaseIterable, Identifiable {
  68. var id: String { rawValue }
  69. case mealBolusCombo
  70. case meal
  71. case bolus
  72. var displayName: String {
  73. switch self {
  74. case .mealBolusCombo: return "Meal & Bolus"
  75. case .meal: return "Meal"
  76. case .bolus: return "Bolus"
  77. }
  78. }
  79. }