//
//  OnboardingWrapup.swift
//  Reflect (iOS)
//
//  Created by Trey Tartt on 1/21/22.
//

import SwiftUI

struct OnboardingWrapup: View {
    @ObservedObject var onboardingData: OnboardingData
    
    let completionClosure: ((OnboardingData) -> Void)
    
    var formatter: DateFormatter {
        let dateFormatter = DateFormatter()
        dateFormatter.timeStyle = .short
        return dateFormatter
    }
    
    var body: some View {
        GeometryReader { geometry in
            VStack {
                ScrollView {

                    Spacer()

                    Text(String(localized: "onboarding_wrap_up_1"))
                        .padding(.top)
                        .padding()
                        .font(.title)
                        .foregroundColor(Color(UIColor.white))

                    Text(formatter.string(from: onboardingData.date))
                        .font(.title)
                        .fontWeight(.bold)
                        .padding()
                        .foregroundColor(Color(UIColor.white))

                    Text(String(localized: "onboarding_wrap_up_3"))
                        .font(.title)
                        .padding()
                        .foregroundColor(Color(UIColor.white))

                    Text(onboardingData.inputDay.localizedValue)
                        .font(.title)
                        .fontWeight(.bold)
                        .padding()
                        .foregroundColor(Color(UIColor.white))

                    Button(action: {
                        AnalyticsManager.shared.track(.onboardingCompleted(dayId: String(onboardingData.inputDay.rawValue)))
                        completionClosure(onboardingData)
                    }, label: {
                        Text(String(localized: "onboarding_wrap_up_complete_button"))
                            .font(.title)
                            .fontWeight(.bold)
                            .foregroundColor(Color(hex: "31d158"))
                            .padding()
                            .background(RoundedRectangle(cornerRadius: 10).fill().foregroundColor(Color.white))
                            .cornerRadius(10)
                    })
                    .padding([.top], 65)
                }
                .multilineTextAlignment(.center)
            }
            .frame(maxWidth: geometry.size.width)
        }
        .background {
            ZStack {
                Color(hex: "31d158")
                VStack {
                    Spacer()
                    Image("great", bundle: .main)
                        .foregroundColor(Color(UIColor.darkText))
                        .opacity(0.04)
                        .scaleEffect(1.2, anchor: .trailing)
                        .accessibilityHidden(true)
                    Spacer()
                }
            }
        }
    }
}

struct OnboardingWrapup_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            OnboardingWrapup(onboardingData: OnboardingData(), completionClosure: { _ in
                
            })
            
            OnboardingWrapup(onboardingData: OnboardingData(), completionClosure: { _ in
                
            })
            .preferredColorScheme(.dark)
        }
    }
}
