wake-ios/wake/View/Subscribe/Components/PlanCompare.swift
2025-09-01 19:42:32 +08:00

165 lines
5.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PlanCompare.swift
// wake
//
// Created by fairclip on 2025/8/20.
//
import SwiftUI
// MARK: -
struct PlanFeature {
let title: String
let subtitle: String?
let freeValue: String
let pioneerValue: String
let icon: String?
}
// MARK: -
struct PlanCompare: View {
// MARK: -
private let features: [PlanFeature] = [
PlanFeature(
title: "Mystery Box Purchase:",
subtitle: nil,
freeValue: "3 /week",
pioneerValue: "Unlimited",
icon: nil
),
PlanFeature(
title: "Material Upload:",
subtitle: nil,
freeValue: "50 images and\n5 videos/day",
pioneerValue: "Unlimited",
icon: nil
),
PlanFeature(
title: "Free Credits:",
subtitle: "Expires the next day",
freeValue: "200 /day",
pioneerValue: "500 /day",
icon: nil
)
]
var body: some View {
HStack(spacing: 0) {
//
featureNamesColumn
.frame(minWidth: 163)
// Free
planColumn(title: "Free", isPioneer: false)
.layoutPriority(1)
// Pioneer
planColumn(title: "Pioneer", isPioneer: true)
.frame(width: 88)
}
.background(Theme.Colors.cardBackground)
.cornerRadius(Theme.CornerRadius.medium)
// .shadow(
// color: Theme.Shadows.small,
// radius: Theme.Shadows.cardShadow.radius,
// x: Theme.Shadows.cardShadow.x,
// y: Theme.Shadows.cardShadow.y
// )
}
// MARK: -
private var featureNamesColumn: some View {
VStack(spacing: 0) {
//
Text("")
.font(Typography.font(for: .title, family: .quicksandBold, size: 14))
.padding(.vertical, Theme.Spacing.sm)
.frame(maxWidth: .infinity, minHeight: 30)
//
ForEach(Array(features.enumerated()), id: \.offset) { index, feature in
VStack(alignment: .leading, spacing: Theme.Spacing.xs) {
Text(feature.title)
.font(Typography.font(for: .body, family: .quicksandBold, size: 12))
.foregroundColor(Theme.Colors.textPrimary)
.multilineTextAlignment(.leading)
if let subtitle = feature.subtitle {
Text(subtitle)
.font(Typography.font(for: .caption, family: .quicksandRegular))
.foregroundColor(Theme.Colors.textSecondary)
.multilineTextAlignment(.leading)
}
}
.frame(maxWidth: .infinity, minHeight: 30, alignment: .leading)
.padding(.horizontal, Theme.Spacing.sm)
.padding(.vertical, Theme.Spacing.sm)
}
}
.padding(Theme.Spacing.sm)
}
// MARK: -
private func planColumn(title: String, isPioneer: Bool) -> some View {
VStack(spacing: 0) {
//
VStack(spacing: Theme.Spacing.xs) {
Text(title)
.font(Typography.font(for: .title, family: .quicksandBold, size: 14))
.foregroundColor(Color.black)
}
.frame(maxWidth: .infinity)
.padding(.vertical, Theme.Spacing.sm)
//
ForEach(Array(features.enumerated()), id: \.offset) { index, feature in
let value = isPioneer ? feature.pioneerValue : feature.freeValue
Text(value)
.font(Typography.font(for: .body, family: .quicksandRegular, size: 12))
.foregroundColor(isPioneer ? Color.black : Theme.Colors.textSecondary)
.fontWeight(isPioneer ? .semibold : .regular)
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity, minHeight: 30)
.padding(.vertical, Theme.Spacing.sm)
}
}
.frame(maxWidth: .infinity)
.background(isPioneer ? Theme.Colors.primaryLight : Color.white)
.cornerRadius(Theme.CornerRadius.medium)
.overlay(
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
.stroke(
isPioneer ? Theme.Colors.primary : Theme.Colors.border,
lineWidth: isPioneer ? 1 : 0
)
)
.padding(Theme.Spacing.sm)
}
}
// MARK: -
#Preview("PlanCompare") {
ScrollView {
VStack(spacing: Theme.Spacing.xl) {
PlanCompare()
}
.padding()
}
.background(Theme.Colors.background)
}
#Preview("PlanCompare Dark") {
ScrollView {
VStack(spacing: Theme.Spacing.xl) {
PlanCompare()
}
.padding()
}
.background(Color.black)
.preferredColorScheme(.dark)
}