// // SubscriptionStatusBar.swift // wake // // Created by fairclip on 2025/8/19. // import SwiftUI // MARK: - 订阅状态枚举 enum SubscriptionStatus { case free case pioneer(expiryDate: Date) var title: String { switch self { case .free: return "Free" case .pioneer: return "Pioneer" } } var hasExpiry: Bool { switch self { case .free: return false case .pioneer: return true } } var backgroundColor: Color { switch self { case .free: return Theme.Colors.freeBackground // 浅橙色背景 case .pioneer: return Theme.Colors.pioneerBackground // 橙色背景 } } var textColor: Color { switch self { case .free: return Theme.Colors.textPrimary case .pioneer: return Theme.Colors.textPrimary } } } // MARK: - 订阅状态栏组件 struct SubscriptionStatusBar: View { let status: SubscriptionStatus let onSubscribeTap: (() -> Void)? init(status: SubscriptionStatus, onSubscribeTap: (() -> Void)? = nil) { self.status = status self.onSubscribeTap = onSubscribeTap } var body: some View { HStack(spacing: 16) { VStack(alignment: .leading, spacing: 8) { // 订阅类型标题 Text(status.title) .font(.system(size: 28, weight: .bold, design: .rounded)) .foregroundColor(status.textColor) // 过期时间或订阅按钮 if case .pioneer(let expiryDate) = status { VStack(alignment: .leading, spacing: 4) { Text("Expires on :") .font(.system(size: 14, weight: .medium)) .foregroundColor(status.textColor.opacity(0.8)) Text(formatDate(expiryDate)) .font(.system(size: 16, weight: .semibold)) .foregroundColor(status.textColor) } } else { Button(action: { onSubscribeTap?() }) { Text("Subscribe") .font(.system(size: 14, weight: .semibold)) .foregroundColor(Theme.Colors.textPrimary) .padding(.horizontal, 20) .padding(.vertical, 8) .background(Theme.Colors.subscribeButton) .cornerRadius(Theme.CornerRadius.large) } } } Spacer() // 播放按钮图标 Circle() .fill(Color.black) .frame(width: 60, height: 60) .overlay( Image(systemName: "play.fill") .foregroundColor(.white) .font(.title2) .offset(x: 2) // 微调播放图标位置 ) } .padding(20) .background(status.backgroundColor) .cornerRadius(20) // .shadow(color: Color.black.opacity(0.1), radius: 4, x: 0, y: 2) } // MARK: - 日期格式化 private func formatDate(_ date: Date) -> String { let formatter = DateFormatter() formatter.dateFormat = "MMMM d, yyyy" return formatter.string(from: date) } } // MARK: - 预览 #Preview("Free Status") { VStack(spacing: 20) { SubscriptionStatusBar( status: .free, onSubscribeTap: { print("Subscribe tapped") } ) .padding() SubscriptionStatusBar( status: .pioneer(expiryDate: Calendar.current.date(byAdding: .month, value: 6, to: Date()) ?? Date()) ) .padding() } .background(Color(.systemGroupedBackground)) }