//
//  OnboardingMain.swift
//  Reflect (iOS)
//
//  Created by Trey Tartt on 1/20/22.
//

import SwiftUI

struct OnboardingMain: View {
    @Environment(\.presentationMode) var presentationMode
    @State var onboardingData: OnboardingData
    @EnvironmentObject var iapManager: IAPManager

    let updateBoardingDataClosure: ((OnboardingData) -> Void)

    var body: some View {
        TabView {
            // 1. Welcome screen
            OnboardingWelcome()

            // 2. Which day to rate
            OnboardingDay(onboardingData: onboardingData)

            // 3. Reminder time
            OnboardingTime(onboardingData: onboardingData)

            // 4. Style customization
            OnboardingStyle(onboardingData: onboardingData)

            // 5. Subscription benefits & completion
            OnboardingSubscription(
                onboardingData: onboardingData,
                completionClosure: { data in
                    updateBoardingDataClosure(data)
                }
            )
        }
        .ignoresSafeArea()
        .tabViewStyle(.page)
        .onAppear {
            setupAppearance()
        }
        .interactiveDismissDisabled()
    }

    func setupAppearance() {
        UIPageControl.appearance().currentPageIndicatorTintColor = .white
        UIPageControl.appearance().pageIndicatorTintColor = UIColor.white.withAlphaComponent(0.3)
    }
}

struct OnboardingMain_Previews: PreviewProvider {
    static var previews: some View {
        OnboardingMain(
            onboardingData: OnboardingData(),
            updateBoardingDataClosure: { _ in }
        )
        .environmentObject(IAPManager())
    }
}
