wake-ios/wake/View/Credits/CreditsInfoCard.swift
2025-09-02 20:31:13 +08:00

108 lines
3.5 KiB
Swift

//
// CreditsInfoCard.swift
// wake
//
// Created by fairclip on 2025/8/19.
//
import SwiftUI
// MARK: -
struct CreditsInfoCard: View {
let totalCredits: Int
let onInfoTap: (() -> Void)?
let onDetailTap: (() -> Void)?
@State private var showInfoPopover = false
init(
totalCredits: Int,
onInfoTap: (() -> Void)? = nil,
onDetailTap: (() -> Void)? = nil
) {
self.totalCredits = totalCredits
self.onInfoTap = onInfoTap
self.onDetailTap = onDetailTap
}
var body: some View {
Button(action: {
onDetailTap?()
}) {
mainCreditsSection
}
.buttonStyle(PlainButtonStyle())
.background(Color.themeTextWhite)
.cornerRadius(Theme.CornerRadius.round)
// .shadow(color: Theme.Shadows.small, radius: Theme.Shadows.cardShadow.radius, x: Theme.Shadows.cardShadow.x, y: Theme.Shadows.cardShadow.y)
}
// MARK: -
private var mainCreditsSection: some View {
HStack(spacing: Theme.Spacing.md) {
//
HStack(spacing: Theme.Spacing.sm) {
Text("Credits:")
.font(Typography.font(for: .subtitle, family: .quicksandBold))
.foregroundColor(Theme.Colors.textPrimary)
Text("\(totalCredits)")
.font(Typography.font(for: .subtitle, family: .quicksandBold))
.foregroundColor(Theme.Colors.textPrimary)
}
//
HStack(spacing: Theme.Spacing.sm) {
//
Button(action: {
showInfoPopover = true
onInfoTap?()
}) {
Image(systemName: "questionmark.circle")
.foregroundColor(Theme.Colors.textSecondary)
.font(.system(size: 16))
}
.popover(isPresented: $showInfoPopover, attachmentAnchor: .point(.bottom), arrowEdge: .top) {
Text("Credits can be used for material indexing (1 credit per photo or per second of video) and for buying blind boxes (100 crediteach)")
.font(Typography.font(for: .caption, family: .quicksandRegular))
.multilineTextAlignment(.center)
.presentationBackground(Theme.Gradients.backgroundGradient)
.frame(minWidth: 200, maxWidth: UIScreen.main.bounds.width * 0.6)
.presentationCompactAdaptation(.popover)
.padding(.horizontal, Theme.Spacing.md)
.padding(.vertical, Theme.Spacing.sm)
}
Spacer()
//
Image(systemName: "chevron.right")
.foregroundColor(Theme.Colors.textPrimary)
.font(.system(size: 14, weight: .medium))
}
}
.padding(Theme.Spacing.lg)
}
}
// MARK: -
#Preview("Credits Info Card") {
VStack(spacing: 20) {
CreditsInfoCard(
totalCredits: 3290,
onInfoTap: {
print("Info tapped")
},
onDetailTap: {
print("Detail tapped")
}
)
}
.padding()
.background(Color(.systemGroupedBackground))
}