//
//  OnboardingWrapup.swift
//  Feels (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 {
        ZStack {
            
            Image("good", bundle: .main)
                .foregroundColor(Color(UIColor.darkText))
                .opacity(0.04)
                .scaleEffect(1.2)
                .padding(.bottom, 55)
            
            ScrollView {
                VStack {
                    Spacer()
                    
                    Text(String(localized: "onboarding_wrap_up_1"))
                        .font(.title)
                        .foregroundColor(Color(UIColor.white))
                        .padding([.trailing, .leading], 55)
                        .padding([.top], 15)
                    
                    Text(formatter.string(from: onboardingData.date))
                        .font(.title)
                        .fontWeight(.bold)
                        .foregroundColor(Color(UIColor.white))
                        .padding([.trailing, .leading], 55)
                        .padding([.top], 15)
                    
                    Text(String(localized: "onboarding_wrap_up_2"))
                        .font(.title)
                        .foregroundColor(Color(UIColor.white))
                        .padding([.trailing, .leading], 55)
                        .padding([.top], 15)
                    
                    Text(onboardingData.title)
                        .font(.title)
                        .fontWeight(.bold)
                        .foregroundColor(Color(UIColor.white))
                        .padding([.trailing, .leading], 55)
                        .padding([.top], 15)
                    
                    Text(String(localized: "onboarding_wrap_up_3"))
                        .font(.title)
                        .foregroundColor(Color(UIColor.white))
                        .padding([.trailing, .leading], 55)
                        .padding([.top], 15)
                    
                    Text(onboardingData.inputDay.localizedValue)
                        .font(.title)
                        .fontWeight(.bold)
                        .foregroundColor(Color(UIColor.white))
                        .padding([.trailing, .leading], 55)
                        .padding([.top], 15)

                    Button(action: {
                        completionClosure(onboardingData)
                    }, label: {
                        Text(String(localized: "onboarding_wrap_up_complete_button"))
                            .font(.title)
                            .fontWeight(.bold)
                            .foregroundColor(.yellow)
                            .padding(10)
                            .padding([.leading, .trailing], 25)
                            .background(RoundedRectangle(cornerRadius: 10).fill().foregroundColor(Color.white))
                            .cornerRadius(10)
                    })
                        .padding([.top], 65)
                }
                .multilineTextAlignment(.center)
            }
        }
        .background(.yellow)
    }
}

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