TabPosition.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // LoopFollow
  2. // TabPosition.swift
  3. enum TabPosition: String, CaseIterable, Codable, Comparable {
  4. case position1
  5. case position2
  6. case position3
  7. case position4
  8. case menu
  9. case more
  10. case disabled
  11. var displayName: String {
  12. switch self {
  13. case .position1: return "Tab 1"
  14. case .position2: return "Tab 2"
  15. case .position3: return "Tab 3"
  16. case .position4: return "Tab 4"
  17. case .menu, .more, .disabled: return "Menu"
  18. }
  19. }
  20. /// The index in the tab bar (0-based)
  21. var tabIndex: Int? {
  22. switch self {
  23. case .position1: return 0
  24. case .position2: return 1
  25. case .position3: return 2
  26. case .position4: return 3
  27. case .menu, .more, .disabled: return 4
  28. }
  29. }
  30. /// Positions that users can customize (1-4)
  31. static var customizablePositions: [TabPosition] {
  32. [.position1, .position2, .position3, .position4]
  33. }
  34. /// Normalize legacy values to current values
  35. var normalized: TabPosition {
  36. switch self {
  37. case .more, .disabled: return .menu
  38. default: return self
  39. }
  40. }
  41. // Comparable conformance for sorting
  42. static func < (lhs: TabPosition, rhs: TabPosition) -> Bool {
  43. let order: [TabPosition] = [.position1, .position2, .position3, .position4, .menu, .more, .disabled]
  44. guard let lhsIndex = order.firstIndex(of: lhs),
  45. let rhsIndex = order.firstIndex(of: rhs) else { return false }
  46. return lhsIndex < rhsIndex
  47. }
  48. }
  49. /// Represents a tab item that can be placed in any position
  50. enum TabItem: String, CaseIterable, Codable, Identifiable {
  51. case home
  52. case alarms
  53. case remote
  54. case nightscout
  55. case snoozer
  56. case treatments
  57. case stats
  58. var id: String { rawValue }
  59. var displayName: String {
  60. switch self {
  61. case .home: return "Home"
  62. case .alarms: return "Alarms"
  63. case .remote: return "Remote"
  64. case .nightscout: return "Nightscout"
  65. case .snoozer: return "Snoozer"
  66. case .treatments: return "Treatments"
  67. case .stats: return "Statistics"
  68. }
  69. }
  70. var icon: String {
  71. switch self {
  72. case .home: return "house"
  73. case .alarms: return "alarm"
  74. case .remote: return "antenna.radiowaves.left.and.right"
  75. case .nightscout: return "safari"
  76. case .snoozer: return "zzz"
  77. case .treatments: return "cross.case"
  78. case .stats: return "chart.bar.xaxis"
  79. }
  80. }
  81. /// Canonical feature order used by menus and customization screens.
  82. static var featureOrder: [TabItem] {
  83. [.home, .alarms, .nightscout, .remote, .snoozer, .stats, .treatments]
  84. }
  85. /// Items that can be moved between tab bar and menu (all except settings which doesn't exist as a tab)
  86. static var movableItems: [TabItem] {
  87. featureOrder
  88. }
  89. }