11import SwiftUI
2+ import Networking
23
34struct UpdateAttendanceStatusView : View {
45 @Environment ( \. dismiss) private var dismiss
5- private let statuses = AttendanceStatus . allCases
6- private let onStatusSelected : ( AttendanceStatus ) -> Void
6+ private let onStatusSelected : ( BookingAttendanceStatus ) -> Void
7+ @ State private var selectedStatus : BookingAttendanceStatus
78
8- init ( onStatusSelected: @escaping ( AttendanceStatus ) -> Void ) {
9+ init ( selectedStatus : BookingAttendanceStatus , onStatusSelected: @escaping ( BookingAttendanceStatus ) -> Void ) {
910 self . onStatusSelected = onStatusSelected
11+ self . _selectedStatus = . init( initialValue: selectedStatus)
1012 }
1113
1214 var body : some View {
@@ -17,7 +19,7 @@ struct UpdateAttendanceStatusView: View {
1719 . foregroundColor ( . secondary)
1820 . padding ( . horizontal)
1921
20- ForEach ( statuses) { status in
22+ ForEach ( Constants . statuses, id : \ . self ) { status in
2123 HStack ( alignment: . top, spacing: 16 ) {
2224 Image ( systemName: status. iconName)
2325 . font ( . title3. weight ( . medium) )
@@ -31,6 +33,13 @@ struct UpdateAttendanceStatusView: View {
3133 . foregroundColor ( . secondary)
3234 . fixedSize ( horizontal: false , vertical: true )
3335 }
36+
37+ if status == selectedStatus {
38+ Spacer ( )
39+ Image ( systemName: " checkmark " )
40+ . font ( . title3. weight ( . medium) )
41+ . foregroundStyle ( Color . accentColor)
42+ }
3443 }
3544 . padding ( . horizontal)
3645 . contentShape ( Rectangle ( ) )
@@ -45,17 +54,7 @@ struct UpdateAttendanceStatusView: View {
4554 }
4655}
4756
48- extension UpdateAttendanceStatusView {
49- enum AttendanceStatus : CaseIterable , Identifiable {
50- case booked
51- case checkedIn
52- case noShow
53-
54- var id : Self { self }
55- }
56- }
57-
58- private extension UpdateAttendanceStatusView . AttendanceStatus {
57+ private extension BookingAttendanceStatus {
5958 var title : String {
6059 switch self {
6160 case . booked:
@@ -64,6 +63,8 @@ private extension UpdateAttendanceStatusView.AttendanceStatus {
6463 return UpdateAttendanceStatusView . Localization. checkedInTitle
6564 case . noShow:
6665 return UpdateAttendanceStatusView . Localization. noShowTitle
66+ case . cancelled, . unknown:
67+ return " "
6768 }
6869 }
6970
@@ -75,6 +76,8 @@ private extension UpdateAttendanceStatusView.AttendanceStatus {
7576 return UpdateAttendanceStatusView . Localization. checkedInDescription
7677 case . noShow:
7778 return UpdateAttendanceStatusView . Localization. noShowDescription
79+ case . cancelled, . unknown:
80+ return " "
7881 }
7982 }
8083
@@ -83,14 +86,20 @@ private extension UpdateAttendanceStatusView.AttendanceStatus {
8386 case . booked:
8487 return " calendar.badge.checkmark "
8588 case . checkedIn:
86- return " calendar.and.person "
89+ return " person.fill.checkmark "
8790 case . noShow:
8891 return " calendar.badge.exclamationmark "
92+ case . cancelled, . unknown:
93+ return " "
8994 }
9095 }
9196}
9297
9398private extension UpdateAttendanceStatusView {
99+ enum Constants {
100+ static let statuses : [ BookingAttendanceStatus ] = [ . booked, . checkedIn, . noShow]
101+ }
102+
94103 enum Localization {
95104 static let title = NSLocalizedString (
96105 " UpdateAttendanceStatusView.title " ,
@@ -136,7 +145,7 @@ private extension UpdateAttendanceStatusView {
136145#if DEBUG
137146struct UpdateAttendanceStatusView_Previews : PreviewProvider {
138147 static var previews : some View {
139- UpdateAttendanceStatusView { selectedStatus in
148+ UpdateAttendanceStatusView ( selectedStatus : . booked ) { selectedStatus in
140149 print ( " Selected status: \( selectedStatus) " )
141150 }
142151 }
0 commit comments