//
//  PaywallPresenter.swift
//  SelfieCam
//
//  Presents RevenueCat native Paywall with automatic fallback to custom PaywallView
//  if the RevenueCat paywall fails to load or is not configured.
//

import SwiftUI
import Bedrock

/// Presents the custom SelfieCam paywall.
///
/// Usage:
/// ```swift
/// .sheet(isPresented: $showPaywall) {
///     PaywallPresenter {
///         // Called on successful purchase or restore
///         print("Purchase successful!")
///     }
/// }
/// ```
///
struct PaywallPresenter: View {
    /// Callback triggered when a purchase or restore is successful
    var onPurchaseSuccess: (() -> Void)?
    
    /// Creates a PaywallPresenter with an optional success callback
    /// - Parameter onPurchaseSuccess: Called when purchase or restore completes successfully
    init(onPurchaseSuccess: (() -> Void)? = nil) {
        self.onPurchaseSuccess = onPurchaseSuccess
    }
    
    var body: some View {
        ProPaywallView(onPurchaseSuccess: onPurchaseSuccess)
    }
}

// MARK: - Preview

#Preview {
    PaywallPresenter()
        .preferredColorScheme(.dark)
}
