|
| 1 | +import SwiftUI |
| 2 | + |
| 3 | +struct UpdateAttendanceStatusView: View { |
| 4 | + @Environment(\.dismiss) private var dismiss |
| 5 | + private let statuses = AttendanceStatus.allCases |
| 6 | + private let onStatusSelected: (AttendanceStatus) -> Void |
| 7 | + |
| 8 | + init(onStatusSelected: @escaping (AttendanceStatus) -> Void) { |
| 9 | + self.onStatusSelected = onStatusSelected |
| 10 | + } |
| 11 | + |
| 12 | + var body: some View { |
| 13 | + ScrollView { |
| 14 | + VStack(alignment: .leading, spacing: 24) { |
| 15 | + Text(Localization.title) |
| 16 | + .font(.subheadline.weight(.medium)) |
| 17 | + .foregroundColor(.secondary) |
| 18 | + .padding(.horizontal) |
| 19 | + |
| 20 | + ForEach(statuses) { status in |
| 21 | + HStack(alignment: .top, spacing: 16) { |
| 22 | + Image(systemName: status.iconName) |
| 23 | + .font(.title3.weight(.medium)) |
| 24 | + .foregroundStyle(Color(.systemGray)) |
| 25 | + VStack(alignment: .leading, spacing: 4) { |
| 26 | + Text(status.title) |
| 27 | + .font(.body.weight(.medium)) |
| 28 | + .fixedSize(horizontal: false, vertical: true) |
| 29 | + Text(status.description) |
| 30 | + .font(.subheadline) |
| 31 | + .foregroundColor(.secondary) |
| 32 | + .fixedSize(horizontal: false, vertical: true) |
| 33 | + } |
| 34 | + } |
| 35 | + .padding(.horizontal) |
| 36 | + .contentShape(Rectangle()) |
| 37 | + .tappable { |
| 38 | + onStatusSelected(status) |
| 39 | + dismiss() |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + .padding(.top) |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 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 { |
| 59 | + var title: String { |
| 60 | + switch self { |
| 61 | + case .booked: |
| 62 | + return UpdateAttendanceStatusView.Localization.bookedTitle |
| 63 | + case .checkedIn: |
| 64 | + return UpdateAttendanceStatusView.Localization.checkedInTitle |
| 65 | + case .noShow: |
| 66 | + return UpdateAttendanceStatusView.Localization.noShowTitle |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + var description: String { |
| 71 | + switch self { |
| 72 | + case .booked: |
| 73 | + return UpdateAttendanceStatusView.Localization.bookedDescription |
| 74 | + case .checkedIn: |
| 75 | + return UpdateAttendanceStatusView.Localization.checkedInDescription |
| 76 | + case .noShow: |
| 77 | + return UpdateAttendanceStatusView.Localization.noShowDescription |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + var iconName: String { |
| 82 | + switch self { |
| 83 | + case .booked: |
| 84 | + return "calendar.badge.checkmark" |
| 85 | + case .checkedIn: |
| 86 | + return "calendar.and.person" |
| 87 | + case .noShow: |
| 88 | + return "calendar.badge.exclamationmark" |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +private extension UpdateAttendanceStatusView { |
| 94 | + enum Localization { |
| 95 | + static let title = NSLocalizedString( |
| 96 | + "UpdateAttendanceStatusView.title", |
| 97 | + value: "Update attendance status", |
| 98 | + comment: "Title of the update attendance status bottom sheet." |
| 99 | + ) |
| 100 | + |
| 101 | + static let bookedTitle = NSLocalizedString( |
| 102 | + "UpdateAttendanceStatusView.booked.title", |
| 103 | + value: "Booked", |
| 104 | + comment: "Title for the 'Booked' attendance status." |
| 105 | + ) |
| 106 | + static let bookedDescription = NSLocalizedString( |
| 107 | + "UpdateAttendanceStatusView.booked.description", |
| 108 | + value: "The appointment is scheduled but hasn't happened yet.", |
| 109 | + comment: "Description for the 'Booked' attendance status." |
| 110 | + ) |
| 111 | + |
| 112 | + static let checkedInTitle = NSLocalizedString( |
| 113 | + "UpdateAttendanceStatusView.checkedIn.title", |
| 114 | + value: "Checked-in", |
| 115 | + comment: "Title for the 'Checked-in' attendance status." |
| 116 | + ) |
| 117 | + static let checkedInDescription = NSLocalizedString( |
| 118 | + "UpdateAttendanceStatusView.checkedIn.description", |
| 119 | + value: "The customer arrived and the session took place as planned.", |
| 120 | + comment: "Description for the 'Checked-in' attendance status." |
| 121 | + ) |
| 122 | + |
| 123 | + static let noShowTitle = NSLocalizedString( |
| 124 | + "UpdateAttendanceStatusView.noShow.title", |
| 125 | + value: "No-show", |
| 126 | + comment: "Title for the 'No-show' attendance status." |
| 127 | + ) |
| 128 | + static let noShowDescription = NSLocalizedString( |
| 129 | + "UpdateAttendanceStatusView.noShow.description", |
| 130 | + value: "The client missed the appointment without canceling in advance.", |
| 131 | + comment: "Description for the 'No-show' attendance status." |
| 132 | + ) |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +#if DEBUG |
| 137 | +struct UpdateAttendanceStatusView_Previews: PreviewProvider { |
| 138 | + static var previews: some View { |
| 139 | + UpdateAttendanceStatusView { selectedStatus in |
| 140 | + print("Selected status: \(selectedStatus)") |
| 141 | + } |
| 142 | + } |
| 143 | +} |
| 144 | +#endif |
0 commit comments