import SwiftUI #if canImport(UIKit) import UIKit #endif /// Vier Rating-Buttons unten am Bildschirm. Tap → onRate(rating) /// plus Haptic-Feedback. struct RatingBar: View { let onRate: (Rating) -> Void var body: some View { HStack(spacing: 8) { ForEach(Rating.allCases, id: \.self) { rating in Button { triggerHaptic(for: rating) onRate(rating) } label: { VStack(spacing: 2) { Text(rating.label) .font(.subheadline.weight(.semibold)) Text(rating.shortcut) .font(.caption2) .foregroundStyle(.secondary) } .frame(maxWidth: .infinity) .padding(.vertical, 14) .background(background(for: rating), in: RoundedRectangle(cornerRadius: 10)) .foregroundStyle(foreground(for: rating)) } .buttonStyle(.plain) } } .padding(.horizontal, 16) } private func background(for rating: Rating) -> Color { switch rating { case .again: CardsTheme.error.opacity(0.12) case .hard: CardsTheme.warning.opacity(0.12) case .good: CardsTheme.primary.opacity(0.12) case .easy: CardsTheme.success.opacity(0.12) } } private func foreground(for rating: Rating) -> Color { switch rating { case .again: CardsTheme.error case .hard: CardsTheme.warning case .good: CardsTheme.primary case .easy: CardsTheme.success } } private func triggerHaptic(for rating: Rating) { #if canImport(UIKit) let generator = UIImpactFeedbackGenerator( style: rating == .easy ? .heavy : .medium ) generator.impactOccurred() #endif } }