Repository Public License
1// ORIX Alarm2// File: App/Features/Dashboard/DashboardCards.swift3// Description: Cards of the Today dashboard: next alarm, scheduling problems, quick alarms, upcoming, sleep plan, recorded performance, tips, focus timer.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import AlarmCore8import SwiftUI910// MARK: Next alarm1112struct NextAlarmCard: View {13 let alarm: AlarmDefinition14 let date: Date15 let now: Date16 @Environment(AppModel.self) private var model1718 var body: some View {19 let error = model.schedulingErrors[alarm.id]20 let status = model.status(for: alarm.id)21 let progressive = alarm.scenario.progressive.isEnabled22 VStack(alignment: .leading, spacing: 14) {23 HStack(alignment: .center) {24 Overline("Next alarm")25 AlarmStatusBadge(status: status, hasError: error != nil)26 }27 VStack(alignment: .leading, spacing: 2) {28 AlarmTimeText(time: alarm.time, size: 60)29 Text(AlarmText.name(alarm)).font(.orixTitle).lineLimit(2)30 }31 VStack(alignment: .leading, spacing: 6) {32 Label(Fmt.countdown(to: date, from: now), systemImage: "hourglass")33 .font(.orixHeadline).foregroundStyle(Theme.sunrise)34 Label("\(AlarmText.dayLabel(for: date, now: now, calendar: model.calendar)) · \(Fmt.recurrence(alarm.weekdays))",35 systemImage: alarm.isRecurring ? "repeat" : "1.circle")36 .font(.orixCaption).foregroundStyle(Theme.textSecondary)37 }38 if alarm.scenario.missions.isEmpty {39 Label(alarm.scenario.requiresConfirmation ? "No mission · wake confirmation asked" : "No mission", systemImage: "puzzlepiece.extension")40 .font(.orixCaption).foregroundStyle(Theme.textSecondary)41 } else {42 MissionChipFlow(missions: alarm.scenario.missions)43 }44 if error != nil {45 Label("This alarm is not scheduled with iOS. See the problem at the top of this page.", systemImage: "exclamationmark.triangle.fill")46 .font(.orixCaption).foregroundStyle(Theme.danger).fixedSize(horizontal: false, vertical: true)47 } else if status != .confirmed {48 Label(status == .unverifiable ? "ORIX Alarm could not check this alarm with iOS yet." : "iOS does not hold this alarm as configured.",49 systemImage: status.symbol)50 .font(.orixCaption).foregroundStyle(status.tint).fixedSize(horizontal: false, vertical: true)51 }52 HStack(spacing: 12) {53 Button { model.nightstandAlarmID = alarm.id } label: { Label("Nightstand", systemImage: "moon.stars.fill") }54 .buttonStyle(SecondaryButtonStyle())55 .accessibilityIdentifier("dashboard.nightstand")56 Button { model.editingAlarm = alarm } label: { Label("Edit", systemImage: "slider.horizontal.3") }57 .buttonStyle(SecondaryButtonStyle())58 .accessibilityIdentifier("dashboard.editNext")59 }60 if progressive {61 Text("Progressive wake starts \(alarm.scenario.progressive.leadMinutes) min before the alarm, only while Nightstand is open on screen.")62 .font(.orixCaption).foregroundStyle(Theme.textTertiary).fixedSize(horizontal: false, vertical: true)63 }64 }65 .glassCard(padding: 20, tint: error != nil ? Theme.danger : nil)66 .accessibilityElement(children: .contain)67 .accessibilityIdentifier("dashboard.nextAlarm")68 }69}7071/// Alarms exist but none is switched on.72struct NoActiveAlarmCard: View {73 @Environment(AppModel.self) private var model7475 var body: some View {76 VStack(alignment: .leading, spacing: 12) {77 Overline("Next alarm")78 Label("No alarm is switched on", systemImage: "moon.zzz.fill").font(.orixTitle)79 Text("Nothing will ring. Switch an alarm on, or create a new one.")80 .font(.orixBody).foregroundStyle(Theme.textSecondary)81 Button { model.selectedTab = .alarms } label: { Label("Show my alarms", systemImage: "alarm.fill") }82 .buttonStyle(SecondaryButtonStyle())83 .accessibilityIdentifier("dashboard.showAlarms")84 }85 .glassCard(padding: 20)86 .accessibilityElement(children: .contain)87 .accessibilityIdentifier("dashboard.nextAlarm")88 }89}9091// MARK: Scheduling problems9293/// Alarms the system refused or lost. Shown above everything else so a silent failure cannot go unnoticed.94struct SchedulingProblemsCard: View {95 let alarms: [AlarmDefinition]96 @Environment(AppModel.self) private var model9798 var body: some View {99 VStack(alignment: .leading, spacing: 14) {100 Label(alarms.count == 1 ? "1 alarm is not scheduled" : "\(alarms.count) alarms are not scheduled", systemImage: "exclamationmark.octagon.fill")101 .font(.orixHeadline).foregroundStyle(Theme.danger)102 Text("These alarms are saved in the app but iOS did not accept them, so they will not ring.")103 .font(.orixCaption).foregroundStyle(Theme.textSecondary).fixedSize(horizontal: false, vertical: true)104 ForEach(Array(alarms.enumerated()), id: \.element.id) { index, alarm in105 VStack(alignment: .leading, spacing: 8) {106 Text("\(Fmt.timeString(alarm.time, use24h: model.settings.use24HourClock)) · \(AlarmText.name(alarm))").font(.orixHeadline)107 SchedulingErrorNote(alarm: alarm, message: model.schedulingErrors[alarm.id] ?? "", identifier: "dashboard.retry.\(index)")108 }109 .padding(.top, 2)110 }111 }112 .frame(maxWidth: .infinity, alignment: .leading)113 .glassCard(tint: Theme.danger)114 .accessibilityElement(children: .contain)115 .accessibilityIdentifier("dashboard.schedulingProblems")116 }117}118119// MARK: Quick alarms120121/// One-tap, one-time alarms. The result (or the scheduling error) is reported under the buttons.122struct QuickAlarmCard: View {123 @Environment(AppModel.self) private var model124 @State private var result: (text: String, isError: Bool)?125 @State private var isSaving = false126127 private struct Preset: Identifiable { let id: Int; let title: String; let date: Date }128129 var body: some View {130 let presets = makePresets()131 VStack(alignment: .leading, spacing: 12) {132 Overline("Quick alarm")133 HStack(spacing: 10) {134 ForEach(presets) { preset in135 Button { save(preset) } label: {136 VStack(spacing: 4) {137 Text(preset.title).font(.orixHeadline).foregroundStyle(Theme.textPrimary)138 Text(Fmt.timeString(AlarmText.time(of: preset.date, calendar: model.calendar), use24h: model.settings.use24HourClock))139 .font(.orixCaption).foregroundStyle(Theme.gold).monospacedDigit()140 }141 .lineLimit(1).minimumScaleFactor(0.7)142 .padding(.horizontal, 6)143 .frame(maxWidth: .infinity, minHeight: 62)144 .background(Theme.surfaceRaised, in: RoundedRectangle(cornerRadius: 18, style: .continuous))145 .overlay(RoundedRectangle(cornerRadius: 18, style: .continuous).strokeBorder(Theme.hairline))146 }147 .buttonStyle(.plain).disabled(isSaving)148 .accessibilityHint(Text("Creates a one-time alarm"))149 .accessibilityIdentifier("dashboard.preset.\(preset.id)")150 }151 }152 if let result {153 Label(result.text, systemImage: result.isError ? "exclamationmark.triangle.fill" : "checkmark.circle.fill")154 .font(.orixCaption).foregroundStyle(result.isError ? Theme.danger : Theme.success)155 .fixedSize(horizontal: false, vertical: true)156 .accessibilityIdentifier("dashboard.presetResult")157 }158 }159 .glassCard()160 }161162 private func makePresets() -> [Preset] {163 let now = model.now(), calendar = model.calendar164 // Round up to the next whole minute so the alarm never rings earlier than announced.165 func wholeMinute(after interval: TimeInterval) -> Date {166 let t = now.addingTimeInterval(interval + 59)167 return calendar.date(from: calendar.dateComponents([.year, .month, .day, .hour, .minute], from: t)) ?? t168 }169 let seven = Recurrence.nextFireDate(time: ClockTime(hour: 7, minute: 0), weekdays: [], after: now, calendar: calendar) ?? wholeMinute(after: 8 * 3600)170 let sevenDay = calendar.isDate(seven, inSameDayAs: now) ? String(localized: "Today") : String(localized: "Tomorrow")171 return [172 Preset(id: 0, title: String(localized: "In 20 min"), date: wholeMinute(after: 20 * 60)),173 Preset(id: 1, title: String(localized: "In 8 h"), date: wholeMinute(after: 8 * 3600)),174 Preset(id: 2, title: sevenDay, date: seven),175 ]176 }177178 private func save(_ preset: Preset) {179 var alarm = model.makeDraftAlarm()180 alarm.time = AlarmText.time(of: preset.date, calendar: model.calendar)181 alarm.weekdays = []182 alarm.isEnabled = true183 alarm.name = String(localized: "Quick alarm")184 let time = Fmt.timeString(alarm.time, use24h: model.settings.use24HourClock)185 isSaving = true186 Task {187 let error = await model.save(alarm)188 if let error {189 Haptics.play(.failure)190 result = (String(localized: "Saved for \(time) but not scheduled: \(error)"), true)191 } else {192 let status = model.status(for: alarm.id)193 Haptics.play(status == .confirmed ? .alarmSet : .warning)194 result = status == .confirmed195 ? (String(localized: "Alarm set for \(time). iOS confirms it is scheduled."), false)196 : (String(localized: "Alarm saved for \(time). System status: \(status.title)."), true)197 }198 isSaving = false199 }200 }201}202203// MARK: Upcoming204205/// The occurrences that follow the next alarm, across all enabled alarms.206struct UpcomingCard: View {207 let now: Date208 @Environment(AppModel.self) private var model209210 var body: some View {211 let items = model.alarms.filter(\.isEnabled)212 .flatMap { alarm in Recurrence.upcoming(for: alarm, after: now, count: 5, calendar: model.calendar).map { (alarm: alarm, date: $0) } }213 .sorted { $0.date < $1.date }214 .dropFirst().prefix(4)215 if !items.isEmpty {216 VStack(alignment: .leading, spacing: 4) {217 Overline("Then").padding(.bottom, 6)218 ForEach(Array(items.enumerated()), id: \.offset) { index, item in219 if index > 0 { Divider().overlay(Theme.hairline) }220 HStack(spacing: 12) {221 VStack(alignment: .leading, spacing: 2) {222 Text(AlarmText.dayLabel(for: item.date, now: now, calendar: model.calendar)).font(.orixHeadline)223 Text(AlarmText.name(item.alarm)).font(.orixCaption).foregroundStyle(Theme.textSecondary).lineLimit(1)224 }225 Spacer(minLength: 8)226 if model.schedulingErrors[item.alarm.id] != nil {227 Image(systemName: "exclamationmark.triangle.fill").foregroundStyle(Theme.danger)228 .accessibilityLabel(Text("Not scheduled"))229 }230 MissionGlyphRow(missions: item.alarm.scenario.missions)231 AlarmTimeText(time: item.alarm.time, size: 24)232 }233 .frame(minHeight: 48)234 .accessibilityElement(children: .combine)235 }236 }237 .glassCard()238 }239 }240}241242// MARK: Sleep plan243244/// Where the evening stands relative to the user's own plan. Nothing here is measured.245struct SleepPrepCard: View {246 let plan: SleepPlan247 let now: Date248 @Environment(AppModel.self) private var model249250 private enum Phase {251 case beforeWindDown(start: Date, bedtime: Date)252 case windDown(bedtime: Date)253 case pastBedtime(since: Date, wake: Date)254 }255256 private var phase: Phase? {257 let calendar = model.calendar258 if let previous = Recurrence.previousFireDate(time: plan.bedtime, weekdays: [], before: now, calendar: calendar),259 let wake = Recurrence.nextFireDate(time: plan.wakeTime, weekdays: [], after: previous, calendar: calendar), now < wake {260 return .pastBedtime(since: previous, wake: wake)261 }262 guard let bedtime = Recurrence.nextFireDate(time: plan.bedtime, weekdays: [], after: now, calendar: calendar) else { return nil }263 let start = bedtime.addingTimeInterval(-Double(plan.windDownMinutes) * 60)264 return now >= start ? .windDown(bedtime: bedtime) : .beforeWindDown(start: start, bedtime: bedtime)265 }266267 var body: some View {268 if let phase {269 let use24h = model.settings.use24HourClock270 let bedtime = Fmt.timeString(plan.bedtime, use24h: use24h)271 let wake = Fmt.timeString(plan.wakeTime, use24h: use24h)272 VStack(alignment: .leading, spacing: 10) {273 Overline("Sleep plan")274 switch phase {275 case .beforeWindDown(let start, let bed):276 Label("Wind-down starts \(Fmt.countdown(to: start, from: now))", systemImage: "moon.haze.fill").font(.orixHeadline)277 Text("Planned bedtime \(bedtime), \(Fmt.countdown(to: bed, from: now)).")278 .font(.orixBody).foregroundStyle(Theme.textSecondary)279 case .windDown(let bed):280 Label("Time to wind down", systemImage: "moon.haze.fill").font(.orixHeadline).foregroundStyle(Theme.gold)281 Text("Planned bedtime \(bedtime), \(Fmt.countdown(to: bed, from: now)). Your evening routine is in the Sleep tab.")282 .font(.orixBody).foregroundStyle(Theme.textSecondary)283 case .pastBedtime(let since, _):284 Label("Past your planned bedtime", systemImage: "bed.double.fill").font(.orixHeadline).foregroundStyle(Theme.gold)285 Text("Bedtime was planned for \(bedtime), \(Fmt.duration(now.timeIntervalSince(since))) ago. Planned wake-up at \(wake).")286 .font(.orixBody).foregroundStyle(Theme.textSecondary)287 }288 Text("Plan: \(Fmt.duration(Double(plan.opportunityMinutes) * 60)) in bed. This is your schedule, not a measurement of your sleep.")289 .font(.orixCaption).foregroundStyle(Theme.textTertiary).fixedSize(horizontal: false, vertical: true)290 Button { model.selectedTab = .sleep } label: {291 HStack(spacing: 5) { Text("Open sleep plan"); Image(systemName: "chevron.right").imageScale(.small) }292 .font(.orixCaption).foregroundStyle(Theme.azure).frame(minHeight: 44).contentShape(Rectangle())293 }294 .buttonStyle(.plain)295 .padding(.vertical, -8)296 .accessibilityIdentifier("dashboard.openSleep")297 }298 .frame(maxWidth: .infinity, alignment: .leading)299 .glassCard(tint: Theme.violet)300 }301 }302}303304// MARK: Recorded performance305306struct PerformanceCard: View {307 let stats: WakeStatistics308 @Environment(AppModel.self) private var model309310 private var hasHistory: Bool {311 stats.alarmsFired + stats.wakeConfirmations + stats.snoozes + stats.missionsCompleted + stats.missionsBypassed > 0312 }313314 var body: some View {315 VStack(alignment: .leading, spacing: 14) {316 HStack {317 Overline("Last 7 days")318 Button { model.selectedTab = .insights } label: {319 HStack(spacing: 5) { Text("Insights"); Image(systemName: "chevron.right").imageScale(.small) }320 .font(.orixCaption).foregroundStyle(Theme.azure)321 .frame(minHeight: 44).contentShape(Rectangle())322 }323 .buttonStyle(.plain)324 .accessibilityIdentifier("dashboard.openInsights")325 }326 .padding(.vertical, -10)327 if hasHistory {328 weekStrip329 Grid(horizontalSpacing: 10, verticalSpacing: 10) {330 GridRow {331 tile("flame.fill", Theme.sunrise, stats.currentStreak == 1 ? String(localized: "1 day") : String(localized: "\(stats.currentStreak) days"), "Confirmation streak")332 tile("checkmark.seal.fill", Theme.success, String(localized: "\(stats.wakeConfirmations) of \(stats.alarmsFired)"), "Alarms followed by a wake confirmation")333 }334 GridRow {335 tile("zzz", Theme.violet, "\(stats.snoozes)", stats.snoozes == 1 ? "Snooze" : "Snoozes")336 tile("timer", Theme.azure, stats.averageConfirmationDelay.map { Fmt.duration($0) } ?? "–", "Average time from alarm to confirmation")337 }338 }339 Text("Counted from events recorded on this iPhone. A confirmation is you tapping “I'm up”; the app does not measure whether you are awake.")340 .font(.orixCaption).foregroundStyle(Theme.textTertiary).fixedSize(horizontal: false, vertical: true)341 } else {342 VStack(alignment: .leading, spacing: 6) {343 Label("Nothing recorded yet", systemImage: "chart.bar.xaxis").font(.orixHeadline)344 Text("After your first alarm rings, this card shows what was recorded: confirmations, snoozes and how long you took to confirm.")345 .font(.orixBody).foregroundStyle(Theme.textSecondary).fixedSize(horizontal: false, vertical: true)346 }347 .accessibilityElement(children: .combine)348 .accessibilityIdentifier("dashboard.performanceEmpty")349 }350 }351 .glassCard()352 }353354 /// One mark per day: a tick when a wake confirmation was recorded, a ring when an alarm fired without one, a dash otherwise.355 private var weekStrip: some View {356 HStack(spacing: 0) {357 ForEach(stats.days) { day in358 VStack(spacing: 6) {359 Text(day.day.formatted(.dateTime.weekday(.narrow))).font(.orixOverline).foregroundStyle(Theme.textTertiary)360 ZStack {361 if day.confirmed > 0 {362 Circle().fill(Theme.sunriseGradient)363 Image(systemName: "checkmark").font(.system(size: 12, weight: .heavy)).foregroundStyle(Theme.midnight)364 } else if day.fired > 0 {365 Circle().strokeBorder(Theme.gold, lineWidth: 2)366 Image(systemName: "bell.fill").font(.system(size: 10)).foregroundStyle(Theme.gold)367 } else {368 Capsule().fill(Color.white.opacity(0.2)).frame(width: 10, height: 3)369 }370 }371 .frame(width: 28, height: 28)372 }373 .frame(maxWidth: .infinity)374 }375 }376 .accessibilityElement(children: .ignore)377 .accessibilityLabel(Text("Wake confirmations recorded on \(stats.days.filter { $0.confirmed > 0 }.count) of the last \(stats.days.count) days"))378 }379380 private func tile(_ symbol: String, _ tint: Color, _ value: String, _ caption: LocalizedStringKey) -> some View {381 VStack(alignment: .leading, spacing: 6) {382 Image(systemName: symbol).font(.subheadline.weight(.semibold)).foregroundStyle(tint).accessibilityHidden(true)383 Text(value).font(.system(.title2, design: .rounded, weight: .semibold)).monospacedDigit().lineLimit(1).minimumScaleFactor(0.6)384 Text(caption).font(.orixCaption).foregroundStyle(Theme.textSecondary).fixedSize(horizontal: false, vertical: true)385 }386 .padding(14)387 .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)388 .background(Theme.surface, in: RoundedRectangle(cornerRadius: 18, style: .continuous))389 .accessibilityElement(children: .combine)390 }391}392393// MARK: Tips394395/// Optional suggestions computed from recorded results. Nothing is changed unless the user edits the alarm.396struct SuggestionsCard: View {397 let suggestions: [AdaptiveEngine.Suggestion]398 @Environment(AppModel.self) private var model399400 var body: some View {401 if !suggestions.isEmpty {402 VStack(alignment: .leading, spacing: 12) {403 Overline("Optional tips")404 ForEach(Array(suggestions.prefix(3).enumerated()), id: \.element) { index, suggestion in405 let target = alarm(for: suggestion)406 if index > 0 { Divider().overlay(Theme.hairline) }407 HStack(alignment: .top, spacing: 12) {408 Image(systemName: symbol(for: suggestion)).font(.title3).foregroundStyle(Theme.gold).frame(width: 28).accessibilityHidden(true)409 VStack(alignment: .leading, spacing: 6) {410 Text(text(for: suggestion)).font(.orixBody).fixedSize(horizontal: false, vertical: true)411 if let target {412 Button { model.editingAlarm = target } label: {413 Label("Review “\(AlarmText.name(target))”", systemImage: "slider.horizontal.3")414 .font(.orixCaption).foregroundStyle(Theme.azure).frame(minHeight: 44, alignment: .leading)415 }416 .buttonStyle(.plain)417 .accessibilityIdentifier("dashboard.tip.\(index)")418 }419 }420 }421 }422 Text("Tips come from your recorded mission results and snoozes. They never change an alarm on their own.")423 .font(.orixCaption).foregroundStyle(Theme.textTertiary).fixedSize(horizontal: false, vertical: true)424 }425 .frame(maxWidth: .infinity, alignment: .leading)426 .glassCard()427 }428 }429430 private func symbol(for suggestion: AdaptiveEngine.Suggestion) -> String {431 switch suggestion {432 case .reduceSnoozes: "zzz"; case .raiseDifficulty: "arrow.up.right.circle.fill"; case .lowerDifficulty: "arrow.down.right.circle.fill"433 }434 }435436 private func text(for suggestion: AdaptiveEngine.Suggestion) -> String {437 switch suggestion {438 case .reduceSnoozes(let id, let average):439 let name = model.alarm(id).map(AlarmText.name) ?? String(localized: "this alarm")440 return String(localized: "“\(name)” was snoozed about \(average.formatted(.number.precision(.fractionLength(1)))) times per morning over the last two weeks. You could lower its snooze limit.")441 case .raiseDifficulty(let kind):442 return String(localized: "Your recent \(kind.title) results were quick with few mistakes. You could try a harder level, or switch it to Adaptive.")443 case .lowerDifficulty(let kind):444 return String(localized: "Your recent \(kind.title) results were slow or had several mistakes. You could try an easier level, or switch it to Adaptive.")445 }446 }447448 private func alarm(for suggestion: AdaptiveEngine.Suggestion) -> AlarmDefinition? {449 switch suggestion {450 case .reduceSnoozes(let id, _): model.alarm(id)451 case .raiseDifficulty(let kind), .lowerDifficulty(let kind):452 model.alarms.first { $0.scenario.missions.contains { $0.kind == kind && $0.difficulty != .adaptive } }453 }454 }455}456457// MARK: Focus timer458459struct FocusTimerCard: View {460 @Environment(AppModel.self) private var model461 @State private var error: String?462 @State private var isStarting = false463 private static let presets = [15, 25, 45, 60]464465 var body: some View {466 VStack(alignment: .leading, spacing: 12) {467 Overline("Focus timer")468 if let end = model.focusTimerEnd, end > model.now() {469 // The remaining time is the only part of the dashboard that needs a per-second refresh.470 TimelineView(.periodic(from: .now, by: 1)) { context in471 let remaining = max(0, end.timeIntervalSince(context.date))472 if remaining > 0 { running(remaining: remaining, end: end) } else { finished }473 }474 } else {475 Text("A countdown scheduled with iOS: it alerts you even if the app is closed.")476 .font(.orixCaption).foregroundStyle(Theme.textSecondary).fixedSize(horizontal: false, vertical: true)477 HStack(spacing: 8) {478 ForEach(Self.presets, id: \.self) { minutes in479 Button { start(minutes) } label: {480 VStack(spacing: 0) {481 Text("\(minutes)").font(.system(.title3, design: .rounded, weight: .semibold)).monospacedDigit()482 Text("min").font(.orixCaption).foregroundStyle(Theme.textSecondary)483 }484 .frame(maxWidth: .infinity, minHeight: 56)485 .background(Theme.surfaceRaised, in: RoundedRectangle(cornerRadius: 16, style: .continuous))486 .overlay(RoundedRectangle(cornerRadius: 16, style: .continuous).strokeBorder(Theme.hairline))487 }488 .buttonStyle(.plain).disabled(isStarting)489 .accessibilityLabel(Text("Start a \(minutes) minute focus timer"))490 .accessibilityIdentifier("dashboard.focus.\(minutes)")491 }492 }493 }494 if let error {495 Label("The timer could not be scheduled: \(error)", systemImage: "exclamationmark.triangle.fill")496 .font(.orixCaption).foregroundStyle(Theme.danger).fixedSize(horizontal: false, vertical: true)497 .accessibilityIdentifier("dashboard.focusError")498 }499 }500 .glassCard()501 }502503 private func running(remaining: TimeInterval, end: Date) -> some View {504 let total = Int(remaining.rounded(.up))505 return HStack(alignment: .center, spacing: 12) {506 VStack(alignment: .leading, spacing: 2) {507 Text(String(format: "%d:%02d", total / 60, total % 60)).font(.clock(46, weight: .regular))508 .foregroundStyle(Theme.sunriseGradient)509 .contentTransition(.numericText(countsDown: true))510 .accessibilityLabel(Text("\(Fmt.duration(Double(total))) remaining"))511 Text("Ends at \(Fmt.timeString(AlarmText.time(of: end, calendar: model.calendar), use24h: model.settings.use24HourClock))")512 .font(.orixCaption).foregroundStyle(Theme.textSecondary)513 }514 Spacer(minLength: 8)515 Button {516 Haptics.play(.selection)517 model.cancelFocusTimer()518 } label: {519 Label("Cancel", systemImage: "xmark").font(.orixHeadline).foregroundStyle(Theme.textPrimary)520 .padding(.horizontal, 18).frame(minHeight: 48)521 .background(Theme.surfaceRaised, in: Capsule()).overlay(Capsule().strokeBorder(Theme.hairline))522 }523 .buttonStyle(.plain)524 .accessibilityIdentifier("dashboard.focusCancel")525 }526 }527528 private var finished: some View {529 Label("Timer finished", systemImage: "checkmark.circle.fill").font(.orixHeadline).foregroundStyle(Theme.success)530 }531532 private func start(_ minutes: Int) {533 isStarting = true534 Task {535 error = await model.startFocusTimer(minutes: minutes)536 Haptics.play(error == nil ? .alarmSet : .failure)537 isStarting = false538 }539 }540}541