//
//  OnboardingTime.swift
//  Feels (iOS)
//
//  Created by Trey Tartt on 1/20/22.
//

import SwiftUI

struct OnboardingTime: View {
    @ObservedObject var onboardingData: OnboardingData
    
    var formatter: DateFormatter {
        let dateFormatter = DateFormatter()
        dateFormatter.timeStyle = .short
        return dateFormatter
    }
    
    var body: some View {
        ZStack {
            
            Image("great", bundle: .main)
                .foregroundColor(Color(UIColor.darkText))
                .opacity(0.04)
                .scaleEffect(1.2)
            
            ScrollView {
                VStack {
                    Text(String(localized: "onboarding_time_title"))
                        .font(.title)
                        .padding([.trailing, .leading], 55)
                        .padding([.top], 25)
                        .foregroundColor(Color(UIColor.white))
                    
                    DatePicker("", selection: $onboardingData.date,
                               displayedComponents: .hourAndMinute)
                        .scaleEffect(2)
                        .labelsHidden()
                        .frame(minWidth: 0, maxWidth: .infinity)
                        .padding()
                        .padding([.top, .bottom], 25)
                        .colorScheme(.dark)
                    
                    Text(String(format: String(localized: "onboarding_time_body"),
                                formatter.string(from: onboardingData.date)))
                        .font(.body)
                        .padding([.top], 15)
                        .padding([.trailing, .leading], 55)
                        .foregroundColor(Color(UIColor.white))
                    
                    Spacer()
                }
            }
        }
        .background(.green)
    }
}

struct OnboardingTime_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            OnboardingTime(onboardingData: OnboardingData())
            
            OnboardingTime(onboardingData: OnboardingData())
                .preferredColorScheme(.dark)
        }
    }
}
